mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
This makes verbose-mode output easier to dig thru, and removes an accidental dependence on the order of dict.items() (made visible by recent changes to dictobject.c).
301 lines
6.5 KiB
Text
301 lines
6.5 KiB
Text
test_doctest
|
|
Running doctest.__doc__
|
|
Trying: [1, 2, 3].remove(42)
|
|
Expecting:
|
|
Traceback (most recent call last):
|
|
File "<stdin>", line 1, in ?
|
|
ValueError: list.remove(x): x not in list
|
|
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.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.run__test__.__doc__
|
|
0 of 0 examples failed in doctest.Tester.run__test__.__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.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.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.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.__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.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.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.
|