test_iplib.py
56 lines
| 2.0 KiB
| text/x-python
|
PythonLexer
Fernando Perez
|
r1859 | """Tests for the key iplib module, where the main ipython class is defined. | |
""" | |||
Fernando Perez
|
r1908 | #----------------------------------------------------------------------------- | |
# Module imports | |||
#----------------------------------------------------------------------------- | |||
Fernando Perez
|
r1859 | ||
Fernando Perez
|
r1908 | # stdlib | |
import os | |||
import shutil | |||
import tempfile | |||
# third party | |||
Fernando Perez
|
r1859 | import nose.tools as nt | |
Fernando Perez
|
r1908 | # our own packages | |
Brian Granger
|
r2028 | from IPython.core import iplib | |
Brian Granger
|
r2027 | from IPython.core import ipapi | |
Brian Granger
|
r2322 | ||
Fernando Perez
|
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
|
r1903 | ||
Fernando Perez
|
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
|
r1908 | ||
#----------------------------------------------------------------------------- | |||
# Test functions | |||
#----------------------------------------------------------------------------- | |||
Fernando Perez
|
r1868 | ||
Fernando Perez
|
r1859 | def test_reset(): | |
"""reset must clear most namespaces.""" | |||
Brian Granger
|
r2205 | ip.reset() # first, it should run without error | |
Fernando Perez
|
r1859 | # Then, check that most namespaces end up empty | |
Brian Granger
|
r2205 | for ns in ip.ns_refs_table: | |
if ns is ip.user_ns: | |||
Fernando Perez
|
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
|
r1903 | ||
Brian Granger
|
r1964 |