##// END OF EJS Templates
Update some deprecated ip.magic() to run_line-magic in tests
Matthias Bussonnier -
Show More
@@ -43,11 +43,11 b' def test_alias_args_error():'
43
43
44 def test_alias_args_commented():
44 def test_alias_args_commented():
45 """Check that alias correctly ignores 'commented out' args"""
45 """Check that alias correctly ignores 'commented out' args"""
46 _ip.magic('alias commetarg echo this is %%s a commented out arg')
46 _ip.run_line_magic("alias", "commentarg echo this is %%s a commented out arg")
47
47
48 with capture_output() as cap:
48 with capture_output() as cap:
49 _ip.run_cell('commetarg')
49 _ip.run_cell("commentarg")
50
50
51 # strip() is for pytest compat; testing via iptest patch IPython shell
51 # strip() is for pytest compat; testing via iptest patch IPython shell
52 # in testing.globalipapp and replace the system call which messed up the
52 # in testing.globalipapp and replace the system call which messed up the
53 # \r\n
53 # \r\n
@@ -56,36 +56,42 b' def test_handlers():'
56 ip.user_ns['autocallable'] = autocallable
56 ip.user_ns['autocallable'] = autocallable
57
57
58 # auto
58 # auto
59 ip.magic('autocall 0')
59 ip.run_line_magic("autocall", "0")
60 # Only explicit escapes or instances of IPyAutocallable should get
60 # Only explicit escapes or instances of IPyAutocallable should get
61 # expanded
61 # expanded
62 run([
62 run(
63 ('len "abc"', 'len "abc"'),
63 [
64 ('autocallable', 'autocallable()'),
64 ('len "abc"', 'len "abc"'),
65 # Don't add extra brackets (gh-1117)
65 ("autocallable", "autocallable()"),
66 ('autocallable()', 'autocallable()'),
66 # Don't add extra brackets (gh-1117)
67 ])
67 ("autocallable()", "autocallable()"),
68 ip.magic('autocall 1')
68 ]
69 run([
69 )
70 ('len "abc"', 'len("abc")'),
70 ip.run_line_magic("autocall", "1")
71 ('len "abc";', 'len("abc");'), # ; is special -- moves out of parens
71 run(
72 # Autocall is turned off if first arg is [] and the object
72 [
73 # is both callable and indexable. Like so:
73 ('len "abc"', 'len("abc")'),
74 ('len [1,2]', 'len([1,2])'), # len doesn't support __getitem__...
74 ('len "abc";', 'len("abc");'), # ; is special -- moves out of parens
75 ('call_idx [1]', 'call_idx [1]'), # call_idx *does*..
75 # Autocall is turned off if first arg is [] and the object
76 ('call_idx 1', 'call_idx(1)'),
76 # is both callable and indexable. Like so:
77 ('len', 'len'), # only at 2 does it auto-call on single args
77 ("len [1,2]", "len([1,2])"), # len doesn't support __getitem__...
78 ])
78 ("call_idx [1]", "call_idx [1]"), # call_idx *does*..
79 ip.magic('autocall 2')
79 ("call_idx 1", "call_idx(1)"),
80 run([
80 ("len", "len"), # only at 2 does it auto-call on single args
81 ('len "abc"', 'len("abc")'),
81 ]
82 ('len "abc";', 'len("abc");'),
82 )
83 ('len [1,2]', 'len([1,2])'),
83 ip.run_line_magic("autocall", "2")
84 ('call_idx [1]', 'call_idx [1]'),
84 run(
85 ('call_idx 1', 'call_idx(1)'),
85 [
86 # This is what's different:
86 ('len "abc"', 'len("abc")'),
87 ('len', 'len()'), # only at 2 does it auto-call on single args
87 ('len "abc";', 'len("abc");'),
88 ])
88 ("len [1,2]", "len([1,2])"),
89 ip.magic('autocall 1')
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")
90
96
91 assert failures == []
97 assert failures == []
@@ -52,13 +52,13 b' def test_history():'
52
52
53 # Check whether specifying a range beyond the end of the current
53 # Check whether specifying a range beyond the end of the current
54 # session results in an error (gh-804)
54 # session results in an error (gh-804)
55 ip.magic('%hist 2-500')
55 ip.run_line_magic("hist", "2-500")
56
56
57 # Check that we can write non-ascii characters to a file
57 # Check that we can write non-ascii characters to a file
58 ip.magic("%%hist -f %s" % (tmp_path / "test1"))
58 ip.run_line_magic("hist", "-f %s" % (tmp_path / "test1"))
59 ip.magic("%%hist -pf %s" % (tmp_path / "test2"))
59 ip.run_line_magic("hist", "-pf %s" % (tmp_path / "test2"))
60 ip.magic("%%hist -nf %s" % (tmp_path / "test3"))
60 ip.run_line_magic("hist", "-nf %s" % (tmp_path / "test3"))
61 ip.magic("%%save %s 1-10" % (tmp_path / "test4"))
61 ip.run_line_magic("save", "%s 1-10" % (tmp_path / "test4"))
62
62
63 # New session
63 # New session
64 ip.history_manager.reset()
64 ip.history_manager.reset()
@@ -124,7 +124,7 b' def test_history():'
124
124
125 # Cross testing: check that magic %save can get previous session.
125 # Cross testing: check that magic %save can get previous session.
126 testfilename = (tmp_path / "test.py").resolve()
126 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")
128 with io.open(testfilename, encoding="utf-8") as testfile:
128 with io.open(testfilename, encoding="utf-8") as testfile:
129 assert testfile.read() == "# coding: utf-8\n" + "\n".join(hist) + "\n"
129 assert testfile.read() == "# coding: utf-8\n" + "\n".join(hist) + "\n"
130
130
General Comments 0
You need to be logged in to leave comments. Login now