forked from GothenburgBitFactory/bugwarrior
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_docs.py
80 lines (65 loc) · 2.71 KB
/
test_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import docutils.core
import glob
import os.path
import pathlib
import pkg_resources
import re
import socket
import subprocess
import tempfile
import unittest
DOCS_PATH = pathlib.Path(__file__).parent / '../bugwarrior/docs'
try:
socket.create_connection(('1.1.1.1', 80))
INTERNET = True
except OSError:
INTERNET = False
class ReadmeTest(unittest.TestCase):
def test_service_list(self):
# GET README LISTED SERVICES
def is_services(node):
try:
return 'services' in node.attributes['classes']
except AttributeError: # not all nodes have attributes
return False
with open('README.rst', 'r') as f:
readme = f.read()
readme_document = docutils.core.publish_doctree(readme)
service_list_search = readme_document.traverse(condition=is_services)
self.assertEqual(len(service_list_search), 1)
service_list_element = service_list_search.pop()
readme_listed_services = set(
list_item.astext() for list_item in service_list_element.children)
# GET TITLES FROM SERVICE DOCUMENTATION FILES
documented_services = set()
for service in glob.iglob(str(DOCS_PATH / 'services' / '*.rst')):
with open(service, 'r') as f:
firstline = f.readline().strip()
# ignore directives or empty lines
while firstline.startswith('.. _') or firstline == '':
firstline = f.readline().strip()
documented_services.add(firstline)
self.assertEqual(documented_services, readme_listed_services)
class DocsTest(unittest.TestCase):
@unittest.skipIf(not INTERNET, 'no internet')
def test_docs_build_without_warning(self):
with tempfile.TemporaryDirectory() as buildDir:
subprocess.run(
['sphinx-build', '-n', '-W', '-v', str(DOCS_PATH), buildDir],
check=True)
@unittest.skipIf(not INTERNET, 'no internet')
def test_manpage_build_without_warning(self):
with tempfile.TemporaryDirectory() as buildDir:
subprocess.run(
['sphinx-build', '-b', 'man', '-n', '-W', '-v', str(DOCS_PATH), buildDir],
check=True)
def test_registered_services_are_documented(self):
registered_services = set(
e.name for e in
pkg_resources.iter_entry_points(group='bugwarrior.service'))
documented_services = set()
services_paths = os.listdir(DOCS_PATH / 'services')
for p in services_paths:
if re.match(r'.*\.rst$', p):
documented_services.add(re.sub(r'\.rst$', '', p))
self.assertEqual(registered_services, documented_services)