Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44d64dc

Browse files
committed
Update some deprecated ip.magic() to run_line-magic in tests
1 parent 6d40fd8 commit 44d64dc

3 files changed

Lines changed: 45 additions & 39 deletions

File tree

IPython/core/tests/test_alias.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def test_alias_args_error():
4343

4444
def test_alias_args_commented():
4545
"""Check that alias correctly ignores 'commented out' args"""
46-
_ip.magic('alias commetarg echo this is %%s a commented out arg')
47-
46+
_ip.run_line_magic("alias", "commentarg echo this is %%s a commented out arg")
47+
4848
with capture_output() as cap:
49-
_ip.run_cell('commetarg')
50-
49+
_ip.run_cell("commentarg")
50+
5151
# strip() is for pytest compat; testing via iptest patch IPython shell
5252
# in testing.globalipapp and replace the system call which messed up the
5353
# \r\n

IPython/core/tests/test_handlers.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,42 @@ def test_handlers():
5656
ip.user_ns['autocallable'] = autocallable
5757

5858
# auto
59-
ip.magic('autocall 0')
59+
ip.run_line_magic("autocall", "0")
6060
# Only explicit escapes or instances of IPyAutocallable should get
6161
# expanded
62-
run([
63-
('len "abc"', 'len "abc"'),
64-
('autocallable', 'autocallable()'),
65-
# Don't add extra brackets (gh-1117)
66-
('autocallable()', 'autocallable()'),
67-
])
68-
ip.magic('autocall 1')
69-
run([
70-
('len "abc"', 'len("abc")'),
71-
('len "abc";', 'len("abc");'), # ; is special -- moves out of parens
72-
# Autocall is turned off if first arg is [] and the object
73-
# is both callable and indexable. Like so:
74-
('len [1,2]', 'len([1,2])'), # len doesn't support __getitem__...
75-
('call_idx [1]', 'call_idx [1]'), # call_idx *does*..
76-
('call_idx 1', 'call_idx(1)'),
77-
('len', 'len'), # only at 2 does it auto-call on single args
78-
])
79-
ip.magic('autocall 2')
80-
run([
81-
('len "abc"', 'len("abc")'),
82-
('len "abc";', 'len("abc");'),
83-
('len [1,2]', 'len([1,2])'),
84-
('call_idx [1]', 'call_idx [1]'),
85-
('call_idx 1', 'call_idx(1)'),
86-
# This is what's different:
87-
('len', 'len()'), # only at 2 does it auto-call on single args
88-
])
89-
ip.magic('autocall 1')
62+
run(
63+
[
64+
('len "abc"', 'len "abc"'),
65+
("autocallable", "autocallable()"),
66+
# Don't add extra brackets (gh-1117)
67+
("autocallable()", "autocallable()"),
68+
]
69+
)
70+
ip.run_line_magic("autocall", "1")
71+
run(
72+
[
73+
('len "abc"', 'len("abc")'),
74+
('len "abc";', 'len("abc");'), # ; is special -- moves out of parens
75+
# Autocall is turned off if first arg is [] and the object
76+
# is both callable and indexable. Like so:
77+
("len [1,2]", "len([1,2])"), # len doesn't support __getitem__...
78+
("call_idx [1]", "call_idx [1]"), # call_idx *does*..
79+
("call_idx 1", "call_idx(1)"),
80+
("len", "len"), # only at 2 does it auto-call on single args
81+
]
82+
)
83+
ip.run_line_magic("autocall", "2")
84+
run(
85+
[
86+
('len "abc"', 'len("abc")'),
87+
('len "abc";', 'len("abc");'),
88+
("len [1,2]", "len([1,2])"),
89+
("call_idx [1]", "call_idx [1]"),
90+
("call_idx 1", "call_idx(1)"),
91+
# This is what's different:
92+
("len", "len()"), # only at 2 does it auto-call on single args
93+
]
94+
)
95+
ip.run_line_magic("autocall", "1")
9096

9197
assert failures == []

IPython/core/tests/test_history.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ def test_history():
5252

5353
# Check whether specifying a range beyond the end of the current
5454
# session results in an error (gh-804)
55-
ip.magic('%hist 2-500')
55+
ip.run_line_magic("hist", "2-500")
5656

5757
# Check that we can write non-ascii characters to a file
58-
ip.magic("%%hist -f %s" % (tmp_path / "test1"))
59-
ip.magic("%%hist -pf %s" % (tmp_path / "test2"))
60-
ip.magic("%%hist -nf %s" % (tmp_path / "test3"))
61-
ip.magic("%%save %s 1-10" % (tmp_path / "test4"))
58+
ip.run_line_magic("hist", "-f %s" % (tmp_path / "test1"))
59+
ip.run_line_magic("hist", "-pf %s" % (tmp_path / "test2"))
60+
ip.run_line_magic("hist", "-nf %s" % (tmp_path / "test3"))
61+
ip.run_line_magic("save", "%s 1-10" % (tmp_path / "test4"))
6262

6363
# New session
6464
ip.history_manager.reset()
@@ -124,7 +124,7 @@ def test_history():
124124

125125
# Cross testing: check that magic %save can get previous session.
126126
testfilename = (tmp_path / "test.py").resolve()
127-
ip.magic("save " + str(testfilename) + " ~1/1-3")
127+
ip.run_line_magic("save", str(testfilename) + " ~1/1-3")
128128
with io.open(testfilename, encoding="utf-8") as testfile:
129129
assert testfile.read() == "# coding: utf-8\n" + "\n".join(hist) + "\n"
130130

0 commit comments

Comments
 (0)