##// END OF EJS Templates
Add some inputtransformer test cases
Matthias Bussonnier -
Show More
@@ -5,6 +5,7 b' more complex. See test_inputtransformer2_line for tests for line-based'
5 transformations.
5 transformations.
6 """
6 """
7 import nose.tools as nt
7 import nose.tools as nt
8 import string
8
9
9 from IPython.core import inputtransformer2 as ipt2
10 from IPython.core import inputtransformer2 as ipt2
10 from IPython.core.inputtransformer2 import make_tokens_by_line
11 from IPython.core.inputtransformer2 import make_tokens_by_line
@@ -100,6 +101,16 b' b) = zip?'
100 [r"get_ipython().set_next_input('(a,\nb) = zip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
101 [r"get_ipython().set_next_input('(a,\nb) = zip');get_ipython().run_line_magic('pinfo', 'zip')" + "\n"]
101 )
102 )
102
103
104 def check_make_token_by_line_never_ends_empty():
105 """
106 Check that not sequence of single or double characters ends up leading to en empty list of tokens
107 """
108 from string import printable
109 for c in printable:
110 nt.assert_not_equal(make_tokens_by_line(c)[-1], [])
111 for k in printable:
112 nt.assert_not_equal(make_tokens_by_line(c+k)[-1], [])
113
103 def check_find(transformer, case, match=True):
114 def check_find(transformer, case, match=True):
104 sample, expected_start, _ = case
115 sample, expected_start, _ = case
105 tbl = make_tokens_by_line(sample)
116 tbl = make_tokens_by_line(sample)
@@ -190,6 +201,17 b' def test_check_complete():'
190 nt.assert_equal(cc("for a in range(5):"), ('incomplete', 4))
201 nt.assert_equal(cc("for a in range(5):"), ('incomplete', 4))
191 nt.assert_equal(cc("raise = 2"), ('invalid', None))
202 nt.assert_equal(cc("raise = 2"), ('invalid', None))
192 nt.assert_equal(cc("a = [1,\n2,"), ('incomplete', 0))
203 nt.assert_equal(cc("a = [1,\n2,"), ('incomplete', 0))
204 nt.assert_equal(cc(")"), ('incomplete', 0))
205 nt.assert_equal(cc("\\\r\n"), ('incomplete', 0))
193 nt.assert_equal(cc("a = '''\n hi"), ('incomplete', 3))
206 nt.assert_equal(cc("a = '''\n hi"), ('incomplete', 3))
194 nt.assert_equal(cc("def a():\n x=1\n global x"), ('invalid', None))
207 nt.assert_equal(cc("def a():\n x=1\n global x"), ('invalid', None))
195 nt.assert_equal(cc("a \\ "), ('invalid', None)) # Nothing allowed after backslash
208 nt.assert_equal(cc("a \\ "), ('invalid', None)) # Nothing allowed after backslash
209
210 # no need to loop on all the letters/numbers.
211 short = '12abAB'+string.printable[62:]
212 for c in short:
213 # test does not raise:
214 cc(c)
215 for k in short:
216 cc(c+k)
217
General Comments 0
You need to be logged in to leave comments. Login now