##// END OF EJS Templates
Merge pull request #12482 from meeseeksmachine/auto-backport-of-pr-12475-on-7.x
Matthias Bussonnier -
r25950:16a0884d merge
parent child Browse files
Show More
@@ -94,7 +94,7 b' def cell_magic(lines):'
94 if re.match(r'%%\w+\?', lines[0]):
94 if re.match(r'%%\w+\?', lines[0]):
95 # This case will be handled by help_end
95 # This case will be handled by help_end
96 return lines
96 return lines
97 magic_name, _, first_line = lines[0][2:-1].partition(' ')
97 magic_name, _, first_line = lines[0][2:].rstrip().partition(' ')
98 body = ''.join(lines[1:])
98 body = ''.join(lines[1:])
99 return ['get_ipython().run_cell_magic(%r, %r, %r)\n'
99 return ['get_ipython().run_cell_magic(%r, %r, %r)\n'
100 % (magic_name, first_line, body)]
100 % (magic_name, first_line, body)]
@@ -152,8 +152,8 b' def assemble_continued_line(lines, start: Tuple[int, int], end_line: int):'
152 multiple lines.
152 multiple lines.
153 """
153 """
154 parts = [lines[start[0]][start[1]:]] + lines[start[0]+1:end_line+1]
154 parts = [lines[start[0]][start[1]:]] + lines[start[0]+1:end_line+1]
155 return ' '.join([p[:-2] for p in parts[:-1]] # Strip backslash+newline
155 return ' '.join([p.rstrip()[:-1] for p in parts[:-1]] # Strip backslash+newline
156 + [parts[-1][:-1]]) # Strip newline from last line
156 + [parts[-1].rstrip()]) # Strip newline from last line
157
157
158 class TokenTransformBase:
158 class TokenTransformBase:
159 """Base class for transformations which examine tokens.
159 """Base class for transformations which examine tokens.
@@ -31,6 +31,16 b' for a in range(5):'
31 get_ipython().run_line_magic('ls', '')
31 get_ipython().run_line_magic('ls', '')
32 """.splitlines(keepends=True))
32 """.splitlines(keepends=True))
33
33
34 CRLF_MAGIC = ([
35 "a = f()\n",
36 "%ls\r\n",
37 "g()\n"
38 ], (2, 0), [
39 "a = f()\n",
40 "get_ipython().run_line_magic('ls', '')\n",
41 "g()\n"
42 ])
43
34 MULTILINE_MAGIC_ASSIGN = ("""\
44 MULTILINE_MAGIC_ASSIGN = ("""\
35 a = f()
45 a = f()
36 b = %foo \\
46 b = %foo \\
@@ -190,6 +200,7 b' def test_find_magic_escape():'
190 def test_transform_magic_escape():
200 def test_transform_magic_escape():
191 check_transform(ipt2.EscapedCommand, MULTILINE_MAGIC)
201 check_transform(ipt2.EscapedCommand, MULTILINE_MAGIC)
192 check_transform(ipt2.EscapedCommand, INDENTED_MAGIC)
202 check_transform(ipt2.EscapedCommand, INDENTED_MAGIC)
203 check_transform(ipt2.EscapedCommand, CRLF_MAGIC)
193
204
194 def test_find_autocalls():
205 def test_find_autocalls():
195 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
206 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
@@ -114,3 +114,13 b' def test_leading_empty_lines():'
114 nt.assert_equal(
114 nt.assert_equal(
115 ipt2.leading_empty_lines(sample.splitlines(keepends=True)),
115 ipt2.leading_empty_lines(sample.splitlines(keepends=True)),
116 expected.splitlines(keepends=True))
116 expected.splitlines(keepends=True))
117
118 CRLF_MAGIC = ([
119 "%%ls\r\n"
120 ], [
121 "get_ipython().run_cell_magic('ls', '', '')\n"
122 ])
123
124 def test_crlf_magic():
125 for sample, expected in [CRLF_MAGIC]:
126 nt.assert_equal(ipt2.cell_magic(sample), expected) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now