-
Notifications
You must be signed in to change notification settings - Fork 0
/
method_doc_tests.py
171 lines (140 loc) · 6.53 KB
/
method_doc_tests.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import unittest
from method_doc import MethodDoc
class TestMethodDoc(unittest.TestCase):
def test_init(self):
expected = '# Foo.Bar () Method\n\n'
actual = MethodDoc('Foo', 'Bar ()').build()
self.assertEqual(expected, actual)
def test_buildReturnsDocWithDescription(self):
expected = ('# Foo.Bar () Method\n\n'
'Description of Foo.Bar\n\n')
doc = MethodDoc('Foo', 'Bar ()')
doc.set_description('Description of Foo.Bar')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWithSignature(self):
expected = ('# Foo.Bar () Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Sub Bar ()\n'
'```\n\n')
doc = MethodDoc('Foo', 'Bar ()')
doc.set_description('Description of Foo.Bar')
doc.set_signature('Public Sub Bar ()')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWhenOneArgument(self):
expected = ('# Foo.Bar (Variant) Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Sub Bar (ByVal Item As Variant)\n'
'```\n\n'
'### Parameters\n\n'
'**Item** `Variant` <br>\n'
'Description of an item.\n\n')
doc = MethodDoc('Foo', 'Bar (Variant)')
doc.set_description('Description of Foo.Bar')
doc.set_signature('Public Sub Bar (ByVal Item As Variant)')
doc.add_parameter('Item', 'Variant', 'Description of an item.')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWhenAtLeastOneArgument(self):
expected = ('# Foo.Bar (Variant, Variant) Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Sub Bar (ByVal Item As Variant, ByVal Item2 As Variant)\n'
'```\n\n'
'### Parameters\n\n'
'**Item** `Variant` <br>\n'
'Description of an item.\n\n'
'**Item2** `Variant` <br>\n'
'Description of an item2.\n\n')
doc = MethodDoc('Foo', 'Bar (Variant, Variant)')
doc.set_description('Description of Foo.Bar')
doc.set_signature(
'Public Sub Bar (ByVal Item As Variant, ByVal Item2 As Variant)')
doc.add_parameter('Item', 'Variant', 'Description of an item.')
doc.add_parameter('Item2', 'Variant', 'Description of an item2.')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWhenMethodIsFunctionZeroArgs(self):
expected = ('# Foo.Bar () Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Function Bar () As String\n'
'```\n\n'
'### Returns\n\n'
'`String` <br>\n'
'Description of return value\n\n')
doc = MethodDoc('Foo', 'Bar ()')
doc.set_description('Description of Foo.Bar')
doc.set_signature('Public Function Bar () As String')
doc.add_returns('String', 'Description of return value')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWhenMethodIsFunctionAtLeastOneArg(self):
expected = ('# Foo.Bar (Variant) Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Function Bar (ByVal Item As Variant) As String\n'
'```\n\n'
'### Parameters\n\n'
'**Item** `Variant` <br>\n'
'Description of an item.\n\n'
'### Returns\n\n'
'`String` <br>\n'
'Description of return value\n\n')
doc = MethodDoc('Foo', 'Bar (Variant)')
doc.set_description('Description of Foo.Bar')
doc.set_signature(
'Public Function Bar (ByVal Item As Variant) As String')
doc.add_parameter('Item', 'Variant', 'Description of an item.')
doc.add_returns('String', 'Description of return value')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWhenErrorDefined(self):
expected = ('# Foo.Bar () Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Sub Bar ()\n'
'```\n\n'
'### Errors\n\n'
'`OnInvalidArgumentError` <br>\n'
'Description of error\n\n')
doc = MethodDoc('Foo', 'Bar ()')
doc.set_description('Description of Foo.Bar')
doc.set_signature('Public Sub Bar ()')
doc.add_error('OnInvalidArgumentError', 'Description of error')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWhenMultipleErrorsDefined(self):
expected = ('# Foo.Bar () Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Sub Bar ()\n'
'```\n\n'
'### Errors\n\n'
'`OnInvalidArgumentError` <br>\n'
'Description of error\n\n'
'`OnArgumentOutOfRangeError` <br>\n'
'Description of error\n\n')
doc = MethodDoc('Foo', 'Bar ()')
doc.set_description('Description of Foo.Bar')
doc.set_signature('Public Sub Bar ()')
doc.add_error('OnInvalidArgumentError', 'Description of error')
doc.add_error('OnArgumentOutOfRangeError', 'Description of error')
self.assertEqual(expected, doc.build())
def test_buildReturnsDocWithExample(self):
expected = ('# Foo.Bar () Method\n\n'
'Description of Foo.Bar\n\n'
'```vb\n'
'Public Sub Bar ()\n'
'```\n\n'
'## Examples\n\n'
'This is an example.\n\n')
doc = MethodDoc('Foo', 'Bar ()')
doc.set_description('Description of Foo.Bar')
doc.set_signature('Public Sub Bar ()')
doc.set_example('This is an example.')
self.assertEqual(expected, doc.build())
def test_buildReturnDocWithRemarks(self):
expected = ('# Foo.Bar () Method\n\n'
'### Remarks\n\n'
'This is an example.')
doc = MethodDoc('Foo', 'Bar ()')
doc.set_example('This is an example.')
if __name__ == "__main__":
unittest.main()