diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index 3e3eb2d3f83..f707bcccaae 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -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. diff --git a/IPython/core/tests/test_logger.py b/IPython/core/tests/test_logger.py index 10e462098be..003f603f838 100644 --- a/IPython/core/tests/test_logger.py +++ b/IPython/core/tests/test_logger.py @@ -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() diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index c757b9cf629..036f250d341 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -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" @@ -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: diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 23337b3007d..971f8e30dad 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -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)) @@ -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): diff --git a/IPython/core/tests/test_ultratb.py b/IPython/core/tests/test_ultratb.py index c2e72e4fa85..c8f52710bad 100644 --- a/IPython/core/tests/test_ultratb.py +++ b/IPython/core/tests/test_ultratb.py @@ -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(): @@ -237,7 +238,7 @@ 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: @@ -245,7 +246,7 @@ def test_changing_py_file(self): # 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