()
| 8 | ip.magic('load_ext storemagic') |
| 9 | |
| 10 | def test_store_restore(): |
| 11 | 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" |
| 13 | 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" |
| 15 | ip.user_ns['foo'] = 78 |
| 16 | ip.magic('alias bar echo "hello"') |
| 17 | ip.user_ns['foobar'] = 79 |
| 18 | ip.user_ns['foobaz'] = '80' |
| 19 | tmpd = tempfile.mkdtemp() |
| 20 | ip.magic('cd ' + tmpd) |
| 21 | ip.magic('store foo') |
| 22 | ip.magic('store bar') |
| 23 | ip.magic('store foobar foobaz') |
| 24 | |
| 25 | # Check storing |
| 26 | nt.assert_equal(ip.db['autorestore/foo'], 78) |
| 27 | nt.assert_in('bar', ip.db['stored_aliases']) |
| 28 | nt.assert_equal(ip.db['autorestore/foobar'], 79) |
| 29 | nt.assert_equal(ip.db['autorestore/foobaz'], '80') |
| 30 | |
| 31 | # Remove those items |
| 32 | ip.user_ns.pop('foo', None) |
| 33 | ip.user_ns.pop('foobar', None) |
| 34 | ip.user_ns.pop('foobaz', None) |
| 35 | ip.alias_manager.undefine_alias('bar') |
| 36 | ip.magic('cd -') |
| 37 | ip.user_ns['_dh'][:] = [] |
| 38 | |
| 39 | # Check restoring |
| 40 | ip.magic('store -r foo bar foobar foobaz') |
| 41 | nt.assert_equal(ip.user_ns['foo'], 78) |
| 42 | assert ip.alias_manager.is_alias('bar') |
| 43 | nt.assert_equal(ip.user_ns['foobar'], 79) |
| 44 | nt.assert_equal(ip.user_ns['foobaz'], '80') |
| 45 | |
| 46 | ip.magic('store -r') # restores _dh too |
| 47 | nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh']) |
| 48 | |
| 49 | os.rmdir(tmpd) |
| 50 | |
| 51 | def test_autorestore(): |
| 52 | ip.user_ns['foo'] = 95 |
nothing calls this directly
no test coverage detected