diff --git a/IPython/core/tests/test_alias.py b/IPython/core/tests/test_alias.py index a84b009..32d2e2f 100644 --- a/IPython/core/tests/test_alias.py +++ b/IPython/core/tests/test_alias.py @@ -43,11 +43,11 @@ def test_alias_args_error(): def test_alias_args_commented(): """Check that alias correctly ignores 'commented out' args""" - _ip.magic('alias commetarg echo this is %%s a commented out arg') - + _ip.run_line_magic("alias", "commentarg echo this is %%s a commented out arg") + with capture_output() as cap: - _ip.run_cell('commetarg') - + _ip.run_cell("commentarg") + # strip() is for pytest compat; testing via iptest patch IPython shell # in testing.globalipapp and replace the system call which messed up the # \r\n diff --git a/IPython/core/tests/test_handlers.py b/IPython/core/tests/test_handlers.py index e151e70..604dade 100644 --- a/IPython/core/tests/test_handlers.py +++ b/IPython/core/tests/test_handlers.py @@ -56,36 +56,42 @@ def test_handlers(): ip.user_ns['autocallable'] = autocallable # auto - ip.magic('autocall 0') + ip.run_line_magic("autocall", "0") # Only explicit escapes or instances of IPyAutocallable should get # expanded - run([ - ('len "abc"', 'len "abc"'), - ('autocallable', 'autocallable()'), - # Don't add extra brackets (gh-1117) - ('autocallable()', 'autocallable()'), - ]) - ip.magic('autocall 1') - run([ - ('len "abc"', 'len("abc")'), - ('len "abc";', 'len("abc");'), # ; is special -- moves out of parens - # Autocall is turned off if first arg is [] and the object - # is both callable and indexable. Like so: - ('len [1,2]', 'len([1,2])'), # len doesn't support __getitem__... - ('call_idx [1]', 'call_idx [1]'), # call_idx *does*.. - ('call_idx 1', 'call_idx(1)'), - ('len', 'len'), # only at 2 does it auto-call on single args - ]) - ip.magic('autocall 2') - run([ - ('len "abc"', 'len("abc")'), - ('len "abc";', 'len("abc");'), - ('len [1,2]', 'len([1,2])'), - ('call_idx [1]', 'call_idx [1]'), - ('call_idx 1', 'call_idx(1)'), - # This is what's different: - ('len', 'len()'), # only at 2 does it auto-call on single args - ]) - ip.magic('autocall 1') + run( + [ + ('len "abc"', 'len "abc"'), + ("autocallable", "autocallable()"), + # Don't add extra brackets (gh-1117) + ("autocallable()", "autocallable()"), + ] + ) + ip.run_line_magic("autocall", "1") + run( + [ + ('len "abc"', 'len("abc")'), + ('len "abc";', 'len("abc");'), # ; is special -- moves out of parens + # Autocall is turned off if first arg is [] and the object + # is both callable and indexable. Like so: + ("len [1,2]", "len([1,2])"), # len doesn't support __getitem__... + ("call_idx [1]", "call_idx [1]"), # call_idx *does*.. + ("call_idx 1", "call_idx(1)"), + ("len", "len"), # only at 2 does it auto-call on single args + ] + ) + ip.run_line_magic("autocall", "2") + run( + [ + ('len "abc"', 'len("abc")'), + ('len "abc";', 'len("abc");'), + ("len [1,2]", "len([1,2])"), + ("call_idx [1]", "call_idx [1]"), + ("call_idx 1", "call_idx(1)"), + # This is what's different: + ("len", "len()"), # only at 2 does it auto-call on single args + ] + ) + ip.run_line_magic("autocall", "1") assert failures == [] diff --git a/IPython/core/tests/test_history.py b/IPython/core/tests/test_history.py index 388ebc6..73d50c8 100644 --- a/IPython/core/tests/test_history.py +++ b/IPython/core/tests/test_history.py @@ -52,13 +52,13 @@ def test_history(): # Check whether specifying a range beyond the end of the current # session results in an error (gh-804) - ip.magic('%hist 2-500') + ip.run_line_magic("hist", "2-500") # Check that we can write non-ascii characters to a file - ip.magic("%%hist -f %s" % (tmp_path / "test1")) - ip.magic("%%hist -pf %s" % (tmp_path / "test2")) - ip.magic("%%hist -nf %s" % (tmp_path / "test3")) - ip.magic("%%save %s 1-10" % (tmp_path / "test4")) + ip.run_line_magic("hist", "-f %s" % (tmp_path / "test1")) + ip.run_line_magic("hist", "-pf %s" % (tmp_path / "test2")) + ip.run_line_magic("hist", "-nf %s" % (tmp_path / "test3")) + ip.run_line_magic("save", "%s 1-10" % (tmp_path / "test4")) # New session ip.history_manager.reset() @@ -124,7 +124,7 @@ def test_history(): # Cross testing: check that magic %save can get previous session. testfilename = (tmp_path / "test.py").resolve() - ip.magic("save " + str(testfilename) + " ~1/1-3") + ip.run_line_magic("save", str(testfilename) + " ~1/1-3") with io.open(testfilename, encoding="utf-8") as testfile: assert testfile.read() == "# coding: utf-8\n" + "\n".join(hist) + "\n"