Show More
@@ -43,10 +43,10 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( |
|
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( |
|
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 |
@@ -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( |
|
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 | [ | |||
63 |
('len "abc"', |
|
64 | ('len "abc"', 'len "abc"'), | |
64 |
( |
|
65 | ("autocallable", "autocallable()"), | |
65 | # Don't add extra brackets (gh-1117) |
|
66 | # Don't add extra brackets (gh-1117) | |
66 |
( |
|
67 | ("autocallable()", "autocallable()"), | |
67 |
] |
|
68 | ] | |
68 | ip.magic('autocall 1') |
|
69 | ) | |
69 | run([ |
|
70 | ip.run_line_magic("autocall", "1") | |
|
71 | run( | |||
|
72 | [ | |||
70 | ('len "abc"', 'len("abc")'), |
|
73 | ('len "abc"', 'len("abc")'), | |
71 | ('len "abc";', 'len("abc");'), # ; is special -- moves out of parens |
|
74 | ('len "abc";', 'len("abc");'), # ; is special -- moves out of parens | |
72 | # Autocall is turned off if first arg is [] and the object |
|
75 | # Autocall is turned off if first arg is [] and the object | |
73 | # is both callable and indexable. Like so: |
|
76 | # is both callable and indexable. Like so: | |
74 |
( |
|
77 | ("len [1,2]", "len([1,2])"), # len doesn't support __getitem__... | |
75 |
( |
|
78 | ("call_idx [1]", "call_idx [1]"), # call_idx *does*.. | |
76 |
( |
|
79 | ("call_idx 1", "call_idx(1)"), | |
77 |
( |
|
80 | ("len", "len"), # only at 2 does it auto-call on single args | |
78 |
] |
|
81 | ] | |
79 | ip.magic('autocall 2') |
|
82 | ) | |
80 | run([ |
|
83 | ip.run_line_magic("autocall", "2") | |
|
84 | run( | |||
|
85 | [ | |||
81 | ('len "abc"', 'len("abc")'), |
|
86 | ('len "abc"', 'len("abc")'), | |
82 | ('len "abc";', 'len("abc");'), |
|
87 | ('len "abc";', 'len("abc");'), | |
83 |
( |
|
88 | ("len [1,2]", "len([1,2])"), | |
84 |
( |
|
89 | ("call_idx [1]", "call_idx [1]"), | |
85 |
( |
|
90 | ("call_idx 1", "call_idx(1)"), | |
86 | # This is what's different: |
|
91 | # This is what's different: | |
87 |
( |
|
92 | ("len", "len()"), # only at 2 does it auto-call on single args | |
88 |
] |
|
93 | ] | |
89 | ip.magic('autocall 1') |
|
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( |
|
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(" |
|
58 | ip.run_line_magic("hist", "-f %s" % (tmp_path / "test1")) | |
59 |
ip.magic(" |
|
59 | ip.run_line_magic("hist", "-pf %s" % (tmp_path / "test2")) | |
60 |
ip.magic(" |
|
60 | ip.run_line_magic("hist", "-nf %s" % (tmp_path / "test3")) | |
61 |
ip.magic(" |
|
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 |
|
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