##// END OF EJS Templates
[core][tests][inputtransformer2] Remove nose
Samuel Gaist -
Show More
@@ -4,7 +4,6 b' 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
@@ -147,9 +146,10 b' def check_make_token_by_line_never_ends_empty():'
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
@@ -157,21 +157,21 b' def check_find(transformer, case, match=True):'
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)
@@ -217,12 +217,12 b' def test_find_help():'
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)
@@ -231,16 +231,16 b' def test_find_help():'
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 """
@@ -250,31 +250,34 b' def test_find_assign_op_dedent():'
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:]
@@ -284,7 +287,8 b' def test_check_complete():'
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 """
@@ -294,7 +298,7 b' def test_check_complete_II():'
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():
@@ -303,16 +307,16 b' def test_check_complete_invalidates_sunken_brackets():'
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():
General Comments 0
You need to be logged in to leave comments. Login now