##// END OF EJS Templates
introduce is_url() replacing validate_url() in cases where it is used in a control structure (as opposed to an assert)
introduce is_url() replacing validate_url() in cases where it is used in a control structure (as opposed to an assert)

File last commit:

r4896:a2d83e41
r5078:bc86f8b8
Show More
test_iplib.py
272 lines | 6.8 KiB | text/x-python | PythonLexer
Brian Granger
Moving and renaming in preparation of subclassing InteractiveShell....
r2760 """Tests for the key interactiveshell module, where the main ipython class is defined.
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859 """
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908 #-----------------------------------------------------------------------------
# Module imports
#-----------------------------------------------------------------------------
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908 # stdlib
import os
import shutil
import tempfile
# third party
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859 import nose.tools as nt
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908 # our own packages
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 from IPython.testing import decorators as dec
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 from IPython.testing.globalipapp import get_ipython
Thomas Kluyver
Fix almost all IPython.core tests for Python 3.
r4896 from IPython.utils import py3compat
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 # Get the public instance of IPython
ip = get_ipython()
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908
#-----------------------------------------------------------------------------
# Test functions
#-----------------------------------------------------------------------------
Fernando Perez
Fix problems with multiline doctests and add docs about testing....
r1868
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 @dec.parametric
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859 def test_reset():
"""reset must clear most namespaces."""
Brian Granger
More work to address review comments....
r2509 # The number of variables in the private user_ns_hidden is not zero, but it
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 # should be constant regardless of what we do
Brian Granger
More work to address review comments....
r2509 nvars_config_ns = len(ip.user_ns_hidden)
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398
# Check that reset runs without error
ip.reset()
# Once we've reset it (to clear of any junk that might have been there from
# other tests, we can count how many variables are in the user's namespace
nvars_user_ns = len(ip.user_ns)
# Now add a few variables to user_ns, and check that reset clears them
ip.user_ns['x'] = 1
ip.user_ns['y'] = 1
ip.reset()
# Finally, check that all namespaces have only as many variables as we
# expect to find in them:
Brian Granger
Continuing a massive refactor of everything.
r2205 for ns in ip.ns_refs_table:
if ns is ip.user_ns:
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 nvars_expected = nvars_user_ns
Brian Granger
More work to address review comments....
r2509 elif ns is ip.user_ns_hidden:
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 nvars_expected = nvars_config_ns
else:
nvars_expected = 0
yield nt.assert_equals(len(ns), nvars_expected)
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440
# Tests for reporting of exceptions in various modes, handling of SystemExit,
Brian Granger
Moving and renaming in preparation of subclassing InteractiveShell....
r2760 # and %tb functionality. This is really a mix of testing ultraTB and interactiveshell.
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440
def doctest_tb_plain():
"""
In [18]: xmode plain
Exception reporting mode: Plain
In [19]: run simpleerr.py
Traceback (most recent call last):
...line 32, in <module>
bar(mode)
...line 16, in bar
div0()
...line 8, in div0
x/y
Thomas Kluyver
Start using py3compat module.
r4731 ZeroDivisionError: ...
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 """
def doctest_tb_context():
"""
In [3]: xmode context
Exception reporting mode: Context
In [4]: run simpleerr.py
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<BLANKLINE>
... in <module>()
30 mode = 'div'
31
---> 32 bar(mode)
<BLANKLINE>
... in bar(mode)
14 "bar"
15 if mode=='div':
---> 16 div0()
17 elif mode=='exit':
18 try:
<BLANKLINE>
... in div0()
6 x = 1
7 y = 0
----> 8 x/y
9
10 def sysexit(stat, mode):
<BLANKLINE>
Thomas Kluyver
Start using py3compat module.
r4731 ZeroDivisionError: ...
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 """
def doctest_tb_verbose():
"""
In [5]: xmode verbose
Exception reporting mode: Verbose
In [6]: run simpleerr.py
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<BLANKLINE>
... in <module>()
30 mode = 'div'
31
---> 32 bar(mode)
global bar = <function bar at ...>
global mode = 'div'
<BLANKLINE>
... in bar(mode='div')
14 "bar"
15 if mode=='div':
---> 16 div0()
global div0 = <function div0 at ...>
17 elif mode=='exit':
18 try:
<BLANKLINE>
... in div0()
6 x = 1
7 y = 0
----> 8 x/y
x = 1
y = 0
9
10 def sysexit(stat, mode):
<BLANKLINE>
Thomas Kluyver
Start using py3compat module.
r4731 ZeroDivisionError: ...
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 """
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 @py3compat.u_format
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 def doctest_tb_sysexit():
"""
In [17]: %xmode plain
Exception reporting mode: Plain
In [18]: %run simpleerr.py exit
An exception has occurred, use %tb to see the full traceback.
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 SystemExit: (1, {u}'Mode = exit')
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440
In [19]: %run simpleerr.py exit 2
An exception has occurred, use %tb to see the full traceback.
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 SystemExit: (2, {u}'Mode = exit')
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440
In [20]: %tb
Traceback (most recent call last):
File ... in <module>
bar(mode)
File ... line 22, in bar
sysexit(stat, mode)
File ... line 11, in sysexit
raise SystemExit(stat, 'Mode = %s' % mode)
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 SystemExit: (2, {u}'Mode = exit')
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440
In [21]: %xmode context
Exception reporting mode: Context
In [22]: %tb
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
<BLANKLINE>
...<module>()
30 mode = 'div'
31
---> 32 bar(mode)
<BLANKLINE>
...bar(mode)
20 except:
21 stat = 1
---> 22 sysexit(stat, mode)
23 else:
24 raise ValueError('Unknown mode')
<BLANKLINE>
...sysexit(stat, mode)
9
10 def sysexit(stat, mode):
---> 11 raise SystemExit(stat, 'Mode = %s' % mode)
12
13 def bar(mode):
<BLANKLINE>
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 SystemExit: (2, {u}'Mode = exit')
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440
In [23]: %xmode verbose
Exception reporting mode: Verbose
In [24]: %tb
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
<BLANKLINE>
... in <module>()
30 mode = 'div'
31
---> 32 bar(mode)
global bar = <function bar at ...>
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 global mode = {u}'exit'
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 <BLANKLINE>
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 ... in bar(mode={u}'exit')
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 20 except:
21 stat = 1
---> 22 sysexit(stat, mode)
global sysexit = <function sysexit at ...>
stat = 2
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 mode = {u}'exit'
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 23 else:
24 raise ValueError('Unknown mode')
<BLANKLINE>
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 ... in sysexit(stat=2, mode={u}'exit')
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 9
10 def sysexit(stat, mode):
---> 11 raise SystemExit(stat, 'Mode = %s' % mode)
global SystemExit = undefined
stat = 2
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 mode = {u}'exit'
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 12
13 def bar(mode):
<BLANKLINE>
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 SystemExit: (2, {u}'Mode = exit')
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 """
Fernando Perez
Move a few test into proper suite, clean up unused ones....
r2656
Thomas Kluyver
Remove runlines method and calls to it.
r3752 def test_run_cell():
Fernando Perez
Move a few test into proper suite, clean up unused ones....
r2656 import textwrap
Thomas Kluyver
Remove runlines method and calls to it.
r3752 ip.run_cell('a = 10\na+=1')
ip.run_cell('assert a == 11\nassert 1')
Fernando Perez
Move a few test into proper suite, clean up unused ones....
r2656
nt.assert_equals(ip.user_ns['a'], 11)
complex = textwrap.dedent("""
if 1:
print "hello"
if 1:
print "world"
if 2:
print "foo"
if 3:
print "bar"
if 4:
print "bar"
""")
# Simply verifies that this kind of input is run
Thomas Kluyver
Remove runlines method and calls to it.
r3752 ip.run_cell(complex)
Fernando Perez
Move a few test into proper suite, clean up unused ones....
r2656
def test_db():
"""Test the internal database used for variable persistence."""
ip.db['__unittest_'] = 12
nt.assert_equals(ip.db['__unittest_'], 12)
del ip.db['__unittest_']
assert '__unittest_' not in ip.db