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