##// 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 ptformatter.pprint = False
461 ptformatter.pprint = False
462 disp_formatter.active_types = ['text/plain']
462 disp_formatter.active_types = ['text/plain']
463
463
464 shell.magic('xmode Plain')
464 shell.run_line_magic("xmode", "Plain")
465 else:
465 else:
466 # turn off
466 # turn off
467 shell.separate_in = dstore.rc_separate_in
467 shell.separate_in = dstore.rc_separate_in
@@ -83,7 +83,7 class LoggingMagics(Magics):
83 log 'raw' input. Normally, IPython's logs contain the processed
83 log 'raw' input. Normally, IPython's logs contain the processed
84 input, so that user lines are logged in their final form, converted
84 input, so that user lines are logged in their final form, converted
85 into valid Python. For example, %Exit is logged as
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 exactly as typed, with no transformations applied.
87 exactly as typed, with no transformations applied.
88
88
89 -t
89 -t
@@ -5,22 +5,27 from traitlets.config.loader import Config
5
5
6
6
7 def setup_module():
7 def setup_module():
8 ip.magic('load_ext storemagic')
8 ip.run_line_magic("load_ext", "storemagic")
9
9
10
10 def test_store_restore():
11 def test_store_restore():
11 assert 'bar' not in ip.user_ns, "Error: some other test leaked `bar` in user_ns"
12 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 "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 (
14 assert 'foobaz' not in ip.user_ns, "Error: some other test leaked `foobaz` in user_ns"
15 "foobar" not in ip.user_ns
15 ip.user_ns['foo'] = 78
16 ), "Error: some other test leaked `foobar` in user_ns"
16 ip.magic('alias bar echo "hello"')
17 assert (
17 ip.user_ns['foobar'] = 79
18 "foobaz" not in ip.user_ns
18 ip.user_ns['foobaz'] = '80'
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 tmpd = tempfile.mkdtemp()
24 tmpd = tempfile.mkdtemp()
20 ip.magic('cd ' + tmpd)
25 ip.run_line_magic("cd", tmpd)
21 ip.magic('store foo')
26 ip.run_line_magic("store", "foo")
22 ip.magic('store bar')
27 ip.run_line_magic("store", "bar")
23 ip.magic('store foobar foobaz')
28 ip.run_line_magic("store", "foobar foobaz")
24
29
25 # Check storing
30 # Check storing
26 assert ip.db["autorestore/foo"] == 78
31 assert ip.db["autorestore/foo"] == 78
@@ -29,29 +34,29 def test_store_restore():
29 assert ip.db["autorestore/foobaz"] == "80"
34 assert ip.db["autorestore/foobaz"] == "80"
30
35
31 # Remove those items
36 # Remove those items
32 ip.user_ns.pop('foo', None)
37 ip.user_ns.pop("foo", None)
33 ip.user_ns.pop('foobar', None)
38 ip.user_ns.pop("foobar", None)
34 ip.user_ns.pop('foobaz', None)
39 ip.user_ns.pop("foobaz", None)
35 ip.alias_manager.undefine_alias('bar')
40 ip.alias_manager.undefine_alias("bar")
36 ip.magic('cd -')
41 ip.run_line_magic("cd", "-")
37 ip.user_ns['_dh'][:] = []
42 ip.user_ns["_dh"][:] = []
38
43
39 # Check restoring
44 # Check restoring
40 ip.magic("store -r foo bar foobar foobaz")
45 ip.run_line_magic("store", "-r foo bar foobar foobaz")
41 assert ip.user_ns["foo"] == 78
46 assert ip.user_ns["foo"] == 78
42 assert ip.alias_manager.is_alias("bar")
47 assert ip.alias_manager.is_alias("bar")
43 assert ip.user_ns["foobar"] == 79
48 assert ip.user_ns["foobar"] == 79
44 assert ip.user_ns["foobaz"] == "80"
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 assert any(Path(tmpd).samefile(p) for p in ip.user_ns["_dh"])
52 assert any(Path(tmpd).samefile(p) for p in ip.user_ns["_dh"])
48
53
49 os.rmdir(tmpd)
54 os.rmdir(tmpd)
50
55
51 def test_autorestore():
56 def test_autorestore():
52 ip.user_ns['foo'] = 95
57 ip.user_ns["foo"] = 95
53 ip.magic('store foo')
58 ip.run_line_magic("store", "foo")
54 del ip.user_ns['foo']
59 del ip.user_ns["foo"]
55 c = Config()
60 c = Config()
56 c.StoreMagics.autorestore = False
61 c.StoreMagics.autorestore = False
57 orig_config = ip.config
62 orig_config = ip.config
General Comments 0
You need to be logged in to leave comments. Login now