##// END OF EJS Templates
Add test for StoreMagics.autorestore option
Thomas Kluyver -
Show More
@@ -1,32 +1,50
1 1 import tempfile, os
2 2
3 from IPython.config.loader import Config
3 4 import nose.tools as nt
4 5
5 6 ip = get_ipython()
6 7 ip.magic('load_ext storemagic')
7 8
8 9 def test_store_restore():
9 10 ip.user_ns['foo'] = 78
10 11 ip.magic('alias bar echo "hello"')
11 12 tmpd = tempfile.mkdtemp()
12 13 ip.magic('cd ' + tmpd)
13 14 ip.magic('store foo')
14 15 ip.magic('store bar')
15 16
16 17 # Check storing
17 18 nt.assert_equal(ip.db['autorestore/foo'], 78)
18 19 nt.assert_in('bar', ip.db['stored_aliases'])
19 20
20 21 # Remove those items
21 22 ip.user_ns.pop('foo', None)
22 23 ip.alias_manager.undefine_alias('bar')
23 24 ip.magic('cd -')
24 25 ip.user_ns['_dh'][:] = []
25 26
26 27 # Check restoring
27 28 ip.magic('store -r')
28 29 nt.assert_equal(ip.user_ns['foo'], 78)
29 30 nt.assert_in('bar', ip.alias_manager.alias_table)
30 31 nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
31 32
32 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