473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ironic doctest bug?

> 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.
Jul 18 '05 #1
2 1396
"Alan G Isaac" <ai****@american.edu> wrote in message
news:10*************@corp.supernews.com...
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.


This was the punchline of course.
Am I overlooking something?
Thanks,
Alan Isaac
Jul 18 '05 #2
[Alan G Isaac]
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.
This was the punchline of course.
Am I overlooking something?
Mostly just this:

http://www.catb.org/~esr/faqs/smart-questions.html

You didn't say which version of Python, or which OS, and didn't ask a
specific question despite a long original post. Those points all
conspired to make the post ignorable.

My guess is that you're using some flavor of Python 2.3. Your
original post contained the only relevant clue:
python doctest.py -v


If you had run it without -v, my guess is that it would have passed.

Looking at the output with -v identifies the failing test when running
with -v. That's
testmod(m1, isprivate=is_private)
in doctest.Tester.rundict's docstring.

Looking at the other tests in the docstring shows that they all add
verbose=0 to their testmod() call, and that this one was unique in not
doing so. So someone was probably a teensy careless when they added
this test. Change the test to
testmod(m1, isprivate=is_private, verbose=0)


so it looks like the others, and then it passes with or without -v.

It's too minor a bug to justify a new Python 2.3 release <wink>. The
problem doesn't exist in Python CVS, so it won't happen in 2.4.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Pierre Rouleau | last post by:
I have a problem writing self-testable modules using doctest when these modules have internationalized strings using gettext _('...'). - The main module of an application (say app.py) calls...
2
by: Michele Simionato | last post by:
Some time ago I hacked a custom solution to run doctests on text files containing documentation. The solution involved this kind of game: tester=doctest.Tester(globs={},verbose=1)...
5
by: Michele Simionato | last post by:
I am getting a strange error with this script: $ cat doctest-threads.py """ >>> import time, threading >>> def example(): .... thread.out = .... while thread.running: .... ...
1
by: David MacKay | last post by:
Hello, I'm a python-list newbie. I've got a question about doctest; perhaps a bug report. I really like doctest, but sometimes doctest gives a failure when the output looks absolutely fine to me...
1
by: Runsun Pan | last post by:
I intend to use the doctect heavily. For this I am thinking of coding a class that comes with a built-in doctest functionality. I'd like to seek for input before I start. The idea is to have a...
2
by: p.lavarre | last post by:
From: http://docs.python.org/lib/doctest-soapbox.html ... Can I somehow tell doctest that it's time to quit? I ask because not all doctest examples are created equal. Some failures are...
0
by: Eric Mahurin | last post by:
Noob here. Just got into python a little over a week ago... One of the (unique?) things I really like about python is the concept of doctesting. But, now I want more! Here's what I'd like to...
12
by: thomas.guest | last post by:
I'm not making progress with the following and would appreciate any help. Here's an interpreted Python session. .... Traceback (most recent call last): File "<stdin>", line 1, in <module>...
6
by: Bzyczek | last post by:
Hello, I have problems with running doctests if I use czech national characters in UTF-8 encoding. I have Python script, which begin with encoding definition: # -*- coding: utf-8 -*- I...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.