32
def title_case(words):
35
if word.lower() in ['in', 'a', 'the', 'of', 'has']:
36
titled.append(word.lower())
37
elif word.upper() == word:
40
titled.append(word.capitalize())
41
titled = ' '.join(titled)
42
return titled[0].upper() + titled[1:]
32
45
def get_lineno(obj):
33
46
return inspect.getsourcelines(obj)[1]
36
49
def find_tests(finder, module):
37
finder.gotModule(module)
50
finder.got_module(module)
38
51
classes = sorted(reflect.findTestClasses(module), key=get_lineno)
39
52
for testCaseClass in classes:
40
finder.gotTestClass(testCaseClass)
53
finder.got_test_class(testCaseClass)
41
54
methods = [getattr(testCaseClass, 'test%s' % name)
42
55
for name in reflect.getTestCaseNames(testCaseClass)]
43
56
for method in sorted(methods, key=get_lineno):
44
finder.gotTest(method)
57
finder.got_test(method)
47
60
class Documenter(object):
49
62
def __init__(self, formatter):
50
63
self.formatter = formatter
52
def titleCase(self, words):
55
if word.lower() in ['in', 'a', 'the', 'of']:
56
titled.append(word.lower())
57
elif word.upper() == word:
60
titled.append(word.capitalize())
61
titled = ' '.join(titled)
62
return titled[0].upper() + titled[1:]
65
def _append_docs(self, obj):
66
docs = self.extract_docs(obj)
68
self.formatter.paragraph(docs)
64
def getDocs(self, obj):
70
def extract_docs(self, obj):
65
71
doc = inspect.getdoc(obj)
67
73
doc = inspect.getcomments(obj)
70
def gotModule(self, module):
76
def format_module(self, module_name):
79
def format_test(self, test_name):
80
return title_case(split_name(test_name)[1:])
82
def format_test_class(self, class_name):
84
[bit for bit in split_name(class_name) if bit != 'test'])
86
def got_module(self, module):
71
87
self.formatter.title(module.__name__)
72
docs = self.getDocs(module)
74
self.formatter.paragraph(docs)
76
def gotTestClass(self, klass):
77
self.formatter.section(self.titleCase(
78
[bit for bit in split_name(klass.__name__) if bit != 'test']))
79
docs = self.getDocs(klass)
81
self.formatter.paragraph(docs)
83
def gotTest(self, method):
84
self.formatter.subsection(
85
self.titleCase(split_name(method.__name__)[1:]))
86
docs = self.getDocs(method)
88
self.formatter.paragraph(docs)
88
self._append_docs(module)
90
def got_test(self, method):
91
self.formatter.subsection(self.format_test(method.__name__))
92
self._append_docs(method)
94
def got_test_class(self, klass):
95
self.formatter.section(self.format_test_class(klass.__name__))
96
self._append_docs(klass)