##// END OF EJS Templates
Remove set-next input when triggering help....
Matthias Bussonnier -
Show More
@@ -193,7 +193,7 b' def assemble_logical_lines():'
193 line = ''.join(parts)
193 line = ''.join(parts)
194
194
195 # Utilities
195 # Utilities
196 def _make_help_call(target, esc, lspace, next_input=None):
196 def _make_help_call(target, esc, lspace):
197 """Prepares a pinfo(2)/psearch call from a target name and the escape
197 """Prepares a pinfo(2)/psearch call from a target name and the escape
198 (i.e. ? or ??)"""
198 (i.e. ? or ??)"""
199 method = 'pinfo2' if esc == '??' \
199 method = 'pinfo2' if esc == '??' \
@@ -203,11 +203,12 b' def _make_help_call(target, esc, lspace, next_input=None):'
203 #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args)
203 #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args)
204 t_magic_name, _, t_magic_arg_s = arg.partition(' ')
204 t_magic_name, _, t_magic_arg_s = arg.partition(' ')
205 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
205 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
206 if next_input is None:
206 return "%sget_ipython().run_line_magic(%r, %r)" % (
207 return '%sget_ipython().run_line_magic(%r, %r)' % (lspace, t_magic_name, t_magic_arg_s)
207 lspace,
208 else:
208 t_magic_name,
209 return '%sget_ipython().set_next_input(%r);get_ipython().run_line_magic(%r, %r)' % \
209 t_magic_arg_s,
210 (lspace, next_input, t_magic_name, t_magic_arg_s)
210 )
211
211
212
212 # These define the transformations for the different escape characters.
213 # These define the transformations for the different escape characters.
213 def _tr_system(line_info):
214 def _tr_system(line_info):
@@ -349,10 +350,7 b' def help_end(line):'
349 esc = m.group(3)
350 esc = m.group(3)
350 lspace = _initial_space_re.match(line).group(0)
351 lspace = _initial_space_re.match(line).group(0)
351
352
352 # If we're mid-command, put it back on the next prompt for the user.
353 return _make_help_call(target, esc, lspace)
353 next_input = line.rstrip('?') if line.strip() != m.group(0) else None
354
355 return _make_help_call(target, esc, lspace, next_input)
356
354
357
355
358 @CoroutineInputTransformer.wrap
356 @CoroutineInputTransformer.wrap
@@ -325,7 +325,7 b" ESC_PAREN = '/' # Call first argument with rest of line as arguments"
325 ESCAPE_SINGLES = {'!', '?', '%', ',', ';', '/'}
325 ESCAPE_SINGLES = {'!', '?', '%', ',', ';', '/'}
326 ESCAPE_DOUBLES = {'!!', '??'} # %% (cell magic) is handled separately
326 ESCAPE_DOUBLES = {'!!', '??'} # %% (cell magic) is handled separately
327
327
328 def _make_help_call(target, esc, next_input=None):
328 def _make_help_call(target, esc):
329 """Prepares a pinfo(2)/psearch call from a target name and the escape
329 """Prepares a pinfo(2)/psearch call from a target name and the escape
330 (i.e. ? or ??)"""
330 (i.e. ? or ??)"""
331 method = 'pinfo2' if esc == '??' \
331 method = 'pinfo2' if esc == '??' \
@@ -335,11 +335,8 b' def _make_help_call(target, esc, next_input=None):'
335 #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args)
335 #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args)
336 t_magic_name, _, t_magic_arg_s = arg.partition(' ')
336 t_magic_name, _, t_magic_arg_s = arg.partition(' ')
337 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
337 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
338 if next_input is None:
338 return "get_ipython().run_line_magic(%r, %r)" % (t_magic_name, t_magic_arg_s)
339 return 'get_ipython().run_line_magic(%r, %r)' % (t_magic_name, t_magic_arg_s)
339
340 else:
341 return 'get_ipython().set_next_input(%r);get_ipython().run_line_magic(%r, %r)' % \
342 (next_input, t_magic_name, t_magic_arg_s)
343
340
344 def _tr_help(content):
341 def _tr_help(content):
345 """Translate lines escaped with: ?
342 """Translate lines escaped with: ?
@@ -480,13 +477,8 b' class HelpEnd(TokenTransformBase):'
480 target = m.group(1)
477 target = m.group(1)
481 esc = m.group(3)
478 esc = m.group(3)
482
479
483 # If we're mid-command, put it back on the next prompt for the user.
484 next_input = None
485 if (not lines_before) and (not lines_after) \
486 and content.strip() != m.group(0):
487 next_input = content.rstrip('?\n')
488
480
489 call = _make_help_call(target, esc, next_input=next_input)
481 call = _make_help_call(target, esc)
490 new_line = indent + call + '\n'
482 new_line = indent + call + '\n'
491
483
492 return lines_before + [new_line] + lines_after
484 return lines_before + [new_line] + lines_after
@@ -60,105 +60,90 b' syntax = \\'
60 (' ',' '), # blank lines are kept intact
60 (' ',' '), # blank lines are kept intact
61 ("a, b = %foo", "a, b = get_ipython().run_line_magic('foo', '')"),
61 ("a, b = %foo", "a, b = get_ipython().run_line_magic('foo', '')"),
62 ],
62 ],
63
63 classic_prompt=[
64 classic_prompt =
64 (">>> x=1", "x=1"),
65 [('>>> x=1', 'x=1'),
65 ("x=1", "x=1"), # normal input is unmodified
66 ('x=1', 'x=1'), # normal input is unmodified
66 (" ", " "), # blank lines are kept intact
67 (' ', ' '), # blank lines are kept intact
68 ],
67 ],
69
68 ipy_prompt=[
70 ipy_prompt =
69 ("In [1]: x=1", "x=1"),
71 [('In [1]: x=1', 'x=1'),
70 ("x=1", "x=1"), # normal input is unmodified
72 ('x=1', 'x=1'), # normal input is unmodified
71 (" ", " "), # blank lines are kept intact
73 (' ',' '), # blank lines are kept intact
74 ],
72 ],
75
76 # Tests for the escape transformer to leave normal code alone
73 # Tests for the escape transformer to leave normal code alone
77 escaped_noesc =
74 escaped_noesc=[
78 [ (' ', ' '),
75 (" ", " "),
79 ('x=1', 'x=1'),
76 ("x=1", "x=1"),
80 ],
77 ],
81
82 # System calls
78 # System calls
83 escaped_shell =
79 escaped_shell=[
84 [ ('!ls', "get_ipython().system('ls')"),
80 ("!ls", "get_ipython().system('ls')"),
85 # Double-escape shell, this means to capture the output of the
81 # Double-escape shell, this means to capture the output of the
86 # subprocess and return it
82 # subprocess and return it
87 ('!!ls', "get_ipython().getoutput('ls')"),
83 ("!!ls", "get_ipython().getoutput('ls')"),
88 ],
84 ],
89
90 # Help/object info
85 # Help/object info
91 escaped_help =
86 escaped_help=[
92 [ ('?', 'get_ipython().show_usage()'),
87 ("?", "get_ipython().show_usage()"),
93 ('?x1', "get_ipython().run_line_magic('pinfo', 'x1')"),
88 ("?x1", "get_ipython().run_line_magic('pinfo', 'x1')"),
94 ('??x2', "get_ipython().run_line_magic('pinfo2', 'x2')"),
89 ("??x2", "get_ipython().run_line_magic('pinfo2', 'x2')"),
95 ('?a.*s', "get_ipython().run_line_magic('psearch', 'a.*s')"),
90 ("?a.*s", "get_ipython().run_line_magic('psearch', 'a.*s')"),
96 ('?%hist1', "get_ipython().run_line_magic('pinfo', '%hist1')"),
91 ("?%hist1", "get_ipython().run_line_magic('pinfo', '%hist1')"),
97 ('?%%hist2', "get_ipython().run_line_magic('pinfo', '%%hist2')"),
92 ("?%%hist2", "get_ipython().run_line_magic('pinfo', '%%hist2')"),
98 ('?abc = qwe', "get_ipython().run_line_magic('pinfo', 'abc')"),
93 ("?abc = qwe", "get_ipython().run_line_magic('pinfo', 'abc')"),
99 ],
94 ],
100
95 end_help=[
101 end_help =
96 ("x3?", "get_ipython().run_line_magic('pinfo', 'x3')"),
102 [ ('x3?', "get_ipython().run_line_magic('pinfo', 'x3')"),
97 ("x4??", "get_ipython().run_line_magic('pinfo2', 'x4')"),
103 ('x4??', "get_ipython().run_line_magic('pinfo2', 'x4')"),
98 ("%hist1?", "get_ipython().run_line_magic('pinfo', '%hist1')"),
104 ('%hist1?', "get_ipython().run_line_magic('pinfo', '%hist1')"),
99 ("%hist2??", "get_ipython().run_line_magic('pinfo2', '%hist2')"),
105 ('%hist2??', "get_ipython().run_line_magic('pinfo2', '%hist2')"),
100 ("%%hist3?", "get_ipython().run_line_magic('pinfo', '%%hist3')"),
106 ('%%hist3?', "get_ipython().run_line_magic('pinfo', '%%hist3')"),
101 ("%%hist4??", "get_ipython().run_line_magic('pinfo2', '%%hist4')"),
107 ('%%hist4??', "get_ipython().run_line_magic('pinfo2', '%%hist4')"),
102 ("π.foo?", "get_ipython().run_line_magic('pinfo', 'π.foo')"),
108 ('π.foo?', "get_ipython().run_line_magic('pinfo', 'π.foo')"),
103 ("f*?", "get_ipython().run_line_magic('psearch', 'f*')"),
109 ('f*?', "get_ipython().run_line_magic('psearch', 'f*')"),
104 ("ax.*aspe*?", "get_ipython().run_line_magic('psearch', 'ax.*aspe*')"),
110 ('ax.*aspe*?', "get_ipython().run_line_magic('psearch', 'ax.*aspe*')"),
105 ("a = abc?", "get_ipython().run_line_magic('pinfo', 'abc')"),
111 ('a = abc?', "get_ipython().set_next_input('a = abc');"
106 ("a = abc.qe??", "get_ipython().run_line_magic('pinfo2', 'abc.qe')"),
112 "get_ipython().run_line_magic('pinfo', 'abc')"),
107 ("a = *.items?", "get_ipython().run_line_magic('psearch', '*.items')"),
113 ('a = abc.qe??', "get_ipython().set_next_input('a = abc.qe');"
108 ("plot(a?", "get_ipython().run_line_magic('pinfo', 'a')"),
114 "get_ipython().run_line_magic('pinfo2', 'abc.qe')"),
109 ("a*2 #comment?", "a*2 #comment?"),
115 ('a = *.items?', "get_ipython().set_next_input('a = *.items');"
116 "get_ipython().run_line_magic('psearch', '*.items')"),
117 ('plot(a?', "get_ipython().set_next_input('plot(a');"
118 "get_ipython().run_line_magic('pinfo', 'a')"),
119 ('a*2 #comment?', 'a*2 #comment?'),
120 ],
110 ],
121
122 # Explicit magic calls
111 # Explicit magic calls
123 escaped_magic =
112 escaped_magic=[
124 [ ('%cd', "get_ipython().run_line_magic('cd', '')"),
113 ("%cd", "get_ipython().run_line_magic('cd', '')"),
125 ('%cd /home', "get_ipython().run_line_magic('cd', '/home')"),
114 ("%cd /home", "get_ipython().run_line_magic('cd', '/home')"),
126 # Backslashes need to be escaped.
115 # Backslashes need to be escaped.
127 ('%cd C:\\User', "get_ipython().run_line_magic('cd', 'C:\\\\User')"),
116 ("%cd C:\\User", "get_ipython().run_line_magic('cd', 'C:\\\\User')"),
128 (' %magic', " get_ipython().run_line_magic('magic', '')"),
117 (" %magic", " get_ipython().run_line_magic('magic', '')"),
129 ],
118 ],
130
131 # Quoting with separate arguments
119 # Quoting with separate arguments
132 escaped_quote =
120 escaped_quote=[
133 [ (',f', 'f("")'),
121 (",f", 'f("")'),
134 (',f x', 'f("x")'),
122 (",f x", 'f("x")'),
135 (' ,f y', ' f("y")'),
123 (" ,f y", ' f("y")'),
136 (',f a b', 'f("a", "b")'),
124 (",f a b", 'f("a", "b")'),
137 ],
125 ],
138
139 # Quoting with single argument
126 # Quoting with single argument
140 escaped_quote2 =
127 escaped_quote2=[
141 [ (';f', 'f("")'),
128 (";f", 'f("")'),
142 (';f x', 'f("x")'),
129 (";f x", 'f("x")'),
143 (' ;f y', ' f("y")'),
130 (" ;f y", ' f("y")'),
144 (';f a b', 'f("a b")'),
131 (";f a b", 'f("a b")'),
145 ],
132 ],
146
147 # Simply apply parens
133 # Simply apply parens
148 escaped_paren =
134 escaped_paren=[
149 [ ('/f', 'f()'),
135 ("/f", "f()"),
150 ('/f x', 'f(x)'),
136 ("/f x", "f(x)"),
151 (' /f y', ' f(y)'),
137 (" /f y", " f(y)"),
152 ('/f a b', 'f(a, b)'),
138 ("/f a b", "f(a, b)"),
153 ],
139 ],
154
155 # Check that we transform prompts before other transforms
140 # Check that we transform prompts before other transforms
156 mixed =
141 mixed=[
157 [ ('In [1]: %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
142 ("In [1]: %lsmagic", "get_ipython().run_line_magic('lsmagic', '')"),
158 ('>>> %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
143 (">>> %lsmagic", "get_ipython().run_line_magic('lsmagic', '')"),
159 ('In [2]: !ls', "get_ipython().system('ls')"),
144 ("In [2]: !ls", "get_ipython().system('ls')"),
160 ('In [3]: abs?', "get_ipython().run_line_magic('pinfo', 'abs')"),
145 ("In [3]: abs?", "get_ipython().run_line_magic('pinfo', 'abs')"),
161 ('In [4]: b = %who', "b = get_ipython().run_line_magic('who', '')"),
146 ("In [4]: b = %who", "b = get_ipython().run_line_magic('who', '')"),
162 ],
147 ],
163 )
148 )
164
149
@@ -14,45 +14,65 b' import pytest'
14 from IPython.core import inputtransformer2 as ipt2
14 from IPython.core import inputtransformer2 as ipt2
15 from IPython.core.inputtransformer2 import _find_assign_op, make_tokens_by_line
15 from IPython.core.inputtransformer2 import _find_assign_op, make_tokens_by_line
16
16
17 MULTILINE_MAGIC = ("""\
17 MULTILINE_MAGIC = (
18 """\
18 a = f()
19 a = f()
19 %foo \\
20 %foo \\
20 bar
21 bar
21 g()
22 g()
22 """.splitlines(keepends=True), (2, 0), """\
23 """.splitlines(
24 keepends=True
25 ),
26 (2, 0),
27 """\
23 a = f()
28 a = f()
24 get_ipython().run_line_magic('foo', ' bar')
29 get_ipython().run_line_magic('foo', ' bar')
25 g()
30 g()
26 """.splitlines(keepends=True))
31 """.splitlines(
32 keepends=True
33 ),
34 )
27
35
28 INDENTED_MAGIC = ("""\
36 INDENTED_MAGIC = (
37 """\
29 for a in range(5):
38 for a in range(5):
30 %ls
39 %ls
31 """.splitlines(keepends=True), (2, 4), """\
40 """.splitlines(
41 keepends=True
42 ),
43 (2, 4),
44 """\
32 for a in range(5):
45 for a in range(5):
33 get_ipython().run_line_magic('ls', '')
46 get_ipython().run_line_magic('ls', '')
34 """.splitlines(keepends=True))
47 """.splitlines(
48 keepends=True
49 ),
50 )
51
52 CRLF_MAGIC = (
53 ["a = f()\n", "%ls\r\n", "g()\n"],
54 (2, 0),
55 ["a = f()\n", "get_ipython().run_line_magic('ls', '')\n", "g()\n"],
56 )
35
57
36 CRLF_MAGIC = ([
58 MULTILINE_MAGIC_ASSIGN = (
37 "a = f()\n",
59 """\
38 "%ls\r\n",
39 "g()\n"
40 ], (2, 0), [
41 "a = f()\n",
42 "get_ipython().run_line_magic('ls', '')\n",
43 "g()\n"
44 ])
45
46 MULTILINE_MAGIC_ASSIGN = ("""\
47 a = f()
60 a = f()
48 b = %foo \\
61 b = %foo \\
49 bar
62 bar
50 g()
63 g()
51 """.splitlines(keepends=True), (2, 4), """\
64 """.splitlines(
65 keepends=True
66 ),
67 (2, 4),
68 """\
52 a = f()
69 a = f()
53 b = get_ipython().run_line_magic('foo', ' bar')
70 b = get_ipython().run_line_magic('foo', ' bar')
54 g()
71 g()
55 """.splitlines(keepends=True))
72 """.splitlines(
73 keepends=True
74 ),
75 )
56
76
57 MULTILINE_SYSTEM_ASSIGN = ("""\
77 MULTILINE_SYSTEM_ASSIGN = ("""\
58 a = f()
78 a = f()
@@ -72,68 +92,70 b' def test():'
72 for i in range(1):
92 for i in range(1):
73 print(i)
93 print(i)
74 res =! ls
94 res =! ls
75 """.splitlines(keepends=True), (4, 7), '''\
95 """.splitlines(
96 keepends=True
97 ),
98 (4, 7),
99 """\
76 def test():
100 def test():
77 for i in range(1):
101 for i in range(1):
78 print(i)
102 print(i)
79 res =get_ipython().getoutput(\' ls\')
103 res =get_ipython().getoutput(\' ls\')
80 '''.splitlines(keepends=True))
104 """.splitlines(
105 keepends=True
106 ),
107 )
81
108
82 ######
109 ######
83
110
84 AUTOCALL_QUOTE = (
111 AUTOCALL_QUOTE = ([",f 1 2 3\n"], (1, 0), ['f("1", "2", "3")\n'])
85 [",f 1 2 3\n"], (1, 0),
86 ['f("1", "2", "3")\n']
87 )
88
112
89 AUTOCALL_QUOTE2 = (
113 AUTOCALL_QUOTE2 = ([";f 1 2 3\n"], (1, 0), ['f("1 2 3")\n'])
90 [";f 1 2 3\n"], (1, 0),
91 ['f("1 2 3")\n']
92 )
93
114
94 AUTOCALL_PAREN = (
115 AUTOCALL_PAREN = (["/f 1 2 3\n"], (1, 0), ["f(1, 2, 3)\n"])
95 ["/f 1 2 3\n"], (1, 0),
96 ['f(1, 2, 3)\n']
97 )
98
116
99 SIMPLE_HELP = (
117 SIMPLE_HELP = (["foo?\n"], (1, 0), ["get_ipython().run_line_magic('pinfo', 'foo')\n"])
100 ["foo?\n"], (1, 0),
101 ["get_ipython().run_line_magic('pinfo', 'foo')\n"]
102 )
103
118
104 DETAILED_HELP = (
119 DETAILED_HELP = (
105 ["foo??\n"], (1, 0),
120 ["foo??\n"],
106 ["get_ipython().run_line_magic('pinfo2', 'foo')\n"]
121 (1, 0),
122 ["get_ipython().run_line_magic('pinfo2', 'foo')\n"],
107 )
123 )
108
124
109 MAGIC_HELP = (
125 MAGIC_HELP = (["%foo?\n"], (1, 0), ["get_ipython().run_line_magic('pinfo', '%foo')\n"])
110 ["%foo?\n"], (1, 0),
111 ["get_ipython().run_line_magic('pinfo', '%foo')\n"]
112 )
113
126
114 HELP_IN_EXPR = (
127 HELP_IN_EXPR = (
115 ["a = b + c?\n"], (1, 0),
128 ["a = b + c?\n"],
116 ["get_ipython().set_next_input('a = b + c');"
129 (1, 0),
117 "get_ipython().run_line_magic('pinfo', 'c')\n"]
130 ["get_ipython().run_line_magic('pinfo', 'c')\n"],
118 )
131 )
119
132
120 HELP_CONTINUED_LINE = ("""\
133 HELP_CONTINUED_LINE = (
134 """\
121 a = \\
135 a = \\
122 zip?
136 zip?
123 """.splitlines(keepends=True), (1, 0),
137 """.splitlines(
124 [r"get_ipython().set_next_input('a = \\\nzip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
138 keepends=True
139 ),
140 (1, 0),
141 [r"get_ipython().run_line_magic('pinfo', 'zip')" + "\n"],
125 )
142 )
126
143
127 HELP_MULTILINE = ("""\
144 HELP_MULTILINE = (
145 """\
128 (a,
146 (a,
129 b) = zip?
147 b) = zip?
130 """.splitlines(keepends=True), (1, 0),
148 """.splitlines(
131 [r"get_ipython().set_next_input('(a,\nb) = zip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
149 keepends=True
150 ),
151 (1, 0),
152 [r"get_ipython().run_line_magic('pinfo', 'zip')" + "\n"],
132 )
153 )
133
154
134 HELP_UNICODE = (
155 HELP_UNICODE = (
135 ["π.foo?\n"], (1, 0),
156 ["π.foo?\n"],
136 ["get_ipython().run_line_magic('pinfo', 'π.foo')\n"]
157 (1, 0),
158 ["get_ipython().run_line_magic('pinfo', 'π.foo')\n"],
137 )
159 )
138
160
139
161
@@ -149,6 +171,7 b' def test_check_make_token_by_line_never_ends_empty():'
149 Check that not sequence of single or double characters ends up leading to en empty list of tokens
171 Check that not sequence of single or double characters ends up leading to en empty list of tokens
150 """
172 """
151 from string import printable
173 from string import printable
174
152 for c in printable:
175 for c in printable:
153 assert make_tokens_by_line(c)[-1] != []
176 assert make_tokens_by_line(c)[-1] != []
154 for k in printable:
177 for k in printable:
@@ -166,25 +189,30 b' def check_find(transformer, case, match=True):'
166 else:
189 else:
167 assert res is None
190 assert res is None
168
191
192
169 def check_transform(transformer_cls, case):
193 def check_transform(transformer_cls, case):
170 lines, start, expected = case
194 lines, start, expected = case
171 transformer = transformer_cls(start)
195 transformer = transformer_cls(start)
172 assert transformer.transform(lines) == expected
196 assert transformer.transform(lines) == expected
173
197
198
174 def test_continued_line():
199 def test_continued_line():
175 lines = MULTILINE_MAGIC_ASSIGN[0]
200 lines = MULTILINE_MAGIC_ASSIGN[0]
176 assert ipt2.find_end_of_continued_line(lines, 1) == 2
201 assert ipt2.find_end_of_continued_line(lines, 1) == 2
177
202
178 assert ipt2.assemble_continued_line(lines, (1, 5), 2) == "foo bar"
203 assert ipt2.assemble_continued_line(lines, (1, 5), 2) == "foo bar"
179
204
205
180 def test_find_assign_magic():
206 def test_find_assign_magic():
181 check_find(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
207 check_find(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
182 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN, match=False)
208 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN, match=False)
183 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT, match=False)
209 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT, match=False)
184
210
211
185 def test_transform_assign_magic():
212 def test_transform_assign_magic():
186 check_transform(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
213 check_transform(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
187
214
215
188 def test_find_assign_system():
216 def test_find_assign_system():
189 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
217 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
190 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
218 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
@@ -192,30 +220,36 b' def test_find_assign_system():'
192 check_find(ipt2.SystemAssign, (["a=!ls\n"], (1, 2), None))
220 check_find(ipt2.SystemAssign, (["a=!ls\n"], (1, 2), None))
193 check_find(ipt2.SystemAssign, MULTILINE_MAGIC_ASSIGN, match=False)
221 check_find(ipt2.SystemAssign, MULTILINE_MAGIC_ASSIGN, match=False)
194
222
223
195 def test_transform_assign_system():
224 def test_transform_assign_system():
196 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
225 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
197 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
226 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
198
227
228
199 def test_find_magic_escape():
229 def test_find_magic_escape():
200 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC)
230 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC)
201 check_find(ipt2.EscapedCommand, INDENTED_MAGIC)
231 check_find(ipt2.EscapedCommand, INDENTED_MAGIC)
202 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC_ASSIGN, match=False)
232 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC_ASSIGN, match=False)
203
233
234
204 def test_transform_magic_escape():
235 def test_transform_magic_escape():
205 check_transform(ipt2.EscapedCommand, MULTILINE_MAGIC)
236 check_transform(ipt2.EscapedCommand, MULTILINE_MAGIC)
206 check_transform(ipt2.EscapedCommand, INDENTED_MAGIC)
237 check_transform(ipt2.EscapedCommand, INDENTED_MAGIC)
207 check_transform(ipt2.EscapedCommand, CRLF_MAGIC)
238 check_transform(ipt2.EscapedCommand, CRLF_MAGIC)
208
239
240
209 def test_find_autocalls():
241 def test_find_autocalls():
210 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
242 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
211 print("Testing %r" % case[0])
243 print("Testing %r" % case[0])
212 check_find(ipt2.EscapedCommand, case)
244 check_find(ipt2.EscapedCommand, case)
213
245
246
214 def test_transform_autocall():
247 def test_transform_autocall():
215 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
248 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
216 print("Testing %r" % case[0])
249 print("Testing %r" % case[0])
217 check_transform(ipt2.EscapedCommand, case)
250 check_transform(ipt2.EscapedCommand, case)
218
251
252
219 def test_find_help():
253 def test_find_help():
220 for case in [SIMPLE_HELP, DETAILED_HELP, MAGIC_HELP, HELP_IN_EXPR]:
254 for case in [SIMPLE_HELP, DETAILED_HELP, MAGIC_HELP, HELP_IN_EXPR]:
221 check_find(ipt2.HelpEnd, case)
255 check_find(ipt2.HelpEnd, case)
@@ -233,6 +267,7 b' def test_find_help():'
233 # Nor in a string
267 # Nor in a string
234 check_find(ipt2.HelpEnd, (["foo = '''bar?\n"], None, None), match=False)
268 check_find(ipt2.HelpEnd, (["foo = '''bar?\n"], None, None), match=False)
235
269
270
236 def test_transform_help():
271 def test_transform_help():
237 tf = ipt2.HelpEnd((1, 0), (1, 9))
272 tf = ipt2.HelpEnd((1, 0), (1, 9))
238 assert tf.transform(HELP_IN_EXPR[0]) == HELP_IN_EXPR[2]
273 assert tf.transform(HELP_IN_EXPR[0]) == HELP_IN_EXPR[2]
@@ -246,10 +281,12 b' def test_transform_help():'
246 tf = ipt2.HelpEnd((1, 0), (1, 0))
281 tf = ipt2.HelpEnd((1, 0), (1, 0))
247 assert tf.transform(HELP_UNICODE[0]) == HELP_UNICODE[2]
282 assert tf.transform(HELP_UNICODE[0]) == HELP_UNICODE[2]
248
283
284
249 def test_find_assign_op_dedent():
285 def test_find_assign_op_dedent():
250 """
286 """
251 be careful that empty token like dedent are not counted as parens
287 be careful that empty token like dedent are not counted as parens
252 """
288 """
289
253 class Tk:
290 class Tk:
254 def __init__(self, s):
291 def __init__(self, s):
255 self.string = s
292 self.string = s
@@ -302,16 +339,18 b' def test_check_complete_param(code, expected, number):'
302 def test_check_complete():
339 def test_check_complete():
303 cc = ipt2.TransformerManager().check_complete
340 cc = ipt2.TransformerManager().check_complete
304
341
305 example = dedent("""
342 example = dedent(
343 """
306 if True:
344 if True:
307 a=1""" )
345 a=1"""
346 )
308
347
309 assert cc(example) == ("incomplete", 4)
348 assert cc(example) == ("incomplete", 4)
310 assert cc(example + "\n") == ("complete", None)
349 assert cc(example + "\n") == ("complete", None)
311 assert cc(example + "\n ") == ("complete", None)
350 assert cc(example + "\n ") == ("complete", None)
312
351
313 # no need to loop on all the letters/numbers.
352 # no need to loop on all the letters/numbers.
314 short = '12abAB'+string.printable[62:]
353 short = "12abAB" + string.printable[62:]
315 for c in short:
354 for c in short:
316 # test does not raise:
355 # test does not raise:
317 cc(c)
356 cc(c)
@@ -371,10 +410,9 b' def test_null_cleanup_transformer():'
371 assert manager.transform_cell("") == ""
410 assert manager.transform_cell("") == ""
372
411
373
412
374
375
376 def test_side_effects_I():
413 def test_side_effects_I():
377 count = 0
414 count = 0
415
378 def counter(lines):
416 def counter(lines):
379 nonlocal count
417 nonlocal count
380 count += 1
418 count += 1
@@ -384,14 +422,13 b' def test_side_effects_I():'
384
422
385 manager = ipt2.TransformerManager()
423 manager = ipt2.TransformerManager()
386 manager.cleanup_transforms.insert(0, counter)
424 manager.cleanup_transforms.insert(0, counter)
387 assert manager.check_complete("a=1\n") == ('complete', None)
425 assert manager.check_complete("a=1\n") == ("complete", None)
388 assert count == 0
426 assert count == 0
389
427
390
428
391
392
393 def test_side_effects_II():
429 def test_side_effects_II():
394 count = 0
430 count = 0
431
395 def counter(lines):
432 def counter(lines):
396 nonlocal count
433 nonlocal count
397 count += 1
434 count += 1
@@ -401,5 +438,5 b' def test_side_effects_II():'
401
438
402 manager = ipt2.TransformerManager()
439 manager = ipt2.TransformerManager()
403 manager.line_transforms.insert(0, counter)
440 manager.line_transforms.insert(0, counter)
404 assert manager.check_complete("b=1\n") == ('complete', None)
441 assert manager.check_complete("b=1\n") == ("complete", None)
405 assert count == 0
442 assert count == 0
@@ -8,6 +8,11 b''
8 IPython 8.3.0
8 IPython 8.3.0
9 -------------
9 -------------
10
10
11 - :ghpull:`13625`, using ``?``, ``??``, ``*?`` will not call
12 ``set_next_input`` as most frontend allow proper multiline editing and it was
13 causing issues for many users of multi-cell frontends.
14
15
11 - :ghpull:`13600`, ``pre_run_*``-hooks will now have a ``cell_id`` attribute on
16 - :ghpull:`13600`, ``pre_run_*``-hooks will now have a ``cell_id`` attribute on
12 the info object when frontend provide it.
17 the info object when frontend provide it.
13
18
General Comments 0
You need to be logged in to leave comments. Login now