33
44from IPython .testing import tools as tt
55from IPython .utils import py3compat
6- u_fmt = py3compat .u_format
76
87from IPython .core import inputtransformer as ipt
98
@@ -38,7 +37,6 @@ def transform_checker(tests, transformer, **kwargs):
3837
3938syntax = \
4039 dict (assign_system =
41- [(i ,py3compat .u_format (o )) for i ,o in \
4240 [(u'a =! ls' , "a = get_ipython().getoutput('ls')" ),
4341 (u'b = !ls' , "b = get_ipython().getoutput('ls')" ),
4442 (u'c= !ls' , "c = get_ipython().getoutput('ls')" ),
@@ -53,18 +51,17 @@ def transform_checker(tests, transformer, **kwargs):
5351 (u"a, b = range(2)" , u"a, b = range(2)" ),
5452 (u"a, = range(1)" , u"a, = range(1)" ),
5553 (u"a, *bc = range(3)" , u"a, *bc = range(3)" ),
56- ]] ,
54+ ],
5755
5856 assign_magic =
59- [(i ,py3compat .u_format (o )) for i ,o in \
6057 [(u'a =% who' , "a = get_ipython().run_line_magic('who', '')" ),
6158 (u'b = %who' , "b = get_ipython().run_line_magic('who', '')" ),
6259 (u'c= %ls' , "c = get_ipython().run_line_magic('ls', '')" ),
6360 (u'd == %ls' , u'd == %ls' ), # Invalid syntax, but we leave == alone.
6461 ('x=1' , 'x=1' ), # normal input is unmodified
6562 (' ' ,' ' ), # blank lines are kept intact
6663 (u"a, b = %foo" , u"a, b = get_ipython().run_line_magic('foo', '')" ),
67- ]] ,
64+ ],
6865
6966 classic_prompt =
7067 [('>>> x=1' , 'x=1' ),
@@ -86,27 +83,24 @@ def transform_checker(tests, transformer, **kwargs):
8683
8784 # System calls
8885 escaped_shell =
89- [(i ,py3compat .u_format (o )) for i ,o in \
9086 [ (u'!ls' , "get_ipython().system('ls')" ),
9187 # Double-escape shell, this means to capture the output of the
9288 # subprocess and return it
9389 (u'!!ls' , "get_ipython().getoutput('ls')" ),
94- ]] ,
90+ ],
9591
9692 # Help/object info
9793 escaped_help =
98- [(i ,py3compat .u_format (o )) for i ,o in \
9994 [ (u'?' , 'get_ipython().show_usage()' ),
10095 (u'?x1' , "get_ipython().run_line_magic('pinfo', 'x1')" ),
10196 (u'??x2' , "get_ipython().run_line_magic('pinfo2', 'x2')" ),
10297 (u'?a.*s' , "get_ipython().run_line_magic('psearch', 'a.*s')" ),
10398 (u'?%hist1' , "get_ipython().run_line_magic('pinfo', '%hist1')" ),
10499 (u'?%%hist2' , "get_ipython().run_line_magic('pinfo', '%%hist2')" ),
105100 (u'?abc = qwe' , "get_ipython().run_line_magic('pinfo', 'abc')" ),
106- ]] ,
101+ ],
107102
108103 end_help =
109- [(i ,py3compat .u_format (o )) for i ,o in \
110104 [ (u'x3?' , "get_ipython().run_line_magic('pinfo', 'x3')" ),
111105 (u'x4??' , "get_ipython().run_line_magic('pinfo2', 'x4')" ),
112106 (u'%hist1?' , "get_ipython().run_line_magic('pinfo', '%hist1')" ),
@@ -125,17 +119,16 @@ def transform_checker(tests, transformer, **kwargs):
125119 (u'plot(a?' , "get_ipython().set_next_input('plot(a');"
126120 "get_ipython().run_line_magic('pinfo', 'a')" ),
127121 (u'a*2 #comment?' , 'a*2 #comment?' ),
128- ]] ,
122+ ],
129123
130124 # Explicit magic calls
131125 escaped_magic =
132- [(i ,py3compat .u_format (o )) for i ,o in \
133126 [ (u'%cd' , "get_ipython().run_line_magic('cd', '')" ),
134127 (u'%cd /home' , "get_ipython().run_line_magic('cd', '/home')" ),
135128 # Backslashes need to be escaped.
136129 (u'%cd C:\\ User' , "get_ipython().run_line_magic('cd', 'C:\\ \\ User')" ),
137130 (u' %magic' , " get_ipython().run_line_magic('magic', '')" ),
138- ]] ,
131+ ],
139132
140133 # Quoting with separate arguments
141134 escaped_quote =
@@ -163,13 +156,12 @@ def transform_checker(tests, transformer, **kwargs):
163156
164157 # Check that we transform prompts before other transforms
165158 mixed =
166- [(i ,py3compat .u_format (o )) for i ,o in \
167159 [ (u'In [1]: %lsmagic' , "get_ipython().run_line_magic('lsmagic', '')" ),
168160 (u'>>> %lsmagic' , "get_ipython().run_line_magic('lsmagic', '')" ),
169161 (u'In [2]: !ls' , "get_ipython().system('ls')" ),
170162 (u'In [3]: abs?' , "get_ipython().run_line_magic('pinfo', 'abs')" ),
171163 (u'In [4]: b = %who' , "b = get_ipython().run_line_magic('who', '')" ),
172- ]] ,
164+ ],
173165 )
174166
175167# multiline syntax examples. Each of these should be a list of lists, with
@@ -284,11 +276,11 @@ def transform_checker(tests, transformer, **kwargs):
284276
285277 cellmagic =
286278 [ [(u'%%foo a' , None ),
287- (None , u_fmt ( "get_ipython().run_cell_magic('foo', 'a', '')" ) ),
279+ (None , "get_ipython().run_cell_magic('foo', 'a', '')" ),
288280 ],
289281 [(u'%%bar 123' , None ),
290282 (u'hello' , None ),
291- (None , u_fmt ( "get_ipython().run_cell_magic('bar', '123', 'hello')" ) ),
283+ (None , "get_ipython().run_cell_magic('bar', '123', 'hello')" ),
292284 ],
293285 [(u'a=5' , 'a=5' ),
294286 (u'%%cellmagic' , '%%cellmagic' ),
@@ -297,31 +289,31 @@ def transform_checker(tests, transformer, **kwargs):
297289
298290 escaped =
299291 [ [('%abc def \\ ' , None ),
300- ('ghi' , u_fmt ( "get_ipython().run_line_magic('abc', 'def ghi')" ) ),
292+ ('ghi' , "get_ipython().run_line_magic('abc', 'def ghi')" ),
301293 ],
302294 [('%abc def \\ ' , None ),
303295 ('ghi\\ ' , None ),
304- (None , u_fmt ( "get_ipython().run_line_magic('abc', 'def ghi')" ) ),
296+ (None , "get_ipython().run_line_magic('abc', 'def ghi')" ),
305297 ],
306298 ],
307299
308300 assign_magic =
309301 [ [(u'a = %bc de \\ ' , None ),
310- (u'fg' , u_fmt ( "a = get_ipython().run_line_magic('bc', 'de fg')" ) ),
302+ (u'fg' , "a = get_ipython().run_line_magic('bc', 'de fg')" ),
311303 ],
312304 [(u'a = %bc de \\ ' , None ),
313305 (u'fg\\ ' , None ),
314- (None , u_fmt ( "a = get_ipython().run_line_magic('bc', 'de fg')" ) ),
306+ (None , "a = get_ipython().run_line_magic('bc', 'de fg')" ),
315307 ],
316308 ],
317309
318310 assign_system =
319311 [ [(u'a = !bc de \\ ' , None ),
320- (u'fg' , u_fmt ( "a = get_ipython().getoutput('bc de fg')" ) ),
312+ (u'fg' , "a = get_ipython().getoutput('bc de fg')" ),
321313 ],
322314 [(u'a = !bc de \\ ' , None ),
323315 (u'fg\\ ' , None ),
324- (None , u_fmt ( "a = get_ipython().getoutput('bc de fg')" ) ),
316+ (None , "a = get_ipython().getoutput('bc de fg')" ),
325317 ],
326318 ],
327319 )
@@ -437,7 +429,7 @@ def test_cellmagic():
437429
438430 line_example = [(u'%%bar 123' , None ),
439431 (u'hello' , None ),
440- (u'' , u_fmt ( "get_ipython().run_cell_magic('bar', '123', 'hello')" ) ),
432+ (u'' , "get_ipython().run_cell_magic('bar', '123', 'hello')" ),
441433 ]
442434 transform_checker (line_example , ipt .cellmagic , end_on_blank_line = True )
443435
@@ -475,16 +467,16 @@ def decistmt(tokens):
475467
476468
477469def test_token_input_transformer ():
478- tests = [(u'1.2' , u_fmt ( u"Decimal ('1.2')" ) ),
470+ tests = [(u'1.2' , u"Decimal ('1.2')" ),
479471 (u'"1.2"' , u'"1.2"' ),
480472 ]
481473 tt .check_pairs (transform_and_reset (decistmt ), tests )
482474 ml_tests = \
483475 [ [(u"a = 1.2; b = '''x" , None ),
484- (u"y'''" , u_fmt ( u"a =Decimal ('1.2');b ='''x\n y'''" ) ),
476+ (u"y'''" , u"a =Decimal ('1.2');b ='''x\n y'''" ),
485477 ],
486478 [(u"a = [1.2," , None ),
487- (u"3]" , u_fmt ( u"a =[Decimal ('1.2'),\n 3 ]" ) ),
479+ (u"3]" , u"a =[Decimal ('1.2'),\n 3 ]" ),
488480 ],
489481 [(u"a = '''foo" , None ), # Test resetting when within a multi-line string
490482 (u"bar" , None ),
0 commit comments