Show More
@@ -1,322 +1,326 b'' | |||||
1 | import unittest |
|
1 | import unittest | |
2 | import nose.tools as nt |
|
2 | import nose.tools as nt | |
3 |
|
3 | |||
4 | from IPython.testing import tools as tt |
|
4 | from IPython.testing import tools as tt | |
5 | from IPython.utils import py3compat |
|
5 | from IPython.utils import py3compat | |
6 | u_fmt = py3compat.u_format |
|
6 | u_fmt = py3compat.u_format | |
7 |
|
7 | |||
8 | from IPython.core import inputtransformer as ipt |
|
8 | from IPython.core import inputtransformer as ipt | |
9 |
|
9 | |||
10 | def transform_and_reset(transformer): |
|
10 | def transform_and_reset(transformer): | |
11 | transformer = transformer() |
|
11 | transformer = transformer() | |
12 | def transform(inp): |
|
12 | def transform(inp): | |
13 | try: |
|
13 | try: | |
14 | return transformer.push(inp) |
|
14 | return transformer.push(inp) | |
15 | finally: |
|
15 | finally: | |
16 | transformer.reset() |
|
16 | transformer.reset() | |
17 |
|
17 | |||
18 | return transform |
|
18 | return transform | |
19 |
|
19 | |||
20 | # Transformer tests |
|
20 | # Transformer tests | |
21 | def transform_checker(tests, transformer): |
|
21 | def transform_checker(tests, transformer): | |
22 | """Utility to loop over test inputs""" |
|
22 | """Utility to loop over test inputs""" | |
23 | transformer = transformer() |
|
23 | transformer = transformer() | |
24 | try: |
|
24 | try: | |
25 | for inp, tr in tests: |
|
25 | for inp, tr in tests: | |
26 | nt.assert_equal(transformer.push(inp), tr) |
|
26 | if inp is None: | |
|
27 | out = transformer.reset() | |||
|
28 | else: | |||
|
29 | out = transformer.push(inp) | |||
|
30 | nt.assert_equal(out, tr) | |||
27 | finally: |
|
31 | finally: | |
28 | transformer.reset() |
|
32 | transformer.reset() | |
29 |
|
33 | |||
30 | # Data for all the syntax tests in the form of lists of pairs of |
|
34 | # Data for all the syntax tests in the form of lists of pairs of | |
31 | # raw/transformed input. We store it here as a global dict so that we can use |
|
35 | # raw/transformed input. We store it here as a global dict so that we can use | |
32 | # it both within single-function tests and also to validate the behavior of the |
|
36 | # it both within single-function tests and also to validate the behavior of the | |
33 | # larger objects |
|
37 | # larger objects | |
34 |
|
38 | |||
35 | syntax = \ |
|
39 | syntax = \ | |
36 | dict(assign_system = |
|
40 | dict(assign_system = | |
37 | [(i,py3compat.u_format(o)) for i,o in \ |
|
41 | [(i,py3compat.u_format(o)) for i,o in \ | |
38 | [(u'a =! ls', "a = get_ipython().getoutput({u}'ls')"), |
|
42 | [(u'a =! ls', "a = get_ipython().getoutput({u}'ls')"), | |
39 | (u'b = !ls', "b = get_ipython().getoutput({u}'ls')"), |
|
43 | (u'b = !ls', "b = get_ipython().getoutput({u}'ls')"), | |
40 | ('x=1', 'x=1'), # normal input is unmodified |
|
44 | ('x=1', 'x=1'), # normal input is unmodified | |
41 | (' ',' '), # blank lines are kept intact |
|
45 | (' ',' '), # blank lines are kept intact | |
42 | ]], |
|
46 | ]], | |
43 |
|
47 | |||
44 | assign_magic = |
|
48 | assign_magic = | |
45 | [(i,py3compat.u_format(o)) for i,o in \ |
|
49 | [(i,py3compat.u_format(o)) for i,o in \ | |
46 | [(u'a =% who', "a = get_ipython().magic({u}'who')"), |
|
50 | [(u'a =% who', "a = get_ipython().magic({u}'who')"), | |
47 | (u'b = %who', "b = get_ipython().magic({u}'who')"), |
|
51 | (u'b = %who', "b = get_ipython().magic({u}'who')"), | |
48 | ('x=1', 'x=1'), # normal input is unmodified |
|
52 | ('x=1', 'x=1'), # normal input is unmodified | |
49 | (' ',' '), # blank lines are kept intact |
|
53 | (' ',' '), # blank lines are kept intact | |
50 | ]], |
|
54 | ]], | |
51 |
|
55 | |||
52 | classic_prompt = |
|
56 | classic_prompt = | |
53 | [('>>> x=1', 'x=1'), |
|
57 | [('>>> x=1', 'x=1'), | |
54 | ('x=1', 'x=1'), # normal input is unmodified |
|
58 | ('x=1', 'x=1'), # normal input is unmodified | |
55 | (' ', ' '), # blank lines are kept intact |
|
59 | (' ', ' '), # blank lines are kept intact | |
56 | ], |
|
60 | ], | |
57 |
|
61 | |||
58 | ipy_prompt = |
|
62 | ipy_prompt = | |
59 | [('In [1]: x=1', 'x=1'), |
|
63 | [('In [1]: x=1', 'x=1'), | |
60 | ('x=1', 'x=1'), # normal input is unmodified |
|
64 | ('x=1', 'x=1'), # normal input is unmodified | |
61 | (' ',' '), # blank lines are kept intact |
|
65 | (' ',' '), # blank lines are kept intact | |
62 | ], |
|
66 | ], | |
63 |
|
67 | |||
64 | # Tests for the escape transformer to leave normal code alone |
|
68 | # Tests for the escape transformer to leave normal code alone | |
65 | escaped_noesc = |
|
69 | escaped_noesc = | |
66 | [ (' ', ' '), |
|
70 | [ (' ', ' '), | |
67 | ('x=1', 'x=1'), |
|
71 | ('x=1', 'x=1'), | |
68 | ], |
|
72 | ], | |
69 |
|
73 | |||
70 | # System calls |
|
74 | # System calls | |
71 | escaped_shell = |
|
75 | escaped_shell = | |
72 | [(i,py3compat.u_format(o)) for i,o in \ |
|
76 | [(i,py3compat.u_format(o)) for i,o in \ | |
73 | [ (u'!ls', "get_ipython().system({u}'ls')"), |
|
77 | [ (u'!ls', "get_ipython().system({u}'ls')"), | |
74 | # Double-escape shell, this means to capture the output of the |
|
78 | # Double-escape shell, this means to capture the output of the | |
75 | # subprocess and return it |
|
79 | # subprocess and return it | |
76 | (u'!!ls', "get_ipython().getoutput({u}'ls')"), |
|
80 | (u'!!ls', "get_ipython().getoutput({u}'ls')"), | |
77 | ]], |
|
81 | ]], | |
78 |
|
82 | |||
79 | # Help/object info |
|
83 | # Help/object info | |
80 | escaped_help = |
|
84 | escaped_help = | |
81 | [(i,py3compat.u_format(o)) for i,o in \ |
|
85 | [(i,py3compat.u_format(o)) for i,o in \ | |
82 | [ (u'?', 'get_ipython().show_usage()'), |
|
86 | [ (u'?', 'get_ipython().show_usage()'), | |
83 | (u'?x1', "get_ipython().magic({u}'pinfo x1')"), |
|
87 | (u'?x1', "get_ipython().magic({u}'pinfo x1')"), | |
84 | (u'??x2', "get_ipython().magic({u}'pinfo2 x2')"), |
|
88 | (u'??x2', "get_ipython().magic({u}'pinfo2 x2')"), | |
85 | (u'?a.*s', "get_ipython().magic({u}'psearch a.*s')"), |
|
89 | (u'?a.*s', "get_ipython().magic({u}'psearch a.*s')"), | |
86 | (u'?%hist1', "get_ipython().magic({u}'pinfo %hist1')"), |
|
90 | (u'?%hist1', "get_ipython().magic({u}'pinfo %hist1')"), | |
87 | (u'?%%hist2', "get_ipython().magic({u}'pinfo %%hist2')"), |
|
91 | (u'?%%hist2', "get_ipython().magic({u}'pinfo %%hist2')"), | |
88 | (u'?abc = qwe', "get_ipython().magic({u}'pinfo abc')"), |
|
92 | (u'?abc = qwe', "get_ipython().magic({u}'pinfo abc')"), | |
89 | ]], |
|
93 | ]], | |
90 |
|
94 | |||
91 | end_help = |
|
95 | end_help = | |
92 | [(i,py3compat.u_format(o)) for i,o in \ |
|
96 | [(i,py3compat.u_format(o)) for i,o in \ | |
93 | [ (u'x3?', "get_ipython().magic({u}'pinfo x3')"), |
|
97 | [ (u'x3?', "get_ipython().magic({u}'pinfo x3')"), | |
94 | (u'x4??', "get_ipython().magic({u}'pinfo2 x4')"), |
|
98 | (u'x4??', "get_ipython().magic({u}'pinfo2 x4')"), | |
95 | (u'%hist1?', "get_ipython().magic({u}'pinfo %hist1')"), |
|
99 | (u'%hist1?', "get_ipython().magic({u}'pinfo %hist1')"), | |
96 | (u'%hist2??', "get_ipython().magic({u}'pinfo2 %hist2')"), |
|
100 | (u'%hist2??', "get_ipython().magic({u}'pinfo2 %hist2')"), | |
97 | (u'%%hist3?', "get_ipython().magic({u}'pinfo %%hist3')"), |
|
101 | (u'%%hist3?', "get_ipython().magic({u}'pinfo %%hist3')"), | |
98 | (u'%%hist4??', "get_ipython().magic({u}'pinfo2 %%hist4')"), |
|
102 | (u'%%hist4??', "get_ipython().magic({u}'pinfo2 %%hist4')"), | |
99 | (u'f*?', "get_ipython().magic({u}'psearch f*')"), |
|
103 | (u'f*?', "get_ipython().magic({u}'psearch f*')"), | |
100 | (u'ax.*aspe*?', "get_ipython().magic({u}'psearch ax.*aspe*')"), |
|
104 | (u'ax.*aspe*?', "get_ipython().magic({u}'psearch ax.*aspe*')"), | |
101 | (u'a = abc?', "get_ipython().set_next_input({u}'a = abc');" |
|
105 | (u'a = abc?', "get_ipython().set_next_input({u}'a = abc');" | |
102 | "get_ipython().magic({u}'pinfo abc')"), |
|
106 | "get_ipython().magic({u}'pinfo abc')"), | |
103 | (u'a = abc.qe??', "get_ipython().set_next_input({u}'a = abc.qe');" |
|
107 | (u'a = abc.qe??', "get_ipython().set_next_input({u}'a = abc.qe');" | |
104 | "get_ipython().magic({u}'pinfo2 abc.qe')"), |
|
108 | "get_ipython().magic({u}'pinfo2 abc.qe')"), | |
105 | (u'a = *.items?', "get_ipython().set_next_input({u}'a = *.items');" |
|
109 | (u'a = *.items?', "get_ipython().set_next_input({u}'a = *.items');" | |
106 | "get_ipython().magic({u}'psearch *.items')"), |
|
110 | "get_ipython().magic({u}'psearch *.items')"), | |
107 | (u'plot(a?', "get_ipython().set_next_input({u}'plot(a');" |
|
111 | (u'plot(a?', "get_ipython().set_next_input({u}'plot(a');" | |
108 | "get_ipython().magic({u}'pinfo a')"), |
|
112 | "get_ipython().magic({u}'pinfo a')"), | |
109 | (u'a*2 #comment?', 'a*2 #comment?'), |
|
113 | (u'a*2 #comment?', 'a*2 #comment?'), | |
110 | ]], |
|
114 | ]], | |
111 |
|
115 | |||
112 | # Explicit magic calls |
|
116 | # Explicit magic calls | |
113 | escaped_magic = |
|
117 | escaped_magic = | |
114 | [(i,py3compat.u_format(o)) for i,o in \ |
|
118 | [(i,py3compat.u_format(o)) for i,o in \ | |
115 | [ (u'%cd', "get_ipython().magic({u}'cd')"), |
|
119 | [ (u'%cd', "get_ipython().magic({u}'cd')"), | |
116 | (u'%cd /home', "get_ipython().magic({u}'cd /home')"), |
|
120 | (u'%cd /home', "get_ipython().magic({u}'cd /home')"), | |
117 | # Backslashes need to be escaped. |
|
121 | # Backslashes need to be escaped. | |
118 | (u'%cd C:\\User', "get_ipython().magic({u}'cd C:\\\\User')"), |
|
122 | (u'%cd C:\\User', "get_ipython().magic({u}'cd C:\\\\User')"), | |
119 | (u' %magic', " get_ipython().magic({u}'magic')"), |
|
123 | (u' %magic', " get_ipython().magic({u}'magic')"), | |
120 | ]], |
|
124 | ]], | |
121 |
|
125 | |||
122 | # Quoting with separate arguments |
|
126 | # Quoting with separate arguments | |
123 | escaped_quote = |
|
127 | escaped_quote = | |
124 | [ (',f', 'f("")'), |
|
128 | [ (',f', 'f("")'), | |
125 | (',f x', 'f("x")'), |
|
129 | (',f x', 'f("x")'), | |
126 | (' ,f y', ' f("y")'), |
|
130 | (' ,f y', ' f("y")'), | |
127 | (',f a b', 'f("a", "b")'), |
|
131 | (',f a b', 'f("a", "b")'), | |
128 | ], |
|
132 | ], | |
129 |
|
133 | |||
130 | # Quoting with single argument |
|
134 | # Quoting with single argument | |
131 | escaped_quote2 = |
|
135 | escaped_quote2 = | |
132 | [ (';f', 'f("")'), |
|
136 | [ (';f', 'f("")'), | |
133 | (';f x', 'f("x")'), |
|
137 | (';f x', 'f("x")'), | |
134 | (' ;f y', ' f("y")'), |
|
138 | (' ;f y', ' f("y")'), | |
135 | (';f a b', 'f("a b")'), |
|
139 | (';f a b', 'f("a b")'), | |
136 | ], |
|
140 | ], | |
137 |
|
141 | |||
138 | # Simply apply parens |
|
142 | # Simply apply parens | |
139 | escaped_paren = |
|
143 | escaped_paren = | |
140 | [ ('/f', 'f()'), |
|
144 | [ ('/f', 'f()'), | |
141 | ('/f x', 'f(x)'), |
|
145 | ('/f x', 'f(x)'), | |
142 | (' /f y', ' f(y)'), |
|
146 | (' /f y', ' f(y)'), | |
143 | ('/f a b', 'f(a, b)'), |
|
147 | ('/f a b', 'f(a, b)'), | |
144 | ], |
|
148 | ], | |
145 |
|
149 | |||
146 | # Check that we transform prompts before other transforms |
|
150 | # Check that we transform prompts before other transforms | |
147 | mixed = |
|
151 | mixed = | |
148 | [(i,py3compat.u_format(o)) for i,o in \ |
|
152 | [(i,py3compat.u_format(o)) for i,o in \ | |
149 | [ (u'In [1]: %lsmagic', "get_ipython().magic({u}'lsmagic')"), |
|
153 | [ (u'In [1]: %lsmagic', "get_ipython().magic({u}'lsmagic')"), | |
150 | (u'>>> %lsmagic', "get_ipython().magic({u}'lsmagic')"), |
|
154 | (u'>>> %lsmagic', "get_ipython().magic({u}'lsmagic')"), | |
151 | (u'In [2]: !ls', "get_ipython().system({u}'ls')"), |
|
155 | (u'In [2]: !ls', "get_ipython().system({u}'ls')"), | |
152 | (u'In [3]: abs?', "get_ipython().magic({u}'pinfo abs')"), |
|
156 | (u'In [3]: abs?', "get_ipython().magic({u}'pinfo abs')"), | |
153 | (u'In [4]: b = %who', "b = get_ipython().magic({u}'who')"), |
|
157 | (u'In [4]: b = %who', "b = get_ipython().magic({u}'who')"), | |
154 | ]], |
|
158 | ]], | |
155 | ) |
|
159 | ) | |
156 |
|
160 | |||
157 | # multiline syntax examples. Each of these should be a list of lists, with |
|
161 | # multiline syntax examples. Each of these should be a list of lists, with | |
158 | # each entry itself having pairs of raw/transformed input. The union (with |
|
162 | # each entry itself having pairs of raw/transformed input. The union (with | |
159 | # '\n'.join() of the transformed inputs is what the splitter should produce |
|
163 | # '\n'.join() of the transformed inputs is what the splitter should produce | |
160 | # when fed the raw lines one at a time via push. |
|
164 | # when fed the raw lines one at a time via push. | |
161 | syntax_ml = \ |
|
165 | syntax_ml = \ | |
162 | dict(classic_prompt = |
|
166 | dict(classic_prompt = | |
163 | [ [('>>> for i in range(10):','for i in range(10):'), |
|
167 | [ [('>>> for i in range(10):','for i in range(10):'), | |
164 | ('... print i',' print i'), |
|
168 | ('... print i',' print i'), | |
165 | ('... ', ''), |
|
169 | ('... ', ''), | |
166 | ], |
|
170 | ], | |
167 | [('>>> a="""','a="""'), |
|
171 | [('>>> a="""','a="""'), | |
168 | ('... 123"""','123"""'), |
|
172 | ('... 123"""','123"""'), | |
169 | ], |
|
173 | ], | |
170 | [('a="""','a="""'), |
|
174 | [('a="""','a="""'), | |
171 | ('... 123"""','... 123"""'), |
|
175 | ('... 123"""','... 123"""'), | |
172 | ], |
|
176 | ], | |
173 | ], |
|
177 | ], | |
174 |
|
178 | |||
175 | ipy_prompt = |
|
179 | ipy_prompt = | |
176 | [ [('In [24]: for i in range(10):','for i in range(10):'), |
|
180 | [ [('In [24]: for i in range(10):','for i in range(10):'), | |
177 | (' ....: print i',' print i'), |
|
181 | (' ....: print i',' print i'), | |
178 | (' ....: ', ''), |
|
182 | (' ....: ', ''), | |
179 | ], |
|
183 | ], | |
180 | [('In [2]: a="""','a="""'), |
|
184 | [('In [2]: a="""','a="""'), | |
181 | (' ...: 123"""','123"""'), |
|
185 | (' ...: 123"""','123"""'), | |
182 | ], |
|
186 | ], | |
183 | [('a="""','a="""'), |
|
187 | [('a="""','a="""'), | |
184 | (' ...: 123"""',' ...: 123"""'), |
|
188 | (' ...: 123"""',' ...: 123"""'), | |
185 | ], |
|
189 | ], | |
186 | ], |
|
190 | ], | |
187 |
|
191 | |||
188 | multiline_datastructure = |
|
192 | multiline_datastructure = | |
189 | [ [('>>> a = [1,','a = [1,'), |
|
193 | [ [('>>> a = [1,','a = [1,'), | |
190 | ('... 2]','2]'), |
|
194 | ('... 2]','2]'), | |
191 | ], |
|
195 | ], | |
192 | ], |
|
196 | ], | |
193 |
|
197 | |||
194 | leading_indent = |
|
198 | leading_indent = | |
195 | [ [(' print "hi"','print "hi"'), |
|
199 | [ [(' print "hi"','print "hi"'), | |
196 | ], |
|
200 | ], | |
197 | [(' for a in range(5):','for a in range(5):'), |
|
201 | [(' for a in range(5):','for a in range(5):'), | |
198 | (' a*2',' a*2'), |
|
202 | (' a*2',' a*2'), | |
199 | ], |
|
203 | ], | |
200 | [(' a="""','a="""'), |
|
204 | [(' a="""','a="""'), | |
201 | (' 123"""','123"""'), |
|
205 | (' 123"""','123"""'), | |
202 | ], |
|
206 | ], | |
203 | [('a="""','a="""'), |
|
207 | [('a="""','a="""'), | |
204 | (' 123"""',' 123"""'), |
|
208 | (' 123"""',' 123"""'), | |
205 | ], |
|
209 | ], | |
206 | ], |
|
210 | ], | |
207 |
|
211 | |||
208 | cellmagic = |
|
212 | cellmagic = | |
209 | [ [(u'%%foo a', None), |
|
213 | [ [(u'%%foo a', None), | |
210 | (None, u_fmt("get_ipython().run_cell_magic({u}'foo', {u}'a', {u}'')")), |
|
214 | (None, u_fmt("get_ipython().run_cell_magic({u}'foo', {u}'a', {u}'')")), | |
211 | ], |
|
215 | ], | |
212 | [(u'%%bar 123', None), |
|
216 | [(u'%%bar 123', None), | |
213 | (u'hello', None), |
|
217 | (u'hello', None), | |
214 | (u'', u_fmt("get_ipython().run_cell_magic({u}'bar', {u}'123', {u}'hello')")), |
|
218 | (u'', u_fmt("get_ipython().run_cell_magic({u}'bar', {u}'123', {u}'hello')")), | |
215 | ], |
|
219 | ], | |
216 | ], |
|
220 | ], | |
217 |
|
221 | |||
218 | escaped = |
|
222 | escaped = | |
219 | [ [('%abc def \\', None), |
|
223 | [ [('%abc def \\', None), | |
220 | ('ghi', u_fmt("get_ipython().magic({u}'abc def ghi')")), |
|
224 | ('ghi', u_fmt("get_ipython().magic({u}'abc def ghi')")), | |
221 | ], |
|
225 | ], | |
222 | [('%abc def \\', None), |
|
226 | [('%abc def \\', None), | |
223 | ('ghi\\', None), |
|
227 | ('ghi\\', None), | |
224 | (None, u_fmt("get_ipython().magic({u}'abc def ghi')")), |
|
228 | (None, u_fmt("get_ipython().magic({u}'abc def ghi')")), | |
225 | ], |
|
229 | ], | |
226 | ], |
|
230 | ], | |
227 |
|
231 | |||
228 | assign_magic = |
|
232 | assign_magic = | |
229 | [ [(u'a = %bc de \\', None), |
|
233 | [ [(u'a = %bc de \\', None), | |
230 | (u'fg', u_fmt("a = get_ipython().magic({u}'bc de fg')")), |
|
234 | (u'fg', u_fmt("a = get_ipython().magic({u}'bc de fg')")), | |
231 | ], |
|
235 | ], | |
232 | [(u'a = %bc de \\', None), |
|
236 | [(u'a = %bc de \\', None), | |
233 | (u'fg\\', None), |
|
237 | (u'fg\\', None), | |
234 | (None, u_fmt("a = get_ipython().magic({u}'bc de fg')")), |
|
238 | (None, u_fmt("a = get_ipython().magic({u}'bc de fg')")), | |
235 | ], |
|
239 | ], | |
236 | ], |
|
240 | ], | |
237 |
|
241 | |||
238 | assign_system = |
|
242 | assign_system = | |
239 | [ [(u'a = !bc de \\', None), |
|
243 | [ [(u'a = !bc de \\', None), | |
240 | (u'fg', u_fmt("a = get_ipython().getoutput({u}'bc de fg')")), |
|
244 | (u'fg', u_fmt("a = get_ipython().getoutput({u}'bc de fg')")), | |
241 | ], |
|
245 | ], | |
242 | [(u'a = !bc de \\', None), |
|
246 | [(u'a = !bc de \\', None), | |
243 | (u'fg\\', None), |
|
247 | (u'fg\\', None), | |
244 | (None, u_fmt("a = get_ipython().getoutput({u}'bc de fg')")), |
|
248 | (None, u_fmt("a = get_ipython().getoutput({u}'bc de fg')")), | |
245 | ], |
|
249 | ], | |
246 | ], |
|
250 | ], | |
247 | ) |
|
251 | ) | |
248 |
|
252 | |||
249 |
|
253 | |||
250 | def test_assign_system(): |
|
254 | def test_assign_system(): | |
251 | tt.check_pairs(transform_and_reset(ipt.assign_from_system), syntax['assign_system']) |
|
255 | tt.check_pairs(transform_and_reset(ipt.assign_from_system), syntax['assign_system']) | |
252 | for example in syntax_ml['assign_system']: |
|
256 | for example in syntax_ml['assign_system']: | |
253 | transform_checker(example, ipt.assign_from_system) |
|
257 | transform_checker(example, ipt.assign_from_system) | |
254 |
|
258 | |||
255 | def test_assign_magic(): |
|
259 | def test_assign_magic(): | |
256 | tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic']) |
|
260 | tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic']) | |
257 | for example in syntax_ml['assign_magic']: |
|
261 | for example in syntax_ml['assign_magic']: | |
258 | transform_checker(example, ipt.assign_from_magic) |
|
262 | transform_checker(example, ipt.assign_from_magic) | |
259 |
|
263 | |||
260 |
|
264 | |||
261 | def test_classic_prompt(): |
|
265 | def test_classic_prompt(): | |
262 | tt.check_pairs(transform_and_reset(ipt.classic_prompt), syntax['classic_prompt']) |
|
266 | tt.check_pairs(transform_and_reset(ipt.classic_prompt), syntax['classic_prompt']) | |
263 | for example in syntax_ml['classic_prompt']: |
|
267 | for example in syntax_ml['classic_prompt']: | |
264 | transform_checker(example, ipt.classic_prompt) |
|
268 | transform_checker(example, ipt.classic_prompt) | |
265 | for example in syntax_ml['multiline_datastructure']: |
|
269 | for example in syntax_ml['multiline_datastructure']: | |
266 | transform_checker(example, ipt.classic_prompt) |
|
270 | transform_checker(example, ipt.classic_prompt) | |
267 |
|
271 | |||
268 |
|
272 | |||
269 | def test_ipy_prompt(): |
|
273 | def test_ipy_prompt(): | |
270 | tt.check_pairs(transform_and_reset(ipt.ipy_prompt), syntax['ipy_prompt']) |
|
274 | tt.check_pairs(transform_and_reset(ipt.ipy_prompt), syntax['ipy_prompt']) | |
271 | for example in syntax_ml['ipy_prompt']: |
|
275 | for example in syntax_ml['ipy_prompt']: | |
272 | transform_checker(example, ipt.ipy_prompt) |
|
276 | transform_checker(example, ipt.ipy_prompt) | |
273 |
|
277 | |||
274 | def test_help_end(): |
|
278 | def test_help_end(): | |
275 | tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help']) |
|
279 | tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help']) | |
276 |
|
280 | |||
277 | def test_escaped_noesc(): |
|
281 | def test_escaped_noesc(): | |
278 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_noesc']) |
|
282 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_noesc']) | |
279 |
|
283 | |||
280 |
|
284 | |||
281 | def test_escaped_shell(): |
|
285 | def test_escaped_shell(): | |
282 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_shell']) |
|
286 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_shell']) | |
283 |
|
287 | |||
284 |
|
288 | |||
285 | def test_escaped_help(): |
|
289 | def test_escaped_help(): | |
286 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_help']) |
|
290 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_help']) | |
287 |
|
291 | |||
288 |
|
292 | |||
289 | def test_escaped_magic(): |
|
293 | def test_escaped_magic(): | |
290 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_magic']) |
|
294 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_magic']) | |
291 |
|
295 | |||
292 |
|
296 | |||
293 | def test_escaped_quote(): |
|
297 | def test_escaped_quote(): | |
294 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_quote']) |
|
298 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_quote']) | |
295 |
|
299 | |||
296 |
|
300 | |||
297 | def test_escaped_quote2(): |
|
301 | def test_escaped_quote2(): | |
298 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_quote2']) |
|
302 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_quote2']) | |
299 |
|
303 | |||
300 |
|
304 | |||
301 | def test_escaped_paren(): |
|
305 | def test_escaped_paren(): | |
302 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_paren']) |
|
306 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_paren']) | |
303 |
|
307 | |||
304 | def test_escaped_multiline(): |
|
308 | def test_escaped_multiline(): | |
305 | for example in syntax_ml['escaped']: |
|
309 | for example in syntax_ml['escaped']: | |
306 | transform_checker(example, ipt.escaped_transformer) |
|
310 | transform_checker(example, ipt.escaped_transformer) | |
307 |
|
311 | |||
308 | def test_cellmagic(): |
|
312 | def test_cellmagic(): | |
309 | for example in syntax_ml['cellmagic']: |
|
313 | for example in syntax_ml['cellmagic']: | |
310 | transform_checker(example, ipt.cellmagic) |
|
314 | transform_checker(example, ipt.cellmagic) | |
311 |
|
315 | |||
312 | def test_has_comment(): |
|
316 | def test_has_comment(): | |
313 | tests = [('text', False), |
|
317 | tests = [('text', False), | |
314 | ('text #comment', True), |
|
318 | ('text #comment', True), | |
315 | ('text #comment\n', True), |
|
319 | ('text #comment\n', True), | |
316 | ('#comment', True), |
|
320 | ('#comment', True), | |
317 | ('#comment\n', True), |
|
321 | ('#comment\n', True), | |
318 | ('a = "#string"', False), |
|
322 | ('a = "#string"', False), | |
319 | ('a = "#string" # comment', True), |
|
323 | ('a = "#string" # comment', True), | |
320 | ('a #comment not "string"', True), |
|
324 | ('a #comment not "string"', True), | |
321 | ] |
|
325 | ] | |
322 | tt.check_pairs(ipt.has_comment, tests) |
|
326 | tt.check_pairs(ipt.has_comment, tests) |
General Comments 0
You need to be logged in to leave comments.
Login now