Skip to content

Commit

Permalink
do not use .magic(...) that has been deprecated for a decade (ipython…
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored Nov 1, 2024
2 parents 5d95565 + f42bfc8 commit ac9ed9c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion IPython/core/magics/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def doctest_mode(self, parameter_s=''):
ptformatter.pprint = dstore.rc_pprint
disp_formatter.active_types = dstore.rc_active_types

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

# mode here is the state before we switch; switch_doctest_mode takes
# the mode we're switching to.
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_logstart_unicode():
logfname = os.path.join(tdir, "test_unicode.log")
_ip.run_cell("'abc€'")
try:
_ip.magic("logstart -to %s" % logfname)
_ip.run_line_magic("logstart", "-to %s" % logfname)
_ip.run_cell("'abc€'")
finally:
_ip.logger.logstop()
4 changes: 2 additions & 2 deletions IPython/core/tests/test_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def lmagic(line):
@dec.skipif(execution.profile is None)
def test_prun_quotes():
"Test that prun does not clobber string escapes (GH #1302)"
_ip.magic(r"prun -q x = '\t'")
_ip.run_line_magic("prun", r"-q x = '\t'")
assert _ip.user_ns["x"] == "\t"


Expand All @@ -838,7 +838,7 @@ def test_extension():
print(' ', p)
print('CWD', os.getcwd())

pytest.raises(ImportError, _ip.magic, "load_ext daft_extension")
pytest.raises(ImportError, _ip.run_line_magic, "load_ext", "daft_extension")
daft_path = os.path.join(os.path.dirname(__file__), "daft_extension")
sys.path.insert(0, daft_path)
try:
Expand Down
6 changes: 3 additions & 3 deletions IPython/core/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ def test_aggressive_namespace_cleanup(self):
"ip = get_ipython()\n"
"for i in range(5):\n"
" try:\n"
" ip.magic(%r)\n"
" ip.run_line_magic(%r, %r)\n"
" except NameError as e:\n"
" print(i)\n"
" break\n" % ("run " + empty.fname)
" break\n" % ("run", empty.fname)
)
self.mktmp(src)
_ip.run_line_magic("run", str(self.fname))
Expand Down Expand Up @@ -339,7 +339,7 @@ def test_unicode(self):
"""Check that files in odd encodings are accepted."""
mydir = os.path.dirname(__file__)
na = os.path.join(mydir, "nonascii.py")
_ip.magic('run "%s"' % na)
_ip.run_line_magic("run", na)
assert _ip.user_ns["u"] == "Ўт№Ф"

def test_run_py_file_attribute(self):
Expand Down
7 changes: 4 additions & 3 deletions IPython/core/tests/test_ultratb.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def test_indentationerror_shows_line(self):

with tt.AssertPrints("IndentationError"):
with tt.AssertPrints("zoom()", suppress=False):
ip.magic('run %s' % fname)
ip.run_line_magic("run", fname)


@skip_without("pandas")
def test_dynamic_code():
Expand Down Expand Up @@ -237,15 +238,15 @@ def test_changing_py_file(self):
f.write(se_file_1)

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

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

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

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

0 comments on commit ac9ed9c

Please sign in to comment.