ironic doctest bug?

Alan G Isaac aisaac at american.edu
Fri Aug 13 16:06:03 EDT 2004


> python doctest.py -v
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.DocTestSuite.__doc__
0 of 0 examples failed in doctest.DocTestSuite.__doc__
Running doctest.DocTestTestFailure.__doc__
0 of 0 examples failed in doctest.DocTestTestFailure.__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._Tester__record_outcome.__doc__
0 of 0 examples failed in doctest.Tester._Tester__record_outcome.__doc__
Running doctest.Tester._Tester__runone.__doc__
0 of 0 examples failed in doctest.Tester._Tester__runone.__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: import new
Expecting: nothing
ok
Trying: m1 = new.module('_m1')
Expecting: nothing
ok
Trying: m2 = new.module('_m2')
Expecting: nothing
ok
Trying:
test_data = """
def _f():
    '''>>> assert 1 == 1
    '''
def g():
   '''>>> assert 2 != 1
   '''
class H:
   '''>>> assert 2 > 1
   '''
   def bar(self):
       '''>>> assert 1 < 2
       '''
"""
Expecting: nothing
ok
Trying: exec test_data in m1.__dict__
Expecting: nothing
ok
Trying: exec test_data in m2.__dict__
Expecting: nothing
ok
Trying: m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H})
Expecting: nothing
ok
Trying: t = Tester(globs={}, verbose=0, isprivate=is_private)
Expecting: nothing
ok
Trying:
t.rundict(m1.__dict__, "rundict_test", m1)  # _f, f2 and g2 and h2 skipped
Expecting: (0, 3)
ok
Trying: t = Tester(globs={}, verbose=0)
Expecting: nothing
ok
Trying:
t.rundict(m1.__dict__, "rundict_test_pvt", m1)  # Only f2, g2 and h2 skipped
Expecting: (0, 4)
ok
Trying: t = Tester(globs={}, verbose=0)
Expecting: nothing
ok
Trying: t.rundict(m1.__dict__, "rundict_test_pvt")  # None are skipped.
Expecting: (0, 8)
ok
Trying: testmod(m1, isprivate=is_private)
Expecting: (0, 3)
*****************************************************************
Failure in example: testmod(m1, isprivate=is_private)
from line #55 of doctest.Tester.rundict
Expected: (0, 3)
Got:
Running _m1.__doc__
0 of 0 examples failed in _m1.__doc__
Running _m1.H.__doc__
Trying: assert 2 > 1
Expecting: nothing
ok
0 of 1 examples failed in _m1.H.__doc__
Running _m1.H.bar.__doc__
Trying: assert 1 < 2
Expecting: nothing
ok
0 of 1 examples failed in _m1.H.bar.__doc__
Running _m1.g.__doc__
Trying: assert 2 != 1
Expecting: nothing
ok
0 of 1 examples failed in _m1.g.__doc__
1 items had no tests:
    _m1
3 items passed all tests:
   1 tests in _m1.H
   1 tests in _m1.H.bar
   1 tests in _m1.g
3 tests in 4 items.
3 passed and 0 failed.
Test passed.
(0, 3)
1 of 14 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._SpoofOut.__doc__
0 of 0 examples failed in doctest._SpoofOut.__doc__
Running doctest._SpoofOut.__init__.__doc__
0 of 0 examples failed in doctest._SpoofOut.__init__.__doc__
Running doctest._SpoofOut.clear.__doc__
0 of 0 examples failed in doctest._SpoofOut.clear.__doc__
Running doctest._SpoofOut.flush.__doc__
0 of 0 examples failed in doctest._SpoofOut.flush.__doc__
Running doctest._SpoofOut.get.__doc__
0 of 0 examples failed in doctest._SpoofOut.get.__doc__
Running doctest._SpoofOut.write.__doc__
0 of 0 examples failed in doctest._SpoofOut.write.__doc__
Running doctest._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._TestClass.__doc__
Running doctest._TestClass.__init__.__doc__
Trying: t = _TestClass(123)
Expecting: nothing
ok
Trying: print t.get()
Expecting: 123
ok
0 of 2 examples failed in doctest._TestClass.__init__.__doc__
Running doctest._TestClass.get.__doc__
Trying: x = _TestClass(-42)
Expecting: nothing
ok
Trying: print x.get()
Expecting: -42
ok
0 of 2 examples failed in doctest._TestClass.get.__doc__
Running doctest._TestClass.square.__doc__
Trying: _TestClass(13).square().get()
Expecting: 169
ok
0 of 1 examples failed in doctest._TestClass.square.__doc__
Running doctest._expect.__doc__
0 of 0 examples failed in doctest._expect.__doc__
Running doctest._extract_doctests.__doc__
0 of 0 examples failed in doctest._extract_doctests.__doc__
Running doctest._extract_examples.__doc__
0 of 0 examples failed in doctest._extract_examples.__doc__
Running doctest._extract_future_flags.__doc__
0 of 0 examples failed in doctest._extract_future_flags.__doc__
Running doctest._find_tests.__doc__
0 of 0 examples failed in doctest._find_tests.__doc__
Running doctest._from_module.__doc__
0 of 0 examples failed in doctest._from_module.__doc__
Running doctest._get_doctest.__doc__
0 of 0 examples failed in doctest._get_doctest.__doc__
Running doctest._normalize_module.__doc__
0 of 0 examples failed in doctest._normalize_module.__doc__
Running doctest._run_examples.__doc__
0 of 0 examples failed in doctest._run_examples.__doc__
Running doctest._run_examples_inner.__doc__
0 of 0 examples failed in doctest._run_examples_inner.__doc__
Running doctest._tag_out.__doc__
0 of 0 examples failed in doctest._tag_out.__doc__
Running doctest._test.__doc__
0 of 0 examples failed in doctest._test.__doc__
Running doctest._utest.__doc__
0 of 0 examples failed in doctest._utest.__doc__
Running doctest.debug.__doc__
0 of 0 examples failed in doctest.debug.__doc__
Running doctest.is_private.__doc__
Trying: is_private("a.b", "my_func")
Expecting: False
ok
Trying: is_private("____", "_my_func")
Expecting: True
ok
Trying: is_private("someclass", "__init__")
Expecting: False
ok
Trying: is_private("sometypo", "__init_")
Expecting: True
ok
Trying: is_private("x.y.z", "_")
Expecting: True
ok
Trying: is_private("_x.y.z", "__")
Expecting: False
ok
Trying: is_private("", "")  # senseless but consistent
Expecting: False
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.testsource.__doc__
0 of 0 examples failed in doctest.testsource.__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__.bool-int equivalence
Trying: 4 == 4
Expecting: 1
ok
Trying: 4 == 4
Expecting: True
ok
Trying: 4 > 4
Expecting: 0
ok
Trying: 4 > 4
Expecting: False
ok
0 of 4 examples failed in string doctest.__test__.bool-int equivalence
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
30 items had no tests:
    doctest.DocTestSuite
    doctest.DocTestTestFailure
    doctest.Tester._Tester__record_outcome
    doctest.Tester._Tester__runone
    doctest.Tester.__init__
    doctest.Tester.run__test__
    doctest.Tester.summarize
    doctest._SpoofOut
    doctest._SpoofOut.__init__
    doctest._SpoofOut.clear
    doctest._SpoofOut.flush
    doctest._SpoofOut.get
    doctest._SpoofOut.write
    doctest._expect
    doctest._extract_doctests
    doctest._extract_examples
    doctest._extract_future_flags
    doctest._find_tests
    doctest._from_module
    doctest._get_doctest
    doctest._normalize_module
    doctest._run_examples
    doctest._run_examples_inner
    doctest._tag_out
    doctest._test
    doctest._utest
    doctest.debug
    doctest.run_docstring_examples
    doctest.testmod
    doctest.testsource
16 items passed all tests:
   8 tests in doctest
   6 tests in doctest.Tester
  10 tests in doctest.Tester.merge
   3 tests in doctest.Tester.rundoc
   3 tests in doctest.Tester.runstring
   2 tests in doctest._TestClass
   2 tests in doctest._TestClass.__init__
   2 tests in doctest._TestClass.get
   1 tests in doctest._TestClass.square
   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
   4 tests in doctest.__test__.bool-int equivalence
   2 tests in doctest.__test__.string
   7 tests in doctest.is_private
*****************************************************************
1 items had failures:
   1 of  14 in doctest.Tester.rundict
71 tests in 47 items.
70 passed and 1 failed.
***Test Failed*** 1 failures.





More information about the Python-list mailing list