##// END OF EJS Templates
Add test for StoreMagics.autorestore option
Thomas Kluyver -
Show More
@@ -1,32 +1,50 b''
1 import tempfile, os
1 import tempfile, os
2
2
3 from IPython.config.loader import Config
3 import nose.tools as nt
4 import nose.tools as nt
4
5
5 ip = get_ipython()
6 ip = get_ipython()
6 ip.magic('load_ext storemagic')
7 ip.magic('load_ext storemagic')
7
8
8 def test_store_restore():
9 def test_store_restore():
9 ip.user_ns['foo'] = 78
10 ip.user_ns['foo'] = 78
10 ip.magic('alias bar echo "hello"')
11 ip.magic('alias bar echo "hello"')
11 tmpd = tempfile.mkdtemp()
12 tmpd = tempfile.mkdtemp()
12 ip.magic('cd ' + tmpd)
13 ip.magic('cd ' + tmpd)
13 ip.magic('store foo')
14 ip.magic('store foo')
14 ip.magic('store bar')
15 ip.magic('store bar')
15
16
16 # Check storing
17 # Check storing
17 nt.assert_equal(ip.db['autorestore/foo'], 78)
18 nt.assert_equal(ip.db['autorestore/foo'], 78)
18 nt.assert_in('bar', ip.db['stored_aliases'])
19 nt.assert_in('bar', ip.db['stored_aliases'])
19
20
20 # Remove those items
21 # Remove those items
21 ip.user_ns.pop('foo', None)
22 ip.user_ns.pop('foo', None)
22 ip.alias_manager.undefine_alias('bar')
23 ip.alias_manager.undefine_alias('bar')
23 ip.magic('cd -')
24 ip.magic('cd -')
24 ip.user_ns['_dh'][:] = []
25 ip.user_ns['_dh'][:] = []
25
26
26 # Check restoring
27 # Check restoring
27 ip.magic('store -r')
28 ip.magic('store -r')
28 nt.assert_equal(ip.user_ns['foo'], 78)
29 nt.assert_equal(ip.user_ns['foo'], 78)
29 nt.assert_in('bar', ip.alias_manager.alias_table)
30 nt.assert_in('bar', ip.alias_manager.alias_table)
30 nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
31 nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
31
32
32 os.rmdir(tmpd)
33 os.rmdir(tmpd)
34
35 def test_autorestore():
36 ip.user_ns['foo'] = 95
37 ip.magic('store foo')
38 del ip.user_ns['foo']
39 c = Config()
40 c.StoreMagics.autorestore = False
41 orig_config = ip.config
42 try:
43 ip.config = c
44 ip.extension_manager.reload_extension('storemagic')
45 nt.assert_not_in('foo', ip.user_ns)
46 c.StoreMagics.autorestore = True
47 ip.extension_manager.reload_extension('storemagic')
48 nt.assert_equal(ip.user_ns['foo'], 95)
49 finally:
50 ip.config = orig_config
General Comments 0
You need to be logged in to leave comments. Login now