##// END OF EJS Templates
Ported the IPython Sphinx directive to 0.11....
Ported the IPython Sphinx directive to 0.11. This was originally written by John Hunter for the 0.10 API, now it works with 0.11. We still need to automate its test suite, but at least now it runs and the script itself can be executed as a test that produces screen output and figures in a subdir.

File last commit:

r2398:f173ff8e
r2439:858c6e09
Show More
test_iplib.py
75 lines | 2.7 KiB | text/x-python | PythonLexer
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859 """Tests for the key iplib module, where the main ipython class is defined.
"""
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
Brian Granger
iplib.py => core/iplib.py and updated tests and imports.
r2028 from IPython.core import iplib
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 from IPython.testing import decorators as dec
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
# Useful global ipapi object and main IPython one. Unfortunately we have a
# long precedent of carrying the 'ipapi' global object which is injected into
# the system namespace as _ip, but that keeps a pointer to the actual IPython
# InteractiveShell instance, which is named IP. Since in testing we do need
# access to the real thing (we want to probe beyond what ipapi exposes), make
# here a global reference to each. In general, things that are exposed by the
# ipapi instance should be read from there, but we also will often need to use
# the actual IPython one.
Fernando Perez
Allow user_setup to be called multiple times.
r1903
Fernando Perez
Fix tests when run outside iptest.
r1956 # Get the public instance of IPython, and if it's None, make one so we can use
# it for testing
ip = ipapi.get()
if ip is None:
# IPython not running yet, make one from the testing machinery for
# consistency when the test suite is being run via iptest
from IPython.testing.plugin import ipdoctest
ip = ipapi.get()
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."""
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 # The number of variables in the private user_config_ns is not zero, but it
# should be constant regardless of what we do
nvars_config_ns = len(ip.user_config_ns)
# 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
elif ns is ip.user_config_ns:
nvars_expected = nvars_config_ns
else:
nvars_expected = 0
yield nt.assert_equals(len(ns), nvars_expected)