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