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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# Copyright (c) 2007-2010 testdoc authors. See LICENSE for details.
import unittest
from testdoc.documenter import Documenter, split_name, title_case
from testdoc.reflect import extract_docs
class TestSplitName(unittest.TestCase):
def test_single_word(self):
self.assertEqual(split_name('single'), ['single'])
def test_underscores(self):
self.assertEqual(split_name('split_name'), ['split', 'name'])
def test_camel_case(self):
self.assertEqual(split_name('splitName'), ['split', 'name'])
self.assertEqual(
split_name('splitLongName'), ['split', 'long', 'name'])
self.assertEqual(split_name('splitAName'), ['split', 'a', 'name'])
def test_camel_case_with_caps(self):
self.assertEqual(split_name('splitDNSName'), ['split', 'DNS', 'name'])
def test_single_underscore(self):
"""Single underscores are used for reflection prefixes, so we'd like to
ignore them.
"""
self.assertEqual(
split_name('test_splitName'), ['test', 'split', 'name'])
def test_multiple_underscores(self):
"""If there are multiple underscores, but camel case, then someone is
probably referring to a camel-cased identifier in their name.
"""
self.assertEqual(
split_name('test_splitName_works'), ['test', 'splitName', 'works'])
def test_numbers(self):
self.assertEqual(
split_name('test300Name'), ['test', '300', 'name'])
class MockFormatter(object):
def __init__(self):
self.log = []
def title(self, name):
self.log.append(('title', name))
def section(self, name):
self.log.append(('section', name))
def subsection(self, name):
self.log.append(('subsection', name))
def paragraph(self, text):
self.log.append(('para', text))
class TestDocumenter(unittest.TestCase):
def setUp(self):
self.formatter = MockFormatter()
self.documenter = Documenter(self.formatter)
def test_module(self):
from testdoc.tests import empty
self.documenter.got_module(empty)
self.assertEqual(
self.formatter.log,
[('title', self.documenter.format_module('testdoc.tests.empty'))])
def test_empty_module_with_docstrings(self):
from testdoc.tests import hastests
self.documenter.got_module(hastests)
self.assertEqual(
self.formatter.log,
[('title',
self.documenter.format_module('testdoc.tests.hastests')),
('para', extract_docs(hastests))])
def test_empty_case(self):
from testdoc.tests import hastests
self.documenter.got_test_class(hastests.SomeTest)
self.assertEqual(
self.formatter.log,
[('section', self.documenter.format_test_class('SomeTest')),
('para', extract_docs(hastests.SomeTest))])
def test_method(self):
from testdoc.tests import hastests
self.documenter.got_test(hastests.SomeTest.test_foo_handles_qux)
self.assertEqual(
self.formatter.log,
[('subsection',
self.documenter.format_test('test_foo_handles_qux')),
('para', extract_docs(hastests.SomeTest.test_foo_handles_qux))])
def test_title_case(self):
self.assertEqual(
title_case(['foo', 'BAR', 'a', 'In', 'Baz', '999', 'has']),
'Foo BAR a in Baz 999 has')
self.assertEqual(title_case(['in', 'a', 'bind']), 'In a Bind')
def test_format_module(self):
"""The natural language display of a module name is just the name of
the module.
"""
self.assertEqual('foo.bar.baz',
self.documenter.format_module('foo.bar.baz'))
def test_format_test_class(self):
"""The natural language display of a test class name is the class name
split up into words with title-case capitalization and with all
mentions of 'Test' stripped out.
"""
self.assertEqual('Foo Bar',
self.documenter.format_test_class('TestFooBar'))
self.assertEqual('Foo Bar',
self.documenter.format_test_class('FooBarTest'))
def test_format_test(self):
"""The natural language display of a test method name is the name split
into words with the initial word (usually 'test') dropped off. The
phrase uses title-case capitalization.
"""
self.assertEqual('Janey has a Gun',
self.documenter.format_test('test_janey_has_a_gun'))
|