4
from testdoc import split_name, find_tests, Documenter
4
from testdoc import split_name, find_tests, Documenter, title_case
7
7
class TestSplitName(unittest.TestCase):
9
def test_singleWord(self):
9
def test_single_word(self):
10
10
self.assertEqual(split_name('single'), ['single'])
12
12
def test_underscores(self):
13
13
self.assertEqual(split_name('split_name'), ['split', 'name'])
15
def test_camelCase(self):
15
def test_camel_case(self):
16
16
self.assertEqual(split_name('splitName'), ['split', 'name'])
18
18
split_name('splitLongName'), ['split', 'long', 'name'])
19
19
self.assertEqual(split_name('splitAName'), ['split', 'a', 'name'])
21
def test_camelCaseWithCaps(self):
21
def test_camel_case_with_caps(self):
22
22
self.assertEqual(split_name('splitDNSName'), ['split', 'DNS', 'name'])
24
def test_singleUnderscore(self):
24
def test_single_underscore(self):
25
25
"""Single underscores are used for reflection prefixes, so we'd like to
29
29
split_name('test_splitName'), ['test', 'split', 'name'])
31
def test_multipleUnderscores(self):
31
def test_multiple_underscores(self):
32
32
"""If there are multiple underscores, but camel case, then someone is
33
33
probably referring to a camel-cased identifier in their name.
110
110
def test_module(self):
111
111
from testdoc.tests import empty
112
self.documenter.gotModule(empty)
114
self.formatter.log, [
115
('title', 'testdoc.tests.empty')])
117
def test_emptyModuleWithDocstrings(self):
118
from testdoc.tests import hastests
119
self.documenter.gotModule(hastests)
121
self.formatter.log, [
122
('title', 'testdoc.tests.hastests'),
123
('para', self.documenter.getDocs(hastests))])
125
def test_emptyCase(self):
126
from testdoc.tests import hastests
127
self.documenter.gotTestClass(hastests.SomeTest)
129
self.formatter.log, [
130
('section', self.documenter.titleCase(['Some'])),
131
('para', self.documenter.getDocs(hastests.SomeTest))])
112
self.documenter.got_module(empty)
115
[('title', self.documenter.format_module('testdoc.tests.empty'))])
117
def test_empty_module_with_docstrings(self):
118
from testdoc.tests import hastests
119
self.documenter.got_module(hastests)
123
self.documenter.format_module('testdoc.tests.hastests')),
124
('para', self.documenter.extract_docs(hastests))])
126
def test_empty_case(self):
127
from testdoc.tests import hastests
128
self.documenter.got_test_class(hastests.SomeTest)
131
[('section', self.documenter.format_test_class('SomeTest')),
132
('para', self.documenter.extract_docs(hastests.SomeTest))])
133
134
def test_method(self):
134
135
from testdoc.tests import hastests
135
self.documenter.gotTest(hastests.SomeTest.test_foo_handles_qux)
137
self.formatter.log, [
139
self.documenter.titleCase(['Foo', 'handles', 'qux'])),
140
('para', self.documenter.getDocs(
141
hastests.SomeTest.test_foo_handles_qux))])
143
def test_titleCase(self):
145
self.documenter.titleCase(['foo', 'BAR', 'a', 'In', 'Baz', '999']),
146
'Foo BAR a in Baz 999')
148
self.documenter.titleCase(['in', 'a', 'bind']),
151
# Docstrings first, then comments, then nothing
136
self.documenter.got_test(hastests.SomeTest.test_foo_handles_qux)
140
self.documenter.format_test('test_foo_handles_qux')),
141
('para', self.documenter.extract_docs(
142
hastests.SomeTest.test_foo_handles_qux))])
144
def test_title_case(self):
146
title_case(['foo', 'BAR', 'a', 'In', 'Baz', '999', 'has']),
147
'Foo BAR a in Baz 999 has')
148
self.assertEqual(title_case(['in', 'a', 'bind']), 'In a Bind')
150
def test_format_module(self):
151
"""The natural language display of a module name is just the name of
154
self.assertEqual('foo.bar.baz',
155
self.documenter.format_module('foo.bar.baz'))
157
def test_format_test_class(self):
158
"""The natural language display of a test class name is the class name
159
split up into words with title-case capitalization and with all
160
mentions of 'Test' stripped out.
162
self.assertEqual('Foo Bar',
163
self.documenter.format_test_class('TestFooBar'))
164
self.assertEqual('Foo Bar',
165
self.documenter.format_test_class('FooBarTest'))
168
def test_format_test(self):
169
"""The natural language display of a test method name is the name split
170
into words with the initial word (usually 'test') dropped off. The
171
phrase uses title-case capitalization.
173
self.assertEqual('Janey has a Gun',
174
self.documenter.format_test('test_janey_has_a_gun'))