##// END OF EJS Templates
Cleanups, document, working on support for full random tests.
Cleanups, document, working on support for full random tests.

File last commit:

r1429:ff48a73e
r1429:ff48a73e
Show More
dtexample.py
124 lines | 2.0 KiB | text/x-python | PythonLexer
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334 """Simple example using doctests.
This file just contains doctests both using plain python and IPython prompts.
All tests should be loaded by nose.
"""
def pyfunc():
"""Some pure python tests...
>>> pyfunc()
'pyfunc'
>>> import os
>>> 2+3
5
>>> for i in range(3):
... print i,
... print i+1,
...
0 1 1 2 2 3
"""
return 'pyfunc'
def ipfunc():
"""Some ipython tests...
In [1]: import os
In [2]: cd /
/
In [3]: 2+3
Out[3]: 5
In [26]: for i in range(3):
....: print i,
....: print i+1,
....:
0 1 1 2 2 3
Examples that access the operating system work:
In [1]: !echo hello
hello
In [2]: !echo hello > /tmp/foo
In [3]: !cat /tmp/foo
hello
In [4]: rm -f /tmp/foo
It's OK to use '_' for the last result, but do NOT try to use IPython's
numbered history of _NN outputs, since those won't exist under the
doctest environment:
In [7]: 3+4
Out[7]: 7
In [8]: _+3
Out[8]: 10
In [9]: ipfunc()
Out[9]: 'ipfunc'
"""
return 'ipfunc'
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Fix directory handling bug in tests, other small cleanups.
r1428 def ranfunc():
"""A function with some random output.
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 Normal inputs are verified as usual:
Fernando Perez
Fix directory handling bug in tests, other small cleanups.
r1428 >>> 1+3
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 4
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 But if you put '# random' in the output, it is ignored:
Fernando Perez
Fix directory handling bug in tests, other small cleanups.
r1428 >>> 1+3
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 junk goes here... # random
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Fix directory handling bug in tests, other small cleanups.
r1428 >>> 1+2
again, anything goes #random
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 if multiline, the random mark is only needed once.
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 >>> 1+2
You can also put the random marker at the end:
# random
>>> 1+2
# random
.. or at the beginning.
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 More correct input is properly verified:
Fernando Perez
Fix directory handling bug in tests, other small cleanups.
r1428 >>> ranfunc()
'ranfunc'
"""
return 'ranfunc'
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 if 0:
Fernando Perez
Local checkpoint of changes to testing machinery. Work in progress.
r1403 def ranf2():
Fernando Perez
Cleanups, document, working on support for full random tests.
r1429 """A function whose examples' output are completely ignored.
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Local checkpoint of changes to testing machinery. Work in progress.
r1403 Examples:
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Local checkpoint of changes to testing machinery. Work in progress.
r1403 #all-random
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Local checkpoint of changes to testing machinery. Work in progress.
r1403 >>> 1+3
junk goes here...
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Local checkpoint of changes to testing machinery. Work in progress.
r1403 >>> 1+3
klasdfj;
>>> 1+2
again, anything goes
blah...
"""
return 'ranf2'
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378