##// END OF EJS Templates
Merge pull request #12009 from kousikmitra/master...
Merge pull request #12009 from kousikmitra/master "Code Cleanup: Remove unused unused utility functions from 'IPython/utils/py3compat.py' #11985

File last commit:

r22963:2961b531
r25332:61a4f1f7 merge
Show More
dtexample.py
157 lines | 2.8 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):
Thomas Kluyver
Fix doctests in IPython.testing
r13393 ... print(i, end=' ')
... print(i+1, end=' ')
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334 ...
Thomas Kluyver
Fix doctests in IPython.testing
r13393 0 1 1 2 2 3
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334 """
return 'pyfunc'
def ipfunc():
"""Some ipython tests...
In [1]: import os
In [3]: 2+3
Out[3]: 5
In [26]: for i in range(3):
Thomas Kluyver
Fix doctests in IPython.testing
r13393 ....: print(i, end=' ')
....: print(i+1, end=' ')
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334 ....:
Thomas Kluyver
Fix doctests in IPython.testing
r13393 0 1 1 2 2 3
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334
Examples that access the operating system work:
In [1]: !echo hello
hello
Paul Ivanov
more unique filename for test...
r10915 In [2]: !echo hello > /tmp/foo_iptest
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334
Paul Ivanov
more unique filename for test...
r10915 In [3]: !cat /tmp/foo_iptest
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334 hello
Paul Ivanov
more unique filename for test...
r10915 In [4]: rm -f /tmp/foo_iptest
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334
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:
Fernando Perez
Checkpoint before merging with upstream
r1482 In [7]: 'hi'
Out[7]: 'hi'
Thomas Kluyver
Fix doctests in IPython.testing
r13393 In [8]: print(repr(_))
Fernando Perez
Checkpoint before merging with upstream
r1482 'hi'
Fernando Perez
Added Nose support for IPython doctests and extension modules.
r1334 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
Implement support for all random tests. Other minor cleanups.
r1430 Normal examples 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
Implement support for all random tests. Other minor cleanups.
r1430 def random_all():
"""A function where we ignore the output of ALL examples.
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Implement support for all random tests. Other minor cleanups.
r1430 Examples:
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Implement support for all random tests. Other minor cleanups.
r1430 # all-random
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Implement support for all random tests. Other minor cleanups.
r1430 This mark tells the testing machinery that all subsequent examples should
be treated as random (ignoring their output). They are still executed,
so if a they raise an error, it will be detected as such, but their
output is completely ignored.
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Implement support for all random tests. Other minor cleanups.
r1430 >>> 1+3
junk goes here...
Fernando Perez
Local checkpoint of changes to testing machinery. Work in progress.
r1403
Fernando Perez
Implement support for all random tests. Other minor cleanups.
r1430 >>> 1+3
klasdfj;
Fernando Perez
Checkpoint where tests are recognized. Random tests not working yet.
r1378
Fernando Perez
Implement support for all random tests. Other minor cleanups.
r1430 >>> 1+2
again, anything goes
blah...
"""
pass
Fernando Perez
Add a few more tests to the test machinery itself.
r1432
def iprand():
"""Some ipython tests with random output.
In [7]: 3+4
Out[7]: 7
Thomas Kluyver
Fix doctests in IPython.testing
r13393 In [8]: print('hello')
Fernando Perez
Add a few more tests to the test machinery itself.
r1432 world # random
In [9]: iprand()
Out[9]: 'iprand'
"""
return 'iprand'
def iprand_all():
"""Some ipython tests with fully random output.
# all-random
In [7]: 1
Out[7]: 99
Thomas Kluyver
Fix doctests in IPython.testing
r13393 In [8]: print('hello')
Fernando Perez
Add a few more tests to the test machinery itself.
r1432 world
In [9]: iprand_all()
Out[9]: 'junk'
"""
return 'iprand_all'