##// END OF EJS Templates
Remove all usage of u_format (no op), and remove function...
Matthias Bussonnier -
Show More
@@ -3,7 +3,6 b' 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
7
6
8 from IPython.core import inputtransformer as ipt
7 from IPython.core import inputtransformer as ipt
9
8
@@ -38,7 +37,6 b' def transform_checker(tests, transformer, **kwargs):'
38
37
39 syntax = \
38 syntax = \
40 dict(assign_system =
39 dict(assign_system =
41 [(i,py3compat.u_format(o)) for i,o in \
42 [(u'a =! ls', "a = get_ipython().getoutput('ls')"),
40 [(u'a =! ls', "a = get_ipython().getoutput('ls')"),
43 (u'b = !ls', "b = get_ipython().getoutput('ls')"),
41 (u'b = !ls', "b = get_ipython().getoutput('ls')"),
44 (u'c= !ls', "c = get_ipython().getoutput('ls')"),
42 (u'c= !ls', "c = get_ipython().getoutput('ls')"),
@@ -53,10 +51,9 b' syntax = \\'
53 (u"a, b = range(2)", u"a, b = range(2)"),
51 (u"a, b = range(2)", u"a, b = range(2)"),
54 (u"a, = range(1)", u"a, = range(1)"),
52 (u"a, = range(1)", u"a, = range(1)"),
55 (u"a, *bc = range(3)", u"a, *bc = range(3)"),
53 (u"a, *bc = range(3)", u"a, *bc = range(3)"),
56 ]],
54 ],
57
55
58 assign_magic =
56 assign_magic =
59 [(i,py3compat.u_format(o)) for i,o in \
60 [(u'a =% who', "a = get_ipython().run_line_magic('who', '')"),
57 [(u'a =% who', "a = get_ipython().run_line_magic('who', '')"),
61 (u'b = %who', "b = get_ipython().run_line_magic('who', '')"),
58 (u'b = %who', "b = get_ipython().run_line_magic('who', '')"),
62 (u'c= %ls', "c = get_ipython().run_line_magic('ls', '')"),
59 (u'c= %ls', "c = get_ipython().run_line_magic('ls', '')"),
@@ -64,7 +61,7 b' syntax = \\'
64 ('x=1', 'x=1'), # normal input is unmodified
61 ('x=1', 'x=1'), # normal input is unmodified
65 (' ',' '), # blank lines are kept intact
62 (' ',' '), # blank lines are kept intact
66 (u"a, b = %foo", u"a, b = get_ipython().run_line_magic('foo', '')"),
63 (u"a, b = %foo", u"a, b = get_ipython().run_line_magic('foo', '')"),
67 ]],
64 ],
68
65
69 classic_prompt =
66 classic_prompt =
70 [('>>> x=1', 'x=1'),
67 [('>>> x=1', 'x=1'),
@@ -86,16 +83,14 b' syntax = \\'
86
83
87 # System calls
84 # System calls
88 escaped_shell =
85 escaped_shell =
89 [(i,py3compat.u_format(o)) for i,o in \
90 [ (u'!ls', "get_ipython().system('ls')"),
86 [ (u'!ls', "get_ipython().system('ls')"),
91 # Double-escape shell, this means to capture the output of the
87 # Double-escape shell, this means to capture the output of the
92 # subprocess and return it
88 # subprocess and return it
93 (u'!!ls', "get_ipython().getoutput('ls')"),
89 (u'!!ls', "get_ipython().getoutput('ls')"),
94 ]],
90 ],
95
91
96 # Help/object info
92 # Help/object info
97 escaped_help =
93 escaped_help =
98 [(i,py3compat.u_format(o)) for i,o in \
99 [ (u'?', 'get_ipython().show_usage()'),
94 [ (u'?', 'get_ipython().show_usage()'),
100 (u'?x1', "get_ipython().run_line_magic('pinfo', 'x1')"),
95 (u'?x1', "get_ipython().run_line_magic('pinfo', 'x1')"),
101 (u'??x2', "get_ipython().run_line_magic('pinfo2', 'x2')"),
96 (u'??x2', "get_ipython().run_line_magic('pinfo2', 'x2')"),
@@ -103,10 +98,9 b' syntax = \\'
103 (u'?%hist1', "get_ipython().run_line_magic('pinfo', '%hist1')"),
98 (u'?%hist1', "get_ipython().run_line_magic('pinfo', '%hist1')"),
104 (u'?%%hist2', "get_ipython().run_line_magic('pinfo', '%%hist2')"),
99 (u'?%%hist2', "get_ipython().run_line_magic('pinfo', '%%hist2')"),
105 (u'?abc = qwe', "get_ipython().run_line_magic('pinfo', 'abc')"),
100 (u'?abc = qwe', "get_ipython().run_line_magic('pinfo', 'abc')"),
106 ]],
101 ],
107
102
108 end_help =
103 end_help =
109 [(i,py3compat.u_format(o)) for i,o in \
110 [ (u'x3?', "get_ipython().run_line_magic('pinfo', 'x3')"),
104 [ (u'x3?', "get_ipython().run_line_magic('pinfo', 'x3')"),
111 (u'x4??', "get_ipython().run_line_magic('pinfo2', 'x4')"),
105 (u'x4??', "get_ipython().run_line_magic('pinfo2', 'x4')"),
112 (u'%hist1?', "get_ipython().run_line_magic('pinfo', '%hist1')"),
106 (u'%hist1?', "get_ipython().run_line_magic('pinfo', '%hist1')"),
@@ -125,17 +119,16 b' syntax = \\'
125 (u'plot(a?', "get_ipython().set_next_input('plot(a');"
119 (u'plot(a?', "get_ipython().set_next_input('plot(a');"
126 "get_ipython().run_line_magic('pinfo', 'a')"),
120 "get_ipython().run_line_magic('pinfo', 'a')"),
127 (u'a*2 #comment?', 'a*2 #comment?'),
121 (u'a*2 #comment?', 'a*2 #comment?'),
128 ]],
122 ],
129
123
130 # Explicit magic calls
124 # Explicit magic calls
131 escaped_magic =
125 escaped_magic =
132 [(i,py3compat.u_format(o)) for i,o in \
133 [ (u'%cd', "get_ipython().run_line_magic('cd', '')"),
126 [ (u'%cd', "get_ipython().run_line_magic('cd', '')"),
134 (u'%cd /home', "get_ipython().run_line_magic('cd', '/home')"),
127 (u'%cd /home', "get_ipython().run_line_magic('cd', '/home')"),
135 # Backslashes need to be escaped.
128 # Backslashes need to be escaped.
136 (u'%cd C:\\User', "get_ipython().run_line_magic('cd', 'C:\\\\User')"),
129 (u'%cd C:\\User', "get_ipython().run_line_magic('cd', 'C:\\\\User')"),
137 (u' %magic', " get_ipython().run_line_magic('magic', '')"),
130 (u' %magic', " get_ipython().run_line_magic('magic', '')"),
138 ]],
131 ],
139
132
140 # Quoting with separate arguments
133 # Quoting with separate arguments
141 escaped_quote =
134 escaped_quote =
@@ -163,13 +156,12 b' syntax = \\'
163
156
164 # Check that we transform prompts before other transforms
157 # Check that we transform prompts before other transforms
165 mixed =
158 mixed =
166 [(i,py3compat.u_format(o)) for i,o in \
167 [ (u'In [1]: %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
159 [ (u'In [1]: %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
168 (u'>>> %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
160 (u'>>> %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
169 (u'In [2]: !ls', "get_ipython().system('ls')"),
161 (u'In [2]: !ls', "get_ipython().system('ls')"),
170 (u'In [3]: abs?', "get_ipython().run_line_magic('pinfo', 'abs')"),
162 (u'In [3]: abs?', "get_ipython().run_line_magic('pinfo', 'abs')"),
171 (u'In [4]: b = %who', "b = get_ipython().run_line_magic('who', '')"),
163 (u'In [4]: b = %who', "b = get_ipython().run_line_magic('who', '')"),
172 ]],
164 ],
173 )
165 )
174
166
175 # multiline syntax examples. Each of these should be a list of lists, with
167 # multiline syntax examples. Each of these should be a list of lists, with
@@ -284,11 +276,11 b' syntax_ml = \\'
284
276
285 cellmagic =
277 cellmagic =
286 [ [(u'%%foo a', None),
278 [ [(u'%%foo a', None),
287 (None, u_fmt("get_ipython().run_cell_magic('foo', 'a', '')")),
279 (None, "get_ipython().run_cell_magic('foo', 'a', '')"),
288 ],
280 ],
289 [(u'%%bar 123', None),
281 [(u'%%bar 123', None),
290 (u'hello', None),
282 (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')"),
292 ],
284 ],
293 [(u'a=5', 'a=5'),
285 [(u'a=5', 'a=5'),
294 (u'%%cellmagic', '%%cellmagic'),
286 (u'%%cellmagic', '%%cellmagic'),
@@ -297,31 +289,31 b' syntax_ml = \\'
297
289
298 escaped =
290 escaped =
299 [ [('%abc def \\', None),
291 [ [('%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')"),
301 ],
293 ],
302 [('%abc def \\', None),
294 [('%abc def \\', None),
303 ('ghi\\', None),
295 ('ghi\\', None),
304 (None, u_fmt("get_ipython().run_line_magic('abc', 'def ghi')")),
296 (None, "get_ipython().run_line_magic('abc', 'def ghi')"),
305 ],
297 ],
306 ],
298 ],
307
299
308 assign_magic =
300 assign_magic =
309 [ [(u'a = %bc de \\', None),
301 [ [(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')"),
311 ],
303 ],
312 [(u'a = %bc de \\', None),
304 [(u'a = %bc de \\', None),
313 (u'fg\\', None),
305 (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')"),
315 ],
307 ],
316 ],
308 ],
317
309
318 assign_system =
310 assign_system =
319 [ [(u'a = !bc de \\', None),
311 [ [(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')"),
321 ],
313 ],
322 [(u'a = !bc de \\', None),
314 [(u'a = !bc de \\', None),
323 (u'fg\\', None),
315 (u'fg\\', None),
324 (None, u_fmt("a = get_ipython().getoutput('bc de fg')")),
316 (None, "a = get_ipython().getoutput('bc de fg')"),
325 ],
317 ],
326 ],
318 ],
327 )
319 )
@@ -437,7 +429,7 b' def test_cellmagic():'
437
429
438 line_example = [(u'%%bar 123', None),
430 line_example = [(u'%%bar 123', None),
439 (u'hello', None),
431 (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')"),
441 ]
433 ]
442 transform_checker(line_example, ipt.cellmagic, end_on_blank_line=True)
434 transform_checker(line_example, ipt.cellmagic, end_on_blank_line=True)
443
435
@@ -475,16 +467,16 b' def decistmt(tokens):'
475
467
476
468
477 def test_token_input_transformer():
469 def test_token_input_transformer():
478 tests = [(u'1.2', u_fmt(u"Decimal ('1.2')")),
470 tests = [(u'1.2', u"Decimal ('1.2')"),
479 (u'"1.2"', u'"1.2"'),
471 (u'"1.2"', u'"1.2"'),
480 ]
472 ]
481 tt.check_pairs(transform_and_reset(decistmt), tests)
473 tt.check_pairs(transform_and_reset(decistmt), tests)
482 ml_tests = \
474 ml_tests = \
483 [ [(u"a = 1.2; b = '''x", None),
475 [ [(u"a = 1.2; b = '''x", None),
484 (u"y'''", u_fmt(u"a =Decimal ('1.2');b ='''x\ny'''")),
476 (u"y'''", u"a =Decimal ('1.2');b ='''x\ny'''"),
485 ],
477 ],
486 [(u"a = [1.2,", None),
478 [(u"a = [1.2,", None),
487 (u"3]", u_fmt(u"a =[Decimal ('1.2'),\n3 ]")),
479 (u"3]", u"a =[Decimal ('1.2'),\n3 ]"),
488 ],
480 ],
489 [(u"a = '''foo", None), # Test resetting when within a multi-line string
481 [(u"a = '''foo", None), # Test resetting when within a multi-line string
490 (u"bar", None),
482 (u"bar", None),
@@ -39,26 +39,6 b' def buffer_to_bytes(buf):'
39 buf = bytes(buf)
39 buf = bytes(buf)
40 return buf
40 return buf
41
41
42 def _modify_str_or_docstring(str_change_func):
43 @functools.wraps(str_change_func)
44 def wrapper(func_or_str):
45 if isinstance(func_or_str, (str,)):
46 func = None
47 doc = func_or_str
48 else:
49 func = func_or_str
50 doc = func.__doc__
51
52 # PYTHONOPTIMIZE=2 strips docstrings, so they can disappear unexpectedly
53 if doc is not None:
54 doc = str_change_func(doc)
55
56 if func:
57 func.__doc__ = doc
58 return func
59 return doc
60 return wrapper
61
62 def safe_unicode(e):
42 def safe_unicode(e):
63 """unicode(e) with various fallbacks. Used for exceptions, which may not be
43 """unicode(e) with various fallbacks. Used for exceptions, which may not be
64 safe to call unicode() on.
44 safe to call unicode() on.
@@ -167,18 +147,6 b' def execfile(fname, glob, loc=None, compiler=None):'
167 compiler = compiler or compile
147 compiler = compiler or compile
168 exec(compiler(f.read(), fname, 'exec'), glob, loc)
148 exec(compiler(f.read(), fname, 'exec'), glob, loc)
169
149
170 # Refactor print statements in doctests.
171 _print_statement_re = re.compile(r"\bprint (?P<expr>.*)$", re.MULTILINE)
172
173 # Abstract u'abc' syntax:
174 @_modify_str_or_docstring
175 def u_format(s):
176 """"{u}'abc'" --> "'abc'" (Python 3)
177
178 Accepts a string or a function, so it can be used as a decorator."""
179 return s.format(u='')
180
181
182 PY2 = not PY3
150 PY2 = not PY3
183 PYPY = platform.python_implementation() == "PyPy"
151 PYPY = platform.python_implementation() == "PyPy"
184
152
General Comments 0
You need to be logged in to leave comments. Login now