Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6db54c6

Browse files
committed
Add std test for doctest.
1 parent ecb6fb9 commit 6db54c6

2 files changed

Lines changed: 301 additions & 0 deletions

File tree

Lib/test/output/test_doctest

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
test_doctest
2+
Running doctest.__doc__
3+
Trying: 1/0
4+
Expecting:
5+
Traceback (innermost last):
6+
File "<stdin>", line 1, in ?
7+
ZeroDivisionError: integer division or modulo by zero
8+
ok
9+
Trying: x = 12
10+
Expecting: nothing
11+
ok
12+
Trying: x
13+
Expecting: 12
14+
ok
15+
Trying:
16+
if x == 13:
17+
print "yes"
18+
else:
19+
print "no"
20+
print "NO"
21+
print "NO!!!"
22+
Expecting:
23+
no
24+
NO
25+
NO!!!
26+
ok
27+
Trying:
28+
if "yes" == \
29+
"y" + \
30+
"es": # in the source code you'll see the doubled backslashes
31+
print 'yes'
32+
Expecting: yes
33+
ok
34+
Trying: assert "Easy!"
35+
Expecting: nothing
36+
ok
37+
Trying: import math
38+
Expecting: nothing
39+
ok
40+
Trying: math.floor(1.9)
41+
Expecting: 1.0
42+
ok
43+
0 of 8 examples failed in doctest.__doc__
44+
Running doctest.Tester.__doc__
45+
Trying: from doctest import Tester
46+
Expecting: nothing
47+
ok
48+
Trying: t = Tester(globs={'x': 42}, verbose=0)
49+
Expecting: nothing
50+
ok
51+
Trying:
52+
t.runstring(r'''
53+
>>> x = x * 2
54+
>>> print x
55+
42
56+
''', 'XYZ')
57+
Expecting:
58+
*****************************************************************
59+
Failure in example: print x
60+
from line #2 of XYZ
61+
Expected: 42
62+
Got: 84
63+
(1, 2)
64+
ok
65+
Trying: t.runstring(">>> x = x * 2\n>>> print x\n84\n", 'example2')
66+
Expecting: (0, 2)
67+
ok
68+
Trying: t.summarize()
69+
Expecting:
70+
1 items had failures:
71+
1 of 2 in XYZ
72+
***Test Failed*** 1 failures.
73+
(1, 4)
74+
ok
75+
Trying: t.summarize(verbose=1)
76+
Expecting:
77+
1 items passed all tests:
78+
2 tests in example2
79+
1 items had failures:
80+
1 of 2 in XYZ
81+
4 tests in 2 items.
82+
3 passed and 1 failed.
83+
***Test Failed*** 1 failures.
84+
(1, 4)
85+
ok
86+
0 of 6 examples failed in doctest.Tester.__doc__
87+
Running doctest.Tester.__init__.__doc__
88+
0 of 0 examples failed in doctest.Tester.__init__.__doc__
89+
Running doctest.Tester.run__test__.__doc__
90+
0 of 0 examples failed in doctest.Tester.run__test__.__doc__
91+
Running doctest.Tester.runstring.__doc__
92+
Trying: t = Tester(globs={}, verbose=1)
93+
Expecting: nothing
94+
ok
95+
Trying:
96+
test = r'''
97+
# just an example
98+
>>> x = 1 + 2
99+
>>> x
100+
3
101+
'''
102+
Expecting: nothing
103+
ok
104+
Trying: t.runstring(test, "Example")
105+
Expecting:
106+
Running string Example
107+
Trying: x = 1 + 2
108+
Expecting: nothing
109+
ok
110+
Trying: x
111+
Expecting: 3
112+
ok
113+
0 of 2 examples failed in string Example
114+
(0, 2)
115+
ok
116+
0 of 3 examples failed in doctest.Tester.runstring.__doc__
117+
Running doctest.Tester.summarize.__doc__
118+
0 of 0 examples failed in doctest.Tester.summarize.__doc__
119+
Running doctest.Tester.rundict.__doc__
120+
Trying:
121+
def _f():
122+
'''>>> assert 1 == 1
123+
'''
124+
Expecting: nothing
125+
ok
126+
Trying:
127+
def g():
128+
'''>>> assert 2 != 1
129+
'''
130+
Expecting: nothing
131+
ok
132+
Trying: d = {"_f": _f, "g": g}
133+
Expecting: nothing
134+
ok
135+
Trying: t = Tester(globs={}, verbose=0)
136+
Expecting: nothing
137+
ok
138+
Trying: t.rundict(d, "rundict_test") # _f is skipped
139+
Expecting: (0, 1)
140+
ok
141+
Trying: t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
142+
Expecting: nothing
143+
ok
144+
Trying: t.rundict(d, "rundict_test_pvt") # both are searched
145+
Expecting: (0, 2)
146+
ok
147+
0 of 7 examples failed in doctest.Tester.rundict.__doc__
148+
Running doctest.Tester.merge.__doc__
149+
Trying: from doctest import Tester
150+
Expecting: nothing
151+
ok
152+
Trying: t1 = Tester(globs={}, verbose=0)
153+
Expecting: nothing
154+
ok
155+
Trying:
156+
t1.runstring('''
157+
>>> x = 12
158+
>>> print x
159+
12
160+
''', "t1example")
161+
Expecting: (0, 2)
162+
ok
163+
Trying: t2 = Tester(globs={}, verbose=0)
164+
Expecting: nothing
165+
ok
166+
Trying:
167+
t2.runstring('''
168+
>>> x = 13
169+
>>> print x
170+
13
171+
''', "t2example")
172+
Expecting: (0, 2)
173+
ok
174+
Trying: common = ">>> assert 1 + 2 == 3\n"
175+
Expecting: nothing
176+
ok
177+
Trying: t1.runstring(common, "common")
178+
Expecting: (0, 1)
179+
ok
180+
Trying: t2.runstring(common, "common")
181+
Expecting: (0, 1)
182+
ok
183+
Trying: t1.merge(t2)
184+
Expecting: *** Tester.merge: 'common' in both testers; summing outcomes.
185+
ok
186+
Trying: t1.summarize(1)
187+
Expecting:
188+
3 items passed all tests:
189+
2 tests in common
190+
2 tests in t1example
191+
2 tests in t2example
192+
6 tests in 3 items.
193+
6 passed and 0 failed.
194+
Test passed.
195+
(0, 6)
196+
ok
197+
0 of 10 examples failed in doctest.Tester.merge.__doc__
198+
Running doctest.Tester.rundoc.__doc__
199+
Trying: t = Tester(globs={}, verbose=0)
200+
Expecting: nothing
201+
ok
202+
Trying:
203+
def _f():
204+
'''Trivial docstring example.
205+
>>> assert 2 == 2
206+
'''
207+
return 32
208+
Expecting: nothing
209+
ok
210+
Trying: t.rundoc(_f) # expect 0 failures in 1 example
211+
Expecting: (0, 1)
212+
ok
213+
0 of 3 examples failed in doctest.Tester.rundoc.__doc__
214+
Running doctest.is_private.__doc__
215+
Trying: is_private("a.b", "my_func")
216+
Expecting: 0
217+
ok
218+
Trying: is_private("____", "_my_func")
219+
Expecting: 1
220+
ok
221+
Trying: is_private("someclass", "__init__")
222+
Expecting: 0
223+
ok
224+
Trying: is_private("sometypo", "__init_")
225+
Expecting: 1
226+
ok
227+
Trying: is_private("x.y.z", "_")
228+
Expecting: 1
229+
ok
230+
Trying: is_private("_x.y.z", "__")
231+
Expecting: 0
232+
ok
233+
Trying: is_private("", "") # senseless but consistent
234+
Expecting: 0
235+
ok
236+
0 of 7 examples failed in doctest.is_private.__doc__
237+
Running doctest.run_docstring_examples.__doc__
238+
0 of 0 examples failed in doctest.run_docstring_examples.__doc__
239+
Running doctest.testmod.__doc__
240+
0 of 0 examples failed in doctest.testmod.__doc__
241+
Running doctest.__test__._TestClass.__doc__
242+
Trying: _TestClass(13).get() + _TestClass(-12).get()
243+
Expecting: 1
244+
ok
245+
Trying: hex(_TestClass(13).square().get())
246+
Expecting: '0xa9'
247+
ok
248+
0 of 2 examples failed in doctest.__test__._TestClass.__doc__
249+
Running doctest.__test__._TestClass.get.__doc__
250+
Trying: x = _TestClass(-42)
251+
Expecting: nothing
252+
ok
253+
Trying: print x.get()
254+
Expecting: -42
255+
ok
256+
0 of 2 examples failed in doctest.__test__._TestClass.get.__doc__
257+
Running doctest.__test__._TestClass.__init__.__doc__
258+
Trying: t = _TestClass(123)
259+
Expecting: nothing
260+
ok
261+
Trying: print t.get()
262+
Expecting: 123
263+
ok
264+
0 of 2 examples failed in doctest.__test__._TestClass.__init__.__doc__
265+
Running doctest.__test__._TestClass.square.__doc__
266+
Trying: _TestClass(13).square().get()
267+
Expecting: 169
268+
ok
269+
0 of 1 examples failed in doctest.__test__._TestClass.square.__doc__
270+
Running string doctest.__test__.string
271+
Trying: x = 1; y = 2
272+
Expecting: nothing
273+
ok
274+
Trying: x + y, x * y
275+
Expecting: (3, 2)
276+
ok
277+
0 of 2 examples failed in string doctest.__test__.string
278+
5 items had no tests:
279+
doctest.Tester.__init__
280+
doctest.Tester.run__test__
281+
doctest.Tester.summarize
282+
doctest.run_docstring_examples
283+
doctest.testmod
284+
12 items passed all tests:
285+
8 tests in doctest
286+
6 tests in doctest.Tester
287+
10 tests in doctest.Tester.merge
288+
7 tests in doctest.Tester.rundict
289+
3 tests in doctest.Tester.rundoc
290+
3 tests in doctest.Tester.runstring
291+
2 tests in doctest.__test__._TestClass
292+
2 tests in doctest.__test__._TestClass.__init__
293+
2 tests in doctest.__test__._TestClass.get
294+
1 tests in doctest.__test__._TestClass.square
295+
2 tests in doctest.__test__.string
296+
7 tests in doctest.is_private
297+
53 tests in 17 items.
298+
53 passed and 0 failed.
299+
Test passed.

Lib/test/test_doctest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import doctest
2+
doctest.testmod(doctest, verbose=1)

0 commit comments

Comments
 (0)