Skip to content

Commit a7baa22

Browse files
authored
Use non-deprecated run_line_magic function (ipython#14574)
2 parents 39c7d0e + eca010b commit a7baa22

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

IPython/core/magics/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def doctest_mode(self, parameter_s=''):
461461
ptformatter.pprint = False
462462
disp_formatter.active_types = ['text/plain']
463463

464-
shell.magic('xmode Plain')
464+
shell.run_line_magic("xmode", "Plain")
465465
else:
466466
# turn off
467467
shell.separate_in = dstore.rc_separate_in

IPython/core/magics/logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ def logstart(self, parameter_s=''):
8383
log 'raw' input. Normally, IPython's logs contain the processed
8484
input, so that user lines are logged in their final form, converted
8585
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
8787
exactly as typed, with no transformations applied.
8888
8989
-t
9090
put timestamps before each input line logged (these are put in
9191
comments).
9292
93-
-q
93+
-q
9494
suppress output of logstate message when logging is invoked
9595
"""
9696

IPython/extensions/tests/test_storemagic.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55

66

77
def setup_module():
8-
ip.magic('load_ext storemagic')
8+
ip.run_line_magic("load_ext", "storemagic")
9+
910

1011
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"
1924
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")
2429

2530
# Check storing
2631
assert ip.db["autorestore/foo"] == 78
@@ -29,29 +34,29 @@ def test_store_restore():
2934
assert ip.db["autorestore/foobaz"] == "80"
3035

3136
# 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"][:] = []
3843

3944
# Check restoring
40-
ip.magic("store -r foo bar foobar foobaz")
45+
ip.run_line_magic("store", "-r foo bar foobar foobaz")
4146
assert ip.user_ns["foo"] == 78
4247
assert ip.alias_manager.is_alias("bar")
4348
assert ip.user_ns["foobar"] == 79
4449
assert ip.user_ns["foobaz"] == "80"
4550

46-
ip.magic("store -r") # restores _dh too
51+
ip.run_line_magic("store", "-r") # restores _dh too
4752
assert any(Path(tmpd).samefile(p) for p in ip.user_ns["_dh"])
4853

4954
os.rmdir(tmpd)
5055

5156
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"]
5560
c = Config()
5661
c.StoreMagics.autorestore = False
5762
orig_config = ip.config

0 commit comments

Comments
 (0)