##// END OF EJS Templates
Use non-deprecated run_line_magic function
M Bussonnier -
Show More
@@ -461,7 +461,7 Currently the magic system has the following functions:""",
461 461 ptformatter.pprint = False
462 462 disp_formatter.active_types = ['text/plain']
463 463
464 shell.magic('xmode Plain')
464 shell.run_line_magic("xmode", "Plain")
465 465 else:
466 466 # turn off
467 467 shell.separate_in = dstore.rc_separate_in
@@ -83,7 +83,7 class LoggingMagics(Magics):
83 83 log 'raw' input. Normally, IPython's logs contain the processed
84 84 input, so that user lines are logged in their final form, converted
85 85 into valid Python. For example, %Exit is logged as
86 _ip.magic("Exit"). If the -r flag is given, all input is logged
86 _ip.run_line_magic("Exit"). If the -r flag is given, all input is logged
87 87 exactly as typed, with no transformations applied.
88 88
89 89 -t
@@ -5,22 +5,27 from traitlets.config.loader import Config
5 5
6 6
7 7 def setup_module():
8 ip.magic('load_ext storemagic')
8 ip.run_line_magic("load_ext", "storemagic")
9
9 10
10 11 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'
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"
19 24 tmpd = tempfile.mkdtemp()
20 ip.magic('cd ' + tmpd)
21 ip.magic('store foo')
22 ip.magic('store bar')
23 ip.magic('store foobar foobaz')
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")
24 29
25 30 # Check storing
26 31 assert ip.db["autorestore/foo"] == 78
@@ -29,29 +34,29 def test_store_restore():
29 34 assert ip.db["autorestore/foobaz"] == "80"
30 35
31 36 # 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'][:] = []
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"][:] = []
38 43
39 44 # Check restoring
40 ip.magic("store -r foo bar foobar foobaz")
45 ip.run_line_magic("store", "-r foo bar foobar foobaz")
41 46 assert ip.user_ns["foo"] == 78
42 47 assert ip.alias_manager.is_alias("bar")
43 48 assert ip.user_ns["foobar"] == 79
44 49 assert ip.user_ns["foobaz"] == "80"
45 50
46 ip.magic("store -r") # restores _dh too
51 ip.run_line_magic("store", "-r") # restores _dh too
47 52 assert any(Path(tmpd).samefile(p) for p in ip.user_ns["_dh"])
48 53
49 54 os.rmdir(tmpd)
50 55
51 56 def test_autorestore():
52 ip.user_ns['foo'] = 95
53 ip.magic('store foo')
54 del ip.user_ns['foo']
57 ip.user_ns["foo"] = 95
58 ip.run_line_magic("store", "foo")
59 del ip.user_ns["foo"]
55 60 c = Config()
56 61 c.StoreMagics.autorestore = False
57 62 orig_config = ip.config
General Comments 0
You need to be logged in to leave comments. Login now