MCPcopy Index your code
hub / github.com/ipython/ipython / test_store_restore

Function test_store_restore

tests/test_storemagic.py:11–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9
10
11def test_store_restore():
12 assert "bar" not in ip.user_ns, "Error: some other test leaked `bar` in user_ns"
13 assert "foo" not in ip.user_ns, "Error: some other test leaked `foo` in user_ns"
14 assert (
15 "foobar" not in ip.user_ns
16 ), "Error: some other test leaked `foobar` in user_ns"
17 assert (
18 "foobaz" not in ip.user_ns
19 ), "Error: some other test leaked `foobaz` in user_ns"
20 ip.user_ns["foo"] = 78
21 ip.run_line_magic("alias", 'bar echo "hello"')
22 ip.user_ns["foobar"] = 79
23 ip.user_ns["foobaz"] = "80"
24 tmpd = tempfile.mkdtemp()
25 ip.run_line_magic("cd", tmpd)
26 ip.run_line_magic("store", "foo")
27 ip.run_line_magic("store", "bar")
28 ip.run_line_magic("store", "foobar foobaz")
29
30 # Check storing
31 assert ip.db["autorestore/foo"] == 78
32 assert "bar" in ip.db["stored_aliases"]
33 assert ip.db["autorestore/foobar"] == 79
34 assert ip.db["autorestore/foobaz"] == "80"
35
36 # Remove those items
37 ip.user_ns.pop("foo", None)
38 ip.user_ns.pop("foobar", None)
39 ip.user_ns.pop("foobaz", None)
40 ip.alias_manager.undefine_alias("bar")
41 ip.run_line_magic("cd", "-")
42 ip.user_ns["_dh"][:] = []
43
44 # Check restoring
45 ip.run_line_magic("store", "-r foo bar foobar foobaz")
46 assert ip.user_ns["foo"] == 78
47 assert ip.alias_manager.is_alias("bar")
48 assert ip.user_ns["foobar"] == 79
49 assert ip.user_ns["foobaz"] == "80"
50
51 ip.run_line_magic("store", "-r") # restores _dh too
52 assert any(Path(tmpd).samefile(p) for p in ip.user_ns["_dh"])
53
54 os.rmdir(tmpd)
55
56
57def test_autorestore():

Callers

nothing calls this directly

Calls 4

run_line_magicMethod · 0.80
popMethod · 0.80
undefine_aliasMethod · 0.80
is_aliasMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…