[IPython-dev] Doctest fixes, testing release out
Jörgen Stenarson
jorgen.stenarson at bostream.nu
Thu Sep 13 13:27:02 EDT 2007
>
> The patch was in the end very small (in fact I reduced code), but it
> touches fairly delicate parts of the execution of files, that are
> prone to subtle complications. And it took me a while to understand
> what I had to do, so I may have missed a corner case and shot myself
> in the foot.
>
> Extensive testing would be much appreciated.
>
> Cheers,
>
> f
>
Unfortunately it looks like you have missed some case(s)
The following script demonstrates a problem
# -*- coding: ISO-8859-1 -*-
import sys
def opa():
print sys.version
opa()
this script works properly when called with %run
but subsequent calls of opa() from the prompt fails
as shown below
C:\python\ipython>ipython
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.8.2.svn.r2750 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: %run crash.py
2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
In [2]: opa()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\python\ipython\<ipython console>
C:\python\ipython\crash.py in opa()
3
4 def opa():
----> 5 print sys.version
global sys.version = undefined
6
7 opa()
AttributeError: 'NoneType' object has no attribute 'version'
In [3]:
A second problem is demonstrated below. Multiple calls to
doctest.testmod() generates what look like a progess report on all calls
after the first calls.
At first I tried to fix this by adding a reload(doctest) (test by
uncommenting case2). This doesn't work at all from the ipython prompt,
it causes tests that used to work to fail. This feels like it could be
related to the previous error.
The solution seems to be to uncomment case 3 which resets a global
variable in doctest.
/Jörgen
def a(x):
"""
>>> a(10)
11x
>>> a(31)
32
"""
return x+1
def b(x):
"""
>>> b([3])
3
>>> b([1])
1
"""
return x[0]
def _test():
import doctest
#reload(doctest) #case 2
#doctest.master=None #case 3
doctest.testmod()
if __name__=="__main__":
_test()
print
print " Another _test ".center(70,"-")
print
_test()
**********************************************************************
File "try_doctest.py", line 4, in __main__.a
Failed example:
a(10)
Expected:
11x
Got:
11
**********************************************************************
1 items had failures:
1 of 2 in __main__.a
***Test Failed*** 1 failures.
--------------------------- Another _test ----------------------------
**********************************************************************
File "try_doctest.py", line 4, in __main__.a
Failed example:
a(10)
Expected:
11x
Got:
11
**********************************************************************
1 items had failures:
1 of 2 in __main__.a
***Test Failed*** 1 failures.
*** DocTestRunner.merge: '__main__._test' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__.b' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__.a' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
######################################################################
######################################################################
Uncomment CASE 2
######################################################################
######################################################################
In [1]: %run try_doctest.py
Out[1]: 11
**********************************************************************
File "try_doctest.py", line 4, in __main__.a
Failed example:
a(10)
Expected:
11x
Got nothing
Out[1]: 32
**********************************************************************
File "try_doctest.py", line 6, in __main__.a
Failed example:
a(31)
Expected:
32
Got nothing
Out[1]: 3
**********************************************************************
File "try_doctest.py", line 13, in __main__.b
Failed example:
b([3])
Expected:
3
Got nothing
Out[1]: 1
**********************************************************************
File "try_doctest.py", line 15, in __main__.b
Failed example:
b([1])
Expected:
1
Got nothing
**********************************************************************
2 items had failures:
2 of 2 in __main__.a
2 of 2 in __main__.b
***Test Failed*** 4 failures.
--------------------------- Another _test ----------------------------
Out[1]: 11
**********************************************************************
File "try_doctest.py", line 4, in __main__.a
Failed example:
a(10)
Expected:
11x
Got nothing
Out[1]: 32
**********************************************************************
File "try_doctest.py", line 6, in __main__.a
Failed example:
a(31)
Expected:
32
Got nothing
Out[1]: 3
**********************************************************************
File "try_doctest.py", line 13, in __main__.b
Failed example:
b([3])
Expected:
3
Got nothing
Out[1]: 1
**********************************************************************
File "try_doctest.py", line 15, in __main__.b
Failed example:
b([1])
Expected:
1
Got nothing
**********************************************************************
2 items had failures:
2 of 2 in __main__.a
2 of 2 in __main__.b
***Test Failed*** 4 failures.
In [2]:
######################################################################
######################################################################
Uncomment CASE 3
######################################################################
######################################################################
In [1]: %run try_doctest.py
**********************************************************************
File "try_doctest.py", line 4, in __main__.a
Failed example:
a(10)
Expected:
11x
Got:
11
**********************************************************************
1 items had failures:
1 of 2 in __main__.a
***Test Failed*** 1 failures.
--------------------------- Another _test ----------------------------
**********************************************************************
File "try_doctest.py", line 4, in __main__.a
Failed example:
a(10)
Expected:
11x
Got:
11
**********************************************************************
1 items had failures:
1 of 2 in __main__.a
***Test Failed*** 1 failures.
In [2]:
More information about the IPython-dev
mailing list