##// END OF EJS Templates
Merging Fernando's fixes to test_iplib.py.
Brian Granger -
r1957:e73c1d57 merge
parent child Browse files
Show More
@@ -1,68 +1,76 b''
1 """Tests for the key iplib module, where the main ipython class is defined.
1 """Tests for the key iplib module, where the main ipython class is defined.
2 """
2 """
3 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
4 # Module imports
4 # Module imports
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6
6
7 # stdlib
7 # stdlib
8 import os
8 import os
9 import shutil
9 import shutil
10 import tempfile
10 import tempfile
11
11
12 # third party
12 # third party
13 import nose.tools as nt
13 import nose.tools as nt
14
14
15 # our own packages
15 # our own packages
16 from IPython import iplib
16 from IPython import ipapi, iplib
17
17
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Globals
19 # Globals
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 # Useful global ipapi object and main IPython one. Unfortunately we have a
22 # Useful global ipapi object and main IPython one. Unfortunately we have a
23 # long precedent of carrying the 'ipapi' global object which is injected into
23 # long precedent of carrying the 'ipapi' global object which is injected into
24 # the system namespace as _ip, but that keeps a pointer to the actual IPython
24 # the system namespace as _ip, but that keeps a pointer to the actual IPython
25 # InteractiveShell instance, which is named IP. Since in testing we do need
25 # InteractiveShell instance, which is named IP. Since in testing we do need
26 # access to the real thing (we want to probe beyond what ipapi exposes), make
26 # access to the real thing (we want to probe beyond what ipapi exposes), make
27 # here a global reference to each. In general, things that are exposed by the
27 # here a global reference to each. In general, things that are exposed by the
28 # ipapi instance should be read from there, but we also will often need to use
28 # ipapi instance should be read from there, but we also will often need to use
29 # the actual IPython one.
29 # the actual IPython one.
30
30
31 ip = _ip # This is the ipapi instance
31 # Get the public instance of IPython, and if it's None, make one so we can use
32 # it for testing
33 ip = ipapi.get()
34 if ip is None:
35 # IPython not running yet, make one from the testing machinery for
36 # consistency when the test suite is being run via iptest
37 from IPython.testing.plugin import ipdoctest
38 ip = ipapi.get()
39
32 IP = ip.IP # This is the actual IPython shell 'raw' object.
40 IP = ip.IP # This is the actual IPython shell 'raw' object.
33
41
34 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
35 # Test functions
43 # Test functions
36 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
37
45
38 def test_reset():
46 def test_reset():
39 """reset must clear most namespaces."""
47 """reset must clear most namespaces."""
40 IP.reset() # first, it should run without error
48 IP.reset() # first, it should run without error
41 # Then, check that most namespaces end up empty
49 # Then, check that most namespaces end up empty
42 for ns in IP.ns_refs_table:
50 for ns in IP.ns_refs_table:
43 if ns is IP.user_ns:
51 if ns is IP.user_ns:
44 # The user namespace is reset with some data, so we can't check for
52 # The user namespace is reset with some data, so we can't check for
45 # it being empty
53 # it being empty
46 continue
54 continue
47 nt.assert_equals(len(ns),0)
55 nt.assert_equals(len(ns),0)
48
56
49
57
50 # make sure that user_setup can be run re-entrantly in 'install' mode.
58 # make sure that user_setup can be run re-entrantly in 'install' mode.
51 def test_user_setup():
59 def test_user_setup():
52 # use a lambda to pass kwargs to the generator
60 # use a lambda to pass kwargs to the generator
53 user_setup = lambda a,k: iplib.user_setup(*a,**k)
61 user_setup = lambda a,k: iplib.user_setup(*a,**k)
54 kw = dict(mode='install', interactive=False)
62 kw = dict(mode='install', interactive=False)
55
63
56 # Call the user setup and verify that the directory exists
64 # Call the user setup and verify that the directory exists
57 yield user_setup, (ip.options.ipythondir,''), kw
65 yield user_setup, (ip.options.ipythondir,''), kw
58 yield os.path.isdir, ip.options.ipythondir
66 yield os.path.isdir, ip.options.ipythondir
59
67
60 # Now repeat the operation with a non-existent directory. Check both that
68 # Now repeat the operation with a non-existent directory. Check both that
61 # the call succeeds and that the directory is created.
69 # the call succeeds and that the directory is created.
62 tmpdir = tempfile.mktemp(prefix='ipython-test-')
70 tmpdir = tempfile.mktemp(prefix='ipython-test-')
63 try:
71 try:
64 yield user_setup, (tmpdir,''), kw
72 yield user_setup, (tmpdir,''), kw
65 yield os.path.isdir, tmpdir
73 yield os.path.isdir, tmpdir
66 finally:
74 finally:
67 # In this case, clean up the temp dir once done
75 # In this case, clean up the temp dir once done
68 shutil.rmtree(tmpdir)
76 shutil.rmtree(tmpdir)
General Comments 0
You need to be logged in to leave comments. Login now