Show More
@@ -1,66 +1,65 b'' | |||||
1 | import tempfile, os |
|
1 | import tempfile, os | |
2 |
|
2 | |||
3 | from traitlets.config.loader import Config |
|
3 | from traitlets.config.loader import Config | |
4 | import nose.tools as nt |
|
|||
5 |
|
4 | |||
6 |
|
5 | |||
7 | def setup_module(): |
|
6 | def setup_module(): | |
8 | ip.magic('load_ext storemagic') |
|
7 | ip.magic('load_ext storemagic') | |
9 |
|
8 | |||
10 | def test_store_restore(): |
|
9 | def test_store_restore(): | |
11 | assert 'bar' not in ip.user_ns, "Error: some other test leaked `bar` in user_ns" |
|
10 | assert 'bar' not in ip.user_ns, "Error: some other test leaked `bar` in user_ns" | |
12 | assert 'foo' not in ip.user_ns, "Error: some other test leaked `foo` in user_ns" |
|
11 | assert 'foo' not in ip.user_ns, "Error: some other test leaked `foo` in user_ns" | |
13 | assert 'foobar' not in ip.user_ns, "Error: some other test leaked `foobar` in user_ns" |
|
12 | assert 'foobar' not in ip.user_ns, "Error: some other test leaked `foobar` in user_ns" | |
14 | assert 'foobaz' not in ip.user_ns, "Error: some other test leaked `foobaz` in user_ns" |
|
13 | assert 'foobaz' not in ip.user_ns, "Error: some other test leaked `foobaz` in user_ns" | |
15 | ip.user_ns['foo'] = 78 |
|
14 | ip.user_ns['foo'] = 78 | |
16 | ip.magic('alias bar echo "hello"') |
|
15 | ip.magic('alias bar echo "hello"') | |
17 | ip.user_ns['foobar'] = 79 |
|
16 | ip.user_ns['foobar'] = 79 | |
18 | ip.user_ns['foobaz'] = '80' |
|
17 | ip.user_ns['foobaz'] = '80' | |
19 | tmpd = tempfile.mkdtemp() |
|
18 | tmpd = tempfile.mkdtemp() | |
20 | ip.magic('cd ' + tmpd) |
|
19 | ip.magic('cd ' + tmpd) | |
21 | ip.magic('store foo') |
|
20 | ip.magic('store foo') | |
22 | ip.magic('store bar') |
|
21 | ip.magic('store bar') | |
23 | ip.magic('store foobar foobaz') |
|
22 | ip.magic('store foobar foobaz') | |
24 |
|
23 | |||
25 | # Check storing |
|
24 | # Check storing | |
26 |
|
|
25 | assert ip.db["autorestore/foo"] == 78 | |
27 |
|
|
26 | assert "bar" in ip.db["stored_aliases"] | |
28 |
|
|
27 | assert ip.db["autorestore/foobar"] == 79 | |
29 |
|
|
28 | assert ip.db["autorestore/foobaz"] == "80" | |
30 |
|
29 | |||
31 | # Remove those items |
|
30 | # Remove those items | |
32 | ip.user_ns.pop('foo', None) |
|
31 | ip.user_ns.pop('foo', None) | |
33 | ip.user_ns.pop('foobar', None) |
|
32 | ip.user_ns.pop('foobar', None) | |
34 | ip.user_ns.pop('foobaz', None) |
|
33 | ip.user_ns.pop('foobaz', None) | |
35 | ip.alias_manager.undefine_alias('bar') |
|
34 | ip.alias_manager.undefine_alias('bar') | |
36 | ip.magic('cd -') |
|
35 | ip.magic('cd -') | |
37 | ip.user_ns['_dh'][:] = [] |
|
36 | ip.user_ns['_dh'][:] = [] | |
38 |
|
37 | |||
39 | # Check restoring |
|
38 | # Check restoring | |
40 |
ip.magic( |
|
39 | ip.magic("store -r foo bar foobar foobaz") | |
41 |
|
|
40 | assert ip.user_ns["foo"] == 78 | |
42 |
assert ip.alias_manager.is_alias( |
|
41 | assert ip.alias_manager.is_alias("bar") | |
43 |
|
|
42 | assert ip.user_ns["foobar"] == 79 | |
44 |
|
|
43 | assert ip.user_ns["foobaz"] == "80" | |
45 |
|
44 | |||
46 |
ip.magic( |
|
45 | ip.magic("store -r") # restores _dh too | |
47 |
|
|
46 | assert os.path.realpath(tmpd) in ip.user_ns["_dh"] | |
48 |
|
47 | |||
49 | os.rmdir(tmpd) |
|
48 | os.rmdir(tmpd) | |
50 |
|
49 | |||
51 | def test_autorestore(): |
|
50 | def test_autorestore(): | |
52 | ip.user_ns['foo'] = 95 |
|
51 | ip.user_ns['foo'] = 95 | |
53 | ip.magic('store foo') |
|
52 | ip.magic('store foo') | |
54 | del ip.user_ns['foo'] |
|
53 | del ip.user_ns['foo'] | |
55 | c = Config() |
|
54 | c = Config() | |
56 | c.StoreMagics.autorestore = False |
|
55 | c.StoreMagics.autorestore = False | |
57 | orig_config = ip.config |
|
56 | orig_config = ip.config | |
58 | try: |
|
57 | try: | |
59 | ip.config = c |
|
58 | ip.config = c | |
60 |
ip.extension_manager.reload_extension( |
|
59 | ip.extension_manager.reload_extension("storemagic") | |
61 |
|
|
60 | assert "foo" not in ip.user_ns | |
62 | c.StoreMagics.autorestore = True |
|
61 | c.StoreMagics.autorestore = True | |
63 |
ip.extension_manager.reload_extension( |
|
62 | ip.extension_manager.reload_extension("storemagic") | |
64 |
|
|
63 | assert ip.user_ns["foo"] == 95 | |
65 | finally: |
|
64 | finally: | |
66 | ip.config = orig_config |
|
65 | ip.config = orig_config |
General Comments 0
You need to be logged in to leave comments.
Login now