Skip to content

Commit f42bfc8

Browse files
committed
do not use .magic(...) that has been deprecated for a decade
1 parent a963358 commit f42bfc8

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

IPython/core/magics/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def doctest_mode(self, parameter_s=''):
472472
ptformatter.pprint = dstore.rc_pprint
473473
disp_formatter.active_types = dstore.rc_active_types
474474

475-
shell.magic('xmode ' + dstore.xmode)
475+
shell.run_line_magic("xmode", dstore.xmode)
476476

477477
# mode here is the state before we switch; switch_doctest_mode takes
478478
# the mode we're switching to.

IPython/core/tests/test_logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_logstart_unicode():
2121
logfname = os.path.join(tdir, "test_unicode.log")
2222
_ip.run_cell("'abc€'")
2323
try:
24-
_ip.magic("logstart -to %s" % logfname)
24+
_ip.run_line_magic("logstart", "-to %s" % logfname)
2525
_ip.run_cell("'abc€'")
2626
finally:
2727
_ip.logger.logstop()

IPython/core/tests/test_magic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def lmagic(line):
827827
@dec.skipif(execution.profile is None)
828828
def test_prun_quotes():
829829
"Test that prun does not clobber string escapes (GH #1302)"
830-
_ip.magic(r"prun -q x = '\t'")
830+
_ip.run_line_magic("prun", r"-q x = '\t'")
831831
assert _ip.user_ns["x"] == "\t"
832832

833833

@@ -838,7 +838,7 @@ def test_extension():
838838
print(' ', p)
839839
print('CWD', os.getcwd())
840840

841-
pytest.raises(ImportError, _ip.magic, "load_ext daft_extension")
841+
pytest.raises(ImportError, _ip.run_line_magic, "load_ext", "daft_extension")
842842
daft_path = os.path.join(os.path.dirname(__file__), "daft_extension")
843843
sys.path.insert(0, daft_path)
844844
try:

IPython/core/tests/test_run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ def test_aggressive_namespace_cleanup(self):
271271
"ip = get_ipython()\n"
272272
"for i in range(5):\n"
273273
" try:\n"
274-
" ip.magic(%r)\n"
274+
" ip.run_line_magic(%r, %r)\n"
275275
" except NameError as e:\n"
276276
" print(i)\n"
277-
" break\n" % ("run " + empty.fname)
277+
" break\n" % ("run", empty.fname)
278278
)
279279
self.mktmp(src)
280280
_ip.run_line_magic("run", str(self.fname))
@@ -339,7 +339,7 @@ def test_unicode(self):
339339
"""Check that files in odd encodings are accepted."""
340340
mydir = os.path.dirname(__file__)
341341
na = os.path.join(mydir, "nonascii.py")
342-
_ip.magic('run "%s"' % na)
342+
_ip.run_line_magic("run", na)
343343
assert _ip.user_ns["u"] == "Ўт№Ф"
344344

345345
def test_run_py_file_attribute(self):

IPython/core/tests/test_ultratb.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def test_indentationerror_shows_line(self):
175175

176176
with tt.AssertPrints("IndentationError"):
177177
with tt.AssertPrints("zoom()", suppress=False):
178-
ip.magic('run %s' % fname)
178+
ip.run_line_magic("run", fname)
179+
179180

180181
@skip_without("pandas")
181182
def test_dynamic_code():
@@ -237,15 +238,15 @@ def test_changing_py_file(self):
237238
f.write(se_file_1)
238239

239240
with tt.AssertPrints(["7/", "SyntaxError"]):
240-
ip.magic("run " + fname)
241+
ip.run_line_magic("run", fname)
241242

242243
# Modify the file
243244
with open(fname, "w", encoding="utf-8") as f:
244245
f.write(se_file_2)
245246

246247
# The SyntaxError should point to the correct line
247248
with tt.AssertPrints(["7/", "SyntaxError"]):
248-
ip.magic("run " + fname)
249+
ip.run_line_magic("run", fname)
249250

250251
def test_non_syntaxerror(self):
251252
# SyntaxTB may be called with an error other than a SyntaxError

0 commit comments

Comments
 (0)