##// END OF EJS Templates
ipapi.get now returns None if there are no InteractiveShells running....
ipapi.get now returns None if there are no InteractiveShells running. It used to simply raise an IndexError, which was bad.

File last commit:

r2205:8ce57664
r2292:146be237
Show More
test_iplib.py
79 lines | 2.9 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
Brian Granger
Massive, crazy refactoring of everything....
r2202 from IPython.core.oldusersetup import user_setup
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
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859 def test_reset():
"""reset must clear most namespaces."""
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.reset() # first, it should run without error
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859 # Then, check that most namespaces end up empty
Brian Granger
Continuing a massive refactor of everything.
r2205 for ns in ip.ns_refs_table:
if ns is ip.user_ns:
Fernando Perez
Fix https://bugs.launchpad.net/ipython/+bug/239054...
r1859 # The user namespace is reset with some data, so we can't check for
# it being empty
continue
nt.assert_equals(len(ns),0)
Fernando Perez
Allow user_setup to be called multiple times.
r1903
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908 # make sure that user_setup can be run re-entrantly in 'install' mode.
Fernando Perez
Allow user_setup to be called multiple times.
r1903 def test_user_setup():
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908 # use a lambda to pass kwargs to the generator
Brian Granger
Massive, crazy refactoring of everything....
r2202 user_setup = lambda a,k: user_setup(*a,**k)
Fernando Perez
Small formatting fixes to address Jorgen's last code review.
r1922 kw = dict(mode='install', interactive=False)
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908
# Call the user setup and verify that the directory exists
Brian Granger
Continuing a massive refactor of everything.
r2205 yield user_setup, (ip.config.IPYTHONDIR,''), kw
yield os.path.isdir, ip.config.IPYTHONDIR
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908
# Now repeat the operation with a non-existent directory. Check both that
# the call succeeds and that the directory is created.
tmpdir = tempfile.mktemp(prefix='ipython-test-')
Brian Granger
Fix for ticket https://bugs.launchpad.net/bugs/362458...
r1964 # Use a try with an empty except because try/finally doesn't work with a
# yield in Python 2.4.
Fernando Perez
Make user_setup a top-level function in iplib and add better tests....
r1908 try:
Fernando Perez
Small formatting fixes to address Jorgen's last code review.
r1922 yield user_setup, (tmpdir,''), kw
yield os.path.isdir, tmpdir
Brian Granger
Fix for ticket https://bugs.launchpad.net/bugs/362458...
r1964 except:
pass
# Clean up the temp dir once done
shutil.rmtree(tmpdir)