##// END OF EJS Templates
[core][tests][inputtransformer2] Remove nose
Samuel Gaist -
Show More
@@ -1,355 +1,359 b''
1 """Tests for the token-based transformers in IPython.core.inputtransformer2
1 """Tests for the token-based transformers in IPython.core.inputtransformer2
2
2
3 Line-based transformers are the simpler ones; token-based transformers are
3 Line-based transformers are the simpler ones; token-based transformers are
4 more complex. See test_inputtransformer2_line for tests for line-based
4 more complex. See test_inputtransformer2_line for tests for line-based
5 transformations.
5 transformations.
6 """
6 """
7 import nose.tools as nt
8 import string
7 import string
9
8
10 from IPython.core import inputtransformer2 as ipt2
9 from IPython.core import inputtransformer2 as ipt2
11 from IPython.core.inputtransformer2 import make_tokens_by_line, _find_assign_op
10 from IPython.core.inputtransformer2 import make_tokens_by_line, _find_assign_op
12
11
13 from textwrap import dedent
12 from textwrap import dedent
14
13
15 MULTILINE_MAGIC = ("""\
14 MULTILINE_MAGIC = ("""\
16 a = f()
15 a = f()
17 %foo \\
16 %foo \\
18 bar
17 bar
19 g()
18 g()
20 """.splitlines(keepends=True), (2, 0), """\
19 """.splitlines(keepends=True), (2, 0), """\
21 a = f()
20 a = f()
22 get_ipython().run_line_magic('foo', ' bar')
21 get_ipython().run_line_magic('foo', ' bar')
23 g()
22 g()
24 """.splitlines(keepends=True))
23 """.splitlines(keepends=True))
25
24
26 INDENTED_MAGIC = ("""\
25 INDENTED_MAGIC = ("""\
27 for a in range(5):
26 for a in range(5):
28 %ls
27 %ls
29 """.splitlines(keepends=True), (2, 4), """\
28 """.splitlines(keepends=True), (2, 4), """\
30 for a in range(5):
29 for a in range(5):
31 get_ipython().run_line_magic('ls', '')
30 get_ipython().run_line_magic('ls', '')
32 """.splitlines(keepends=True))
31 """.splitlines(keepends=True))
33
32
34 CRLF_MAGIC = ([
33 CRLF_MAGIC = ([
35 "a = f()\n",
34 "a = f()\n",
36 "%ls\r\n",
35 "%ls\r\n",
37 "g()\n"
36 "g()\n"
38 ], (2, 0), [
37 ], (2, 0), [
39 "a = f()\n",
38 "a = f()\n",
40 "get_ipython().run_line_magic('ls', '')\n",
39 "get_ipython().run_line_magic('ls', '')\n",
41 "g()\n"
40 "g()\n"
42 ])
41 ])
43
42
44 MULTILINE_MAGIC_ASSIGN = ("""\
43 MULTILINE_MAGIC_ASSIGN = ("""\
45 a = f()
44 a = f()
46 b = %foo \\
45 b = %foo \\
47 bar
46 bar
48 g()
47 g()
49 """.splitlines(keepends=True), (2, 4), """\
48 """.splitlines(keepends=True), (2, 4), """\
50 a = f()
49 a = f()
51 b = get_ipython().run_line_magic('foo', ' bar')
50 b = get_ipython().run_line_magic('foo', ' bar')
52 g()
51 g()
53 """.splitlines(keepends=True))
52 """.splitlines(keepends=True))
54
53
55 MULTILINE_SYSTEM_ASSIGN = ("""\
54 MULTILINE_SYSTEM_ASSIGN = ("""\
56 a = f()
55 a = f()
57 b = !foo \\
56 b = !foo \\
58 bar
57 bar
59 g()
58 g()
60 """.splitlines(keepends=True), (2, 4), """\
59 """.splitlines(keepends=True), (2, 4), """\
61 a = f()
60 a = f()
62 b = get_ipython().getoutput('foo bar')
61 b = get_ipython().getoutput('foo bar')
63 g()
62 g()
64 """.splitlines(keepends=True))
63 """.splitlines(keepends=True))
65
64
66 #####
65 #####
67
66
68 MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT = ("""\
67 MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT = ("""\
69 def test():
68 def test():
70 for i in range(1):
69 for i in range(1):
71 print(i)
70 print(i)
72 res =! ls
71 res =! ls
73 """.splitlines(keepends=True), (4, 7), '''\
72 """.splitlines(keepends=True), (4, 7), '''\
74 def test():
73 def test():
75 for i in range(1):
74 for i in range(1):
76 print(i)
75 print(i)
77 res =get_ipython().getoutput(\' ls\')
76 res =get_ipython().getoutput(\' ls\')
78 '''.splitlines(keepends=True))
77 '''.splitlines(keepends=True))
79
78
80 ######
79 ######
81
80
82 AUTOCALL_QUOTE = (
81 AUTOCALL_QUOTE = (
83 [",f 1 2 3\n"], (1, 0),
82 [",f 1 2 3\n"], (1, 0),
84 ['f("1", "2", "3")\n']
83 ['f("1", "2", "3")\n']
85 )
84 )
86
85
87 AUTOCALL_QUOTE2 = (
86 AUTOCALL_QUOTE2 = (
88 [";f 1 2 3\n"], (1, 0),
87 [";f 1 2 3\n"], (1, 0),
89 ['f("1 2 3")\n']
88 ['f("1 2 3")\n']
90 )
89 )
91
90
92 AUTOCALL_PAREN = (
91 AUTOCALL_PAREN = (
93 ["/f 1 2 3\n"], (1, 0),
92 ["/f 1 2 3\n"], (1, 0),
94 ['f(1, 2, 3)\n']
93 ['f(1, 2, 3)\n']
95 )
94 )
96
95
97 SIMPLE_HELP = (
96 SIMPLE_HELP = (
98 ["foo?\n"], (1, 0),
97 ["foo?\n"], (1, 0),
99 ["get_ipython().run_line_magic('pinfo', 'foo')\n"]
98 ["get_ipython().run_line_magic('pinfo', 'foo')\n"]
100 )
99 )
101
100
102 DETAILED_HELP = (
101 DETAILED_HELP = (
103 ["foo??\n"], (1, 0),
102 ["foo??\n"], (1, 0),
104 ["get_ipython().run_line_magic('pinfo2', 'foo')\n"]
103 ["get_ipython().run_line_magic('pinfo2', 'foo')\n"]
105 )
104 )
106
105
107 MAGIC_HELP = (
106 MAGIC_HELP = (
108 ["%foo?\n"], (1, 0),
107 ["%foo?\n"], (1, 0),
109 ["get_ipython().run_line_magic('pinfo', '%foo')\n"]
108 ["get_ipython().run_line_magic('pinfo', '%foo')\n"]
110 )
109 )
111
110
112 HELP_IN_EXPR = (
111 HELP_IN_EXPR = (
113 ["a = b + c?\n"], (1, 0),
112 ["a = b + c?\n"], (1, 0),
114 ["get_ipython().set_next_input('a = b + c');"
113 ["get_ipython().set_next_input('a = b + c');"
115 "get_ipython().run_line_magic('pinfo', 'c')\n"]
114 "get_ipython().run_line_magic('pinfo', 'c')\n"]
116 )
115 )
117
116
118 HELP_CONTINUED_LINE = ("""\
117 HELP_CONTINUED_LINE = ("""\
119 a = \\
118 a = \\
120 zip?
119 zip?
121 """.splitlines(keepends=True), (1, 0),
120 """.splitlines(keepends=True), (1, 0),
122 [r"get_ipython().set_next_input('a = \\\nzip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
121 [r"get_ipython().set_next_input('a = \\\nzip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
123 )
122 )
124
123
125 HELP_MULTILINE = ("""\
124 HELP_MULTILINE = ("""\
126 (a,
125 (a,
127 b) = zip?
126 b) = zip?
128 """.splitlines(keepends=True), (1, 0),
127 """.splitlines(keepends=True), (1, 0),
129 [r"get_ipython().set_next_input('(a,\nb) = zip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
128 [r"get_ipython().set_next_input('(a,\nb) = zip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
130 )
129 )
131
130
132 HELP_UNICODE = (
131 HELP_UNICODE = (
133 ["Ο€.foo?\n"], (1, 0),
132 ["Ο€.foo?\n"], (1, 0),
134 ["get_ipython().run_line_magic('pinfo', 'Ο€.foo')\n"]
133 ["get_ipython().run_line_magic('pinfo', 'Ο€.foo')\n"]
135 )
134 )
136
135
137
136
138 def null_cleanup_transformer(lines):
137 def null_cleanup_transformer(lines):
139 """
138 """
140 A cleanup transform that returns an empty list.
139 A cleanup transform that returns an empty list.
141 """
140 """
142 return []
141 return []
143
142
144 def check_make_token_by_line_never_ends_empty():
143 def check_make_token_by_line_never_ends_empty():
145 """
144 """
146 Check that not sequence of single or double characters ends up leading to en empty list of tokens
145 Check that not sequence of single or double characters ends up leading to en empty list of tokens
147 """
146 """
148 from string import printable
147 from string import printable
149 for c in printable:
148 for c in printable:
150 nt.assert_not_equal(make_tokens_by_line(c)[-1], [])
149 assert make_tokens_by_line(c)[-1] != []
151 for k in printable:
150 for k in printable:
152 nt.assert_not_equal(make_tokens_by_line(c+k)[-1], [])
151 assert make_tokens_by_line(c + k)[-1] != []
152
153
153
154 def check_find(transformer, case, match=True):
154 def check_find(transformer, case, match=True):
155 sample, expected_start, _ = case
155 sample, expected_start, _ = case
156 tbl = make_tokens_by_line(sample)
156 tbl = make_tokens_by_line(sample)
157 res = transformer.find(tbl)
157 res = transformer.find(tbl)
158 if match:
158 if match:
159 # start_line is stored 0-indexed, expected values are 1-indexed
159 # start_line is stored 0-indexed, expected values are 1-indexed
160 nt.assert_equal((res.start_line+1, res.start_col), expected_start)
160 assert (res.start_line + 1, res.start_col) == expected_start
161 return res
161 return res
162 else:
162 else:
163 nt.assert_is(res, None)
163 assert res is None
164
164
165 def check_transform(transformer_cls, case):
165 def check_transform(transformer_cls, case):
166 lines, start, expected = case
166 lines, start, expected = case
167 transformer = transformer_cls(start)
167 transformer = transformer_cls(start)
168 nt.assert_equal(transformer.transform(lines), expected)
168 assert transformer.transform(lines) == expected
169
169
170 def test_continued_line():
170 def test_continued_line():
171 lines = MULTILINE_MAGIC_ASSIGN[0]
171 lines = MULTILINE_MAGIC_ASSIGN[0]
172 nt.assert_equal(ipt2.find_end_of_continued_line(lines, 1), 2)
172 assert ipt2.find_end_of_continued_line(lines, 1) == 2
173
173
174 nt.assert_equal(ipt2.assemble_continued_line(lines, (1, 5), 2), "foo bar")
174 assert ipt2.assemble_continued_line(lines, (1, 5), 2) == "foo bar"
175
175
176 def test_find_assign_magic():
176 def test_find_assign_magic():
177 check_find(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
177 check_find(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
178 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN, match=False)
178 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN, match=False)
179 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT, match=False)
179 check_find(ipt2.MagicAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT, match=False)
180
180
181 def test_transform_assign_magic():
181 def test_transform_assign_magic():
182 check_transform(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
182 check_transform(ipt2.MagicAssign, MULTILINE_MAGIC_ASSIGN)
183
183
184 def test_find_assign_system():
184 def test_find_assign_system():
185 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
185 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
186 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
186 check_find(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
187 check_find(ipt2.SystemAssign, (["a = !ls\n"], (1, 5), None))
187 check_find(ipt2.SystemAssign, (["a = !ls\n"], (1, 5), None))
188 check_find(ipt2.SystemAssign, (["a=!ls\n"], (1, 2), None))
188 check_find(ipt2.SystemAssign, (["a=!ls\n"], (1, 2), None))
189 check_find(ipt2.SystemAssign, MULTILINE_MAGIC_ASSIGN, match=False)
189 check_find(ipt2.SystemAssign, MULTILINE_MAGIC_ASSIGN, match=False)
190
190
191 def test_transform_assign_system():
191 def test_transform_assign_system():
192 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
192 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN)
193 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
193 check_transform(ipt2.SystemAssign, MULTILINE_SYSTEM_ASSIGN_AFTER_DEDENT)
194
194
195 def test_find_magic_escape():
195 def test_find_magic_escape():
196 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC)
196 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC)
197 check_find(ipt2.EscapedCommand, INDENTED_MAGIC)
197 check_find(ipt2.EscapedCommand, INDENTED_MAGIC)
198 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC_ASSIGN, match=False)
198 check_find(ipt2.EscapedCommand, MULTILINE_MAGIC_ASSIGN, match=False)
199
199
200 def test_transform_magic_escape():
200 def test_transform_magic_escape():
201 check_transform(ipt2.EscapedCommand, MULTILINE_MAGIC)
201 check_transform(ipt2.EscapedCommand, MULTILINE_MAGIC)
202 check_transform(ipt2.EscapedCommand, INDENTED_MAGIC)
202 check_transform(ipt2.EscapedCommand, INDENTED_MAGIC)
203 check_transform(ipt2.EscapedCommand, CRLF_MAGIC)
203 check_transform(ipt2.EscapedCommand, CRLF_MAGIC)
204
204
205 def test_find_autocalls():
205 def test_find_autocalls():
206 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
206 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
207 print("Testing %r" % case[0])
207 print("Testing %r" % case[0])
208 check_find(ipt2.EscapedCommand, case)
208 check_find(ipt2.EscapedCommand, case)
209
209
210 def test_transform_autocall():
210 def test_transform_autocall():
211 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
211 for case in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
212 print("Testing %r" % case[0])
212 print("Testing %r" % case[0])
213 check_transform(ipt2.EscapedCommand, case)
213 check_transform(ipt2.EscapedCommand, case)
214
214
215 def test_find_help():
215 def test_find_help():
216 for case in [SIMPLE_HELP, DETAILED_HELP, MAGIC_HELP, HELP_IN_EXPR]:
216 for case in [SIMPLE_HELP, DETAILED_HELP, MAGIC_HELP, HELP_IN_EXPR]:
217 check_find(ipt2.HelpEnd, case)
217 check_find(ipt2.HelpEnd, case)
218
218
219 tf = check_find(ipt2.HelpEnd, HELP_CONTINUED_LINE)
219 tf = check_find(ipt2.HelpEnd, HELP_CONTINUED_LINE)
220 nt.assert_equal(tf.q_line, 1)
220 assert tf.q_line == 1
221 nt.assert_equal(tf.q_col, 3)
221 assert tf.q_col == 3
222
222
223 tf = check_find(ipt2.HelpEnd, HELP_MULTILINE)
223 tf = check_find(ipt2.HelpEnd, HELP_MULTILINE)
224 nt.assert_equal(tf.q_line, 1)
224 assert tf.q_line == 1
225 nt.assert_equal(tf.q_col, 8)
225 assert tf.q_col == 8
226
226
227 # ? in a comment does not trigger help
227 # ? in a comment does not trigger help
228 check_find(ipt2.HelpEnd, (["foo # bar?\n"], None, None), match=False)
228 check_find(ipt2.HelpEnd, (["foo # bar?\n"], None, None), match=False)
229 # Nor in a string
229 # Nor in a string
230 check_find(ipt2.HelpEnd, (["foo = '''bar?\n"], None, None), match=False)
230 check_find(ipt2.HelpEnd, (["foo = '''bar?\n"], None, None), match=False)
231
231
232 def test_transform_help():
232 def test_transform_help():
233 tf = ipt2.HelpEnd((1, 0), (1, 9))
233 tf = ipt2.HelpEnd((1, 0), (1, 9))
234 nt.assert_equal(tf.transform(HELP_IN_EXPR[0]), HELP_IN_EXPR[2])
234 assert tf.transform(HELP_IN_EXPR[0]) == HELP_IN_EXPR[2]
235
235
236 tf = ipt2.HelpEnd((1, 0), (2, 3))
236 tf = ipt2.HelpEnd((1, 0), (2, 3))
237 nt.assert_equal(tf.transform(HELP_CONTINUED_LINE[0]), HELP_CONTINUED_LINE[2])
237 assert tf.transform(HELP_CONTINUED_LINE[0]) == HELP_CONTINUED_LINE[2]
238
238
239 tf = ipt2.HelpEnd((1, 0), (2, 8))
239 tf = ipt2.HelpEnd((1, 0), (2, 8))
240 nt.assert_equal(tf.transform(HELP_MULTILINE[0]), HELP_MULTILINE[2])
240 assert tf.transform(HELP_MULTILINE[0]) == HELP_MULTILINE[2]
241
241
242 tf = ipt2.HelpEnd((1, 0), (1, 0))
242 tf = ipt2.HelpEnd((1, 0), (1, 0))
243 nt.assert_equal(tf.transform(HELP_UNICODE[0]), HELP_UNICODE[2])
243 assert tf.transform(HELP_UNICODE[0]) == HELP_UNICODE[2]
244
244
245 def test_find_assign_op_dedent():
245 def test_find_assign_op_dedent():
246 """
246 """
247 be careful that empty token like dedent are not counted as parens
247 be careful that empty token like dedent are not counted as parens
248 """
248 """
249 class Tk:
249 class Tk:
250 def __init__(self, s):
250 def __init__(self, s):
251 self.string = s
251 self.string = s
252
252
253 nt.assert_equal(_find_assign_op([Tk(s) for s in ('','a','=','b')]), 2)
253 assert _find_assign_op([Tk(s) for s in ("", "a", "=", "b")]) == 2
254 nt.assert_equal(_find_assign_op([Tk(s) for s in ('','(', 'a','=','b', ')', '=' ,'5')]), 6)
254 assert (
255 _find_assign_op([Tk(s) for s in ("", "(", "a", "=", "b", ")", "=", "5")]) == 6
256 )
257
255
258
256 def test_check_complete():
259 def test_check_complete():
257 cc = ipt2.TransformerManager().check_complete
260 cc = ipt2.TransformerManager().check_complete
258 nt.assert_equal(cc("a = 1"), ("complete", None))
261 assert cc("a = 1") == ("complete", None)
259 nt.assert_equal(cc("for a in range(5):"), ("incomplete", 4))
262 assert cc("for a in range(5):") == ("incomplete", 4)
260 nt.assert_equal(cc("for a in range(5):\n if a > 0:"), ("incomplete", 8))
263 assert cc("for a in range(5):\n if a > 0:") == ("incomplete", 8)
261 nt.assert_equal(cc("raise = 2"), ("invalid", None))
264 assert cc("raise = 2") == ("invalid", None)
262 nt.assert_equal(cc("a = [1,\n2,"), ("incomplete", 0))
265 assert cc("a = [1,\n2,") == ("incomplete", 0)
263 nt.assert_equal(cc("(\n))"), ("incomplete", 0))
266 assert cc("(\n))") == ("incomplete", 0)
264 nt.assert_equal(cc("\\\r\n"), ("incomplete", 0))
267 assert cc("\\\r\n") == ("incomplete", 0)
265 nt.assert_equal(cc("a = '''\n hi"), ("incomplete", 3))
268 assert cc("a = '''\n hi") == ("incomplete", 3)
266 nt.assert_equal(cc("def a():\n x=1\n global x"), ("invalid", None))
269 assert cc("def a():\n x=1\n global x") == ("invalid", None)
267 nt.assert_equal(cc("a \\ "), ("invalid", None)) # Nothing allowed after backslash
270 assert cc("a \\ ") == ("invalid", None) # Nothing allowed after backslash
268 nt.assert_equal(cc("1\\\n+2"), ("complete", None))
271 assert cc("1\\\n+2") == ("complete", None)
269 nt.assert_equal(cc("exit"), ("complete", None))
272 assert cc("exit") == ("complete", None)
270
273
271 example = dedent("""
274 example = dedent("""
272 if True:
275 if True:
273 a=1""" )
276 a=1""" )
274
277
275 nt.assert_equal(cc(example), ('incomplete', 4))
278 assert cc(example) == ("incomplete", 4)
276 nt.assert_equal(cc(example+'\n'), ('complete', None))
279 assert cc(example + "\n") == ("complete", None)
277 nt.assert_equal(cc(example+'\n '), ('complete', None))
280 assert cc(example + "\n ") == ("complete", None)
278
281
279 # no need to loop on all the letters/numbers.
282 # no need to loop on all the letters/numbers.
280 short = '12abAB'+string.printable[62:]
283 short = '12abAB'+string.printable[62:]
281 for c in short:
284 for c in short:
282 # test does not raise:
285 # test does not raise:
283 cc(c)
286 cc(c)
284 for k in short:
287 for k in short:
285 cc(c+k)
288 cc(c+k)
286
289
287 nt.assert_equal(cc("def f():\n x=0\n \\\n "), ('incomplete', 2))
290 assert cc("def f():\n x=0\n \\\n ") == ("incomplete", 2)
291
288
292
289 def test_check_complete_II():
293 def test_check_complete_II():
290 """
294 """
291 Test that multiple line strings are properly handled.
295 Test that multiple line strings are properly handled.
292
296
293 Separate test function for convenience
297 Separate test function for convenience
294
298
295 """
299 """
296 cc = ipt2.TransformerManager().check_complete
300 cc = ipt2.TransformerManager().check_complete
297 nt.assert_equal(cc('''def foo():\n """'''), ('incomplete', 4))
301 assert cc('''def foo():\n """''') == ("incomplete", 4)
298
302
299
303
300 def test_check_complete_invalidates_sunken_brackets():
304 def test_check_complete_invalidates_sunken_brackets():
301 """
305 """
302 Test that a single line with more closing brackets than the opening ones is
306 Test that a single line with more closing brackets than the opening ones is
303 interpreted as invalid
307 interpreted as invalid
304 """
308 """
305 cc = ipt2.TransformerManager().check_complete
309 cc = ipt2.TransformerManager().check_complete
306 nt.assert_equal(cc(")"), ("invalid", None))
310 assert cc(")") == ("invalid", None)
307 nt.assert_equal(cc("]"), ("invalid", None))
311 assert cc("]") == ("invalid", None)
308 nt.assert_equal(cc("}"), ("invalid", None))
312 assert cc("}") == ("invalid", None)
309 nt.assert_equal(cc(")("), ("invalid", None))
313 assert cc(")(") == ("invalid", None)
310 nt.assert_equal(cc("]["), ("invalid", None))
314 assert cc("][") == ("invalid", None)
311 nt.assert_equal(cc("}{"), ("invalid", None))
315 assert cc("}{") == ("invalid", None)
312 nt.assert_equal(cc("]()("), ("invalid", None))
316 assert cc("]()(") == ("invalid", None)
313 nt.assert_equal(cc("())("), ("invalid", None))
317 assert cc("())(") == ("invalid", None)
314 nt.assert_equal(cc(")[]("), ("invalid", None))
318 assert cc(")[](") == ("invalid", None)
315 nt.assert_equal(cc("()]("), ("invalid", None))
319 assert cc("()](") == ("invalid", None)
316
320
317
321
318 def test_null_cleanup_transformer():
322 def test_null_cleanup_transformer():
319 manager = ipt2.TransformerManager()
323 manager = ipt2.TransformerManager()
320 manager.cleanup_transforms.insert(0, null_cleanup_transformer)
324 manager.cleanup_transforms.insert(0, null_cleanup_transformer)
321 assert manager.transform_cell("") == ""
325 assert manager.transform_cell("") == ""
322
326
323
327
324
328
325
329
326 def test_side_effects_I():
330 def test_side_effects_I():
327 count = 0
331 count = 0
328 def counter(lines):
332 def counter(lines):
329 nonlocal count
333 nonlocal count
330 count += 1
334 count += 1
331 return lines
335 return lines
332
336
333 counter.has_side_effects = True
337 counter.has_side_effects = True
334
338
335 manager = ipt2.TransformerManager()
339 manager = ipt2.TransformerManager()
336 manager.cleanup_transforms.insert(0, counter)
340 manager.cleanup_transforms.insert(0, counter)
337 assert manager.check_complete("a=1\n") == ('complete', None)
341 assert manager.check_complete("a=1\n") == ('complete', None)
338 assert count == 0
342 assert count == 0
339
343
340
344
341
345
342
346
343 def test_side_effects_II():
347 def test_side_effects_II():
344 count = 0
348 count = 0
345 def counter(lines):
349 def counter(lines):
346 nonlocal count
350 nonlocal count
347 count += 1
351 count += 1
348 return lines
352 return lines
349
353
350 counter.has_side_effects = True
354 counter.has_side_effects = True
351
355
352 manager = ipt2.TransformerManager()
356 manager = ipt2.TransformerManager()
353 manager.line_transforms.insert(0, counter)
357 manager.line_transforms.insert(0, counter)
354 assert manager.check_complete("b=1\n") == ('complete', None)
358 assert manager.check_complete("b=1\n") == ('complete', None)
355 assert count == 0
359 assert count == 0
General Comments 0
You need to be logged in to leave comments. Login now