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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
test_doctest
Running doctest.__doc__
Trying: 1/0
Expecting:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ZeroDivisionError: integer division or modulo by zero
ok
Trying: x = 12
Expecting: nothing
ok
Trying: x
Expecting: 12
ok
Trying:
if x == 13:
print "yes"
else:
print "no"
print "NO"
print "NO!!!"
Expecting:
no
NO
NO!!!
ok
Trying:
if "yes" == \
"y" + \
"es": # in the source code you'll see the doubled backslashes
print 'yes'
Expecting: yes
ok
Trying: assert "Easy!"
Expecting: nothing
ok
Trying: import math
Expecting: nothing
ok
Trying: math.floor(1.9)
Expecting: 1.0
ok
0 of 8 examples failed in doctest.__doc__
Running doctest.Tester.__doc__
Trying: from doctest import Tester
Expecting: nothing
ok
Trying: t = Tester(globs={'x': 42}, verbose=0)
Expecting: nothing
ok
Trying:
t.runstring(r'''
>>> x = x * 2
>>> print x
42
''', 'XYZ')
Expecting:
*****************************************************************
Failure in example: print x
from line #2 of XYZ
Expected: 42
Got: 84
(1, 2)
ok
Trying: t.runstring(">>> x = x * 2\n>>> print x\n84\n", 'example2')
Expecting: (0, 2)
ok
Trying: t.summarize()
Expecting:
1 items had failures:
1 of 2 in XYZ
***Test Failed*** 1 failures.
(1, 4)
ok
Trying: t.summarize(verbose=1)
Expecting:
1 items passed all tests:
2 tests in example2
1 items had failures:
1 of 2 in XYZ
4 tests in 2 items.
3 passed and 1 failed.
***Test Failed*** 1 failures.
(1, 4)
ok
0 of 6 examples failed in doctest.Tester.__doc__
Running doctest.Tester.__init__.__doc__
0 of 0 examples failed in doctest.Tester.__init__.__doc__
Running doctest.Tester.run__test__.__doc__
0 of 0 examples failed in doctest.Tester.run__test__.__doc__
Running doctest.Tester.runstring.__doc__
Trying: t = Tester(globs={}, verbose=1)
Expecting: nothing
ok
Trying:
test = r'''
# just an example
>>> x = 1 + 2
>>> x
3
'''
Expecting: nothing
ok
Trying: t.runstring(test, "Example")
Expecting:
Running string Example
Trying: x = 1 + 2
Expecting: nothing
ok
Trying: x
Expecting: 3
ok
0 of 2 examples failed in string Example
(0, 2)
ok
0 of 3 examples failed in doctest.Tester.runstring.__doc__
Running doctest.Tester.summarize.__doc__
0 of 0 examples failed in doctest.Tester.summarize.__doc__
Running doctest.Tester.rundict.__doc__
Trying:
def _f():
'''>>> assert 1 == 1
'''
Expecting: nothing
ok
Trying:
def g():
'''>>> assert 2 != 1
'''
Expecting: nothing
ok
Trying: d = {"_f": _f, "g": g}
Expecting: nothing
ok
Trying: t = Tester(globs={}, verbose=0)
Expecting: nothing
ok
Trying: t.rundict(d, "rundict_test") # _f is skipped
Expecting: (0, 1)
ok
Trying: t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
Expecting: nothing
ok
Trying: t.rundict(d, "rundict_test_pvt") # both are searched
Expecting: (0, 2)
ok
0 of 7 examples failed in doctest.Tester.rundict.__doc__
Running doctest.Tester.merge.__doc__
Trying: from doctest import Tester
Expecting: nothing
ok
Trying: t1 = Tester(globs={}, verbose=0)
Expecting: nothing
ok
Trying:
t1.runstring('''
>>> x = 12
>>> print x
12
''', "t1example")
Expecting: (0, 2)
ok
Trying: t2 = Tester(globs={}, verbose=0)
Expecting: nothing
ok
Trying:
t2.runstring('''
>>> x = 13
>>> print x
13
''', "t2example")
Expecting: (0, 2)
ok
Trying: common = ">>> assert 1 + 2 == 3\n"
Expecting: nothing
ok
Trying: t1.runstring(common, "common")
Expecting: (0, 1)
ok
Trying: t2.runstring(common, "common")
Expecting: (0, 1)
ok
Trying: t1.merge(t2)
Expecting: *** Tester.merge: 'common' in both testers; summing outcomes.
ok
Trying: t1.summarize(1)
Expecting:
3 items passed all tests:
2 tests in common
2 tests in t1example
2 tests in t2example
6 tests in 3 items.
6 passed and 0 failed.
Test passed.
(0, 6)
ok
0 of 10 examples failed in doctest.Tester.merge.__doc__
Running doctest.Tester.rundoc.__doc__
Trying: t = Tester(globs={}, verbose=0)
Expecting: nothing
ok
Trying:
def _f():
'''Trivial docstring example.
>>> assert 2 == 2
'''
return 32
Expecting: nothing
ok
Trying: t.rundoc(_f) # expect 0 failures in 1 example
Expecting: (0, 1)
ok
0 of 3 examples failed in doctest.Tester.rundoc.__doc__
Running doctest.is_private.__doc__
Trying: is_private("a.b", "my_func")
Expecting: 0
ok
Trying: is_private("____", "_my_func")
Expecting: 1
ok
Trying: is_private("someclass", "__init__")
Expecting: 0
ok
Trying: is_private("sometypo", "__init_")
Expecting: 1
ok
Trying: is_private("x.y.z", "_")
Expecting: 1
ok
Trying: is_private("_x.y.z", "__")
Expecting: 0
ok
Trying: is_private("", "") # senseless but consistent
Expecting: 0
ok
0 of 7 examples failed in doctest.is_private.__doc__
Running doctest.run_docstring_examples.__doc__
0 of 0 examples failed in doctest.run_docstring_examples.__doc__
Running doctest.testmod.__doc__
0 of 0 examples failed in doctest.testmod.__doc__
Running doctest.__test__._TestClass.__doc__
Trying: _TestClass(13).get() + _TestClass(-12).get()
Expecting: 1
ok
Trying: hex(_TestClass(13).square().get())
Expecting: '0xa9'
ok
0 of 2 examples failed in doctest.__test__._TestClass.__doc__
Running doctest.__test__._TestClass.get.__doc__
Trying: x = _TestClass(-42)
Expecting: nothing
ok
Trying: print x.get()
Expecting: -42
ok
0 of 2 examples failed in doctest.__test__._TestClass.get.__doc__
Running doctest.__test__._TestClass.__init__.__doc__
Trying: t = _TestClass(123)
Expecting: nothing
ok
Trying: print t.get()
Expecting: 123
ok
0 of 2 examples failed in doctest.__test__._TestClass.__init__.__doc__
Running doctest.__test__._TestClass.square.__doc__
Trying: _TestClass(13).square().get()
Expecting: 169
ok
0 of 1 examples failed in doctest.__test__._TestClass.square.__doc__
Running string doctest.__test__.string
Trying: x = 1; y = 2
Expecting: nothing
ok
Trying: x + y, x * y
Expecting: (3, 2)
ok
0 of 2 examples failed in string doctest.__test__.string
5 items had no tests:
doctest.Tester.__init__
doctest.Tester.run__test__
doctest.Tester.summarize
doctest.run_docstring_examples
doctest.testmod
12 items passed all tests:
8 tests in doctest
6 tests in doctest.Tester
10 tests in doctest.Tester.merge
7 tests in doctest.Tester.rundict
3 tests in doctest.Tester.rundoc
3 tests in doctest.Tester.runstring
2 tests in doctest.__test__._TestClass
2 tests in doctest.__test__._TestClass.__init__
2 tests in doctest.__test__._TestClass.get
1 tests in doctest.__test__._TestClass.square
2 tests in doctest.__test__.string
7 tests in doctest.is_private
53 tests in 17 items.
53 passed and 0 failed.
Test passed.
|