##// END OF EJS Templates
Add Python 3.10 CI runners
Add Python 3.10 CI runners

File last commit:

r26899:3bf77e7c
r27062:39ea7f36
Show More
test_inputtransformer.py
484 lines | 15.8 KiB | text/x-python | PythonLexer
/ IPython / core / tests / test_inputtransformer.py
Thomas Kluyver
Add TokenInputTransformer
r10103 import tokenize
Thomas Kluyver
First go at new input transformation system
r10090
from IPython.testing import tools as tt
Thomas Kluyver
Move and combine transformer tests
r10095 from IPython.core import inputtransformer as ipt
Thomas Kluyver
First go at new input transformation system
r10090
Thomas Kluyver
Move and combine transformer tests
r10095 def transform_and_reset(transformer):
Thomas Kluyver
Fix tests in IPython.core
r10097 transformer = transformer()
Thomas Kluyver
First go at new input transformation system
r10090 def transform(inp):
Thomas Kluyver
Move and combine transformer tests
r10095 try:
return transformer.push(inp)
finally:
transformer.reset()
Thomas Kluyver
First go at new input transformation system
r10090
return transform
Thomas Kluyver
Move and combine transformer tests
r10095 # Transformer tests
Thomas Kluyver
Allow IPythonInputSplitter to accept cell magics containing blank lines
r10252 def transform_checker(tests, transformer, **kwargs):
Thomas Kluyver
Move and combine transformer tests
r10095 """Utility to loop over test inputs"""
Thomas Kluyver
Allow IPythonInputSplitter to accept cell magics containing blank lines
r10252 transformer = transformer(**kwargs)
Thomas Kluyver
Move and combine transformer tests
r10095 try:
for inp, tr in tests:
Thomas Kluyver
Correction to test framework.
r10098 if inp is None:
out = transformer.reset()
else:
out = transformer.push(inp)
Samuel Gaist
[core][tests][inputtransformer] Remove nose
r26899 assert out == tr
Thomas Kluyver
Move and combine transformer tests
r10095 finally:
transformer.reset()
# Data for all the syntax tests in the form of lists of pairs of
# raw/transformed input. We store it here as a global dict so that we can use
# it both within single-function tests and also to validate the behavior of the
# larger objects
syntax = \
dict(assign_system =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [('a =! ls', "a = get_ipython().getoutput('ls')"),
('b = !ls', "b = get_ipython().getoutput('ls')"),
('c= !ls', "c = get_ipython().getoutput('ls')"),
('d == !ls', 'd == !ls'), # Invalid syntax, but we leave == alone.
Thomas Kluyver
Move and combine transformer tests
r10095 ('x=1', 'x=1'), # normal input is unmodified
(' ',' '), # blank lines are kept intact
Thomas Kluyver
Add failing tests for tuple unpacking assignments from system cmds
r15785 # Tuple unpacking
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ("a, b = !echo 'a\\nb'", "a, b = get_ipython().getoutput(\"echo 'a\\\\nb'\")"),
("a,= !echo 'a'", "a, = get_ipython().getoutput(\"echo 'a'\")"),
("a, *bc = !echo 'a\\nb\\nc'", "a, *bc = get_ipython().getoutput(\"echo 'a\\\\nb\\\\nc'\")"),
Thomas Kluyver
Add some tests for assignment from system/magic commands
r15789 # Tuple unpacking with regular Python expressions, not our syntax.
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ("a, b = range(2)", "a, b = range(2)"),
("a, = range(1)", "a, = range(1)"),
("a, *bc = range(3)", "a, *bc = range(3)"),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ],
Thomas Kluyver
Move and combine transformer tests
r10095
assign_magic =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [('a =% who', "a = get_ipython().run_line_magic('who', '')"),
('b = %who', "b = get_ipython().run_line_magic('who', '')"),
('c= %ls', "c = get_ipython().run_line_magic('ls', '')"),
('d == %ls', 'd == %ls'), # Invalid syntax, but we leave == alone.
Thomas Kluyver
Move and combine transformer tests
r10095 ('x=1', 'x=1'), # normal input is unmodified
(' ',' '), # blank lines are kept intact
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ("a, b = %foo", "a, b = get_ipython().run_line_magic('foo', '')"),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ],
Thomas Kluyver
Move and combine transformer tests
r10095
classic_prompt =
[('>>> x=1', 'x=1'),
('x=1', 'x=1'), # normal input is unmodified
(' ', ' '), # blank lines are kept intact
],
ipy_prompt =
[('In [1]: x=1', 'x=1'),
('x=1', 'x=1'), # normal input is unmodified
(' ',' '), # blank lines are kept intact
],
# Tests for the escape transformer to leave normal code alone
escaped_noesc =
[ (' ', ' '),
('x=1', 'x=1'),
],
# System calls
escaped_shell =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ ('!ls', "get_ipython().system('ls')"),
Thomas Kluyver
Move and combine transformer tests
r10095 # Double-escape shell, this means to capture the output of the
# subprocess and return it
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('!!ls', "get_ipython().getoutput('ls')"),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ],
Thomas Kluyver
Move and combine transformer tests
r10095
# Help/object info
escaped_help =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ ('?', 'get_ipython().show_usage()'),
('?x1', "get_ipython().run_line_magic('pinfo', 'x1')"),
('??x2', "get_ipython().run_line_magic('pinfo2', 'x2')"),
('?a.*s', "get_ipython().run_line_magic('psearch', 'a.*s')"),
('?%hist1', "get_ipython().run_line_magic('pinfo', '%hist1')"),
('?%%hist2', "get_ipython().run_line_magic('pinfo', '%%hist2')"),
('?abc = qwe', "get_ipython().run_line_magic('pinfo', 'abc')"),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ],
Thomas Kluyver
Move and combine transformer tests
r10095
end_help =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ ('x3?', "get_ipython().run_line_magic('pinfo', 'x3')"),
('x4??', "get_ipython().run_line_magic('pinfo2', 'x4')"),
('%hist1?', "get_ipython().run_line_magic('pinfo', '%hist1')"),
('%hist2??', "get_ipython().run_line_magic('pinfo2', '%hist2')"),
('%%hist3?', "get_ipython().run_line_magic('pinfo', '%%hist3')"),
('%%hist4??', "get_ipython().run_line_magic('pinfo2', '%%hist4')"),
('Ï€.foo?', "get_ipython().run_line_magic('pinfo', 'Ï€.foo')"),
('f*?', "get_ipython().run_line_magic('psearch', 'f*')"),
('ax.*aspe*?', "get_ipython().run_line_magic('psearch', 'ax.*aspe*')"),
('a = abc?', "get_ipython().set_next_input('a = abc');"
adityausathe
fix for #10327: _stack_depth added and {u} string literals removed from core/tests
r23764 "get_ipython().run_line_magic('pinfo', 'abc')"),
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('a = abc.qe??', "get_ipython().set_next_input('a = abc.qe');"
adityausathe
fix for #10327: _stack_depth added and {u} string literals removed from core/tests
r23764 "get_ipython().run_line_magic('pinfo2', 'abc.qe')"),
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('a = *.items?', "get_ipython().set_next_input('a = *.items');"
adityausathe
fix for #10327: _stack_depth added and {u} string literals removed from core/tests
r23764 "get_ipython().run_line_magic('psearch', '*.items')"),
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('plot(a?', "get_ipython().set_next_input('plot(a');"
adityausathe
fix for #10327: _stack_depth added and {u} string literals removed from core/tests
r23764 "get_ipython().run_line_magic('pinfo', 'a')"),
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('a*2 #comment?', 'a*2 #comment?'),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ],
Thomas Kluyver
Move and combine transformer tests
r10095
# Explicit magic calls
escaped_magic =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ ('%cd', "get_ipython().run_line_magic('cd', '')"),
('%cd /home', "get_ipython().run_line_magic('cd', '/home')"),
Thomas Kluyver
Move and combine transformer tests
r10095 # Backslashes need to be escaped.
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('%cd C:\\User', "get_ipython().run_line_magic('cd', 'C:\\\\User')"),
(' %magic', " get_ipython().run_line_magic('magic', '')"),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ],
Thomas Kluyver
Move and combine transformer tests
r10095
# Quoting with separate arguments
escaped_quote =
[ (',f', 'f("")'),
(',f x', 'f("x")'),
(' ,f y', ' f("y")'),
(',f a b', 'f("a", "b")'),
],
# Quoting with single argument
escaped_quote2 =
[ (';f', 'f("")'),
(';f x', 'f("x")'),
(' ;f y', ' f("y")'),
(';f a b', 'f("a b")'),
],
# Simply apply parens
escaped_paren =
[ ('/f', 'f()'),
('/f x', 'f(x)'),
(' /f y', ' f(y)'),
('/f a b', 'f(a, b)'),
],
# Check that we transform prompts before other transforms
mixed =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ ('In [1]: %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
('>>> %lsmagic', "get_ipython().run_line_magic('lsmagic', '')"),
('In [2]: !ls', "get_ipython().system('ls')"),
('In [3]: abs?', "get_ipython().run_line_magic('pinfo', 'abs')"),
('In [4]: b = %who', "b = get_ipython().run_line_magic('who', '')"),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ],
Thomas Kluyver
Move and combine transformer tests
r10095 )
Thomas Kluyver
First go at new input transformation system
r10090
Thomas Kluyver
Move and combine transformer tests
r10095 # multiline syntax examples. Each of these should be a list of lists, with
# each entry itself having pairs of raw/transformed input. The union (with
# '\n'.join() of the transformed inputs is what the splitter should produce
# when fed the raw lines one at a time via push.
syntax_ml = \
dict(classic_prompt =
[ [('>>> for i in range(10):','for i in range(10):'),
('... print i',' print i'),
('... ', ''),
],
[('>>> a="""','a="""'),
('... 123"""','123"""'),
],
[('a="""','a="""'),
MinRK
adjust strip_prompts logic a bit further...
r12309 ('... 123','123'),
('... 456"""','456"""'),
],
[('a="""','a="""'),
('>>> 123','123'),
('... 456"""','456"""'),
Thomas Kluyver
Strip prompts even if the prompt isn't present on the first line....
r10652 ],
[('a="""','a="""'),
('123','123'),
('... 456"""','... 456"""'),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
MinRK
only strip continuation prompts if regular prompts seen first...
r12231 [('....__class__','....__class__'),
],
[('a=5', 'a=5'),
MinRK
adjust strip_prompts logic a bit further...
r12309 ('...', ''),
MinRK
only strip continuation prompts if regular prompts seen first...
r12231 ],
Thomas Kluyver
Allow classic prompts without space....
r11056 [('>>> def f(x):', 'def f(x):'),
('...', ''),
('... return x', ' return x'),
],
Thomas Kluyver
Add failing test for gh-6025
r17037 [('board = """....', 'board = """....'),
('....', '....'),
('...."""', '...."""'),
],
Thomas Kluyver
Move and combine transformer tests
r10095 ],
Thomas Kluyver
First go at new input transformation system
r10090
Thomas Kluyver
Move and combine transformer tests
r10095 ipy_prompt =
[ [('In [24]: for i in range(10):','for i in range(10):'),
(' ....: print i',' print i'),
(' ....: ', ''),
],
Thomas Kluyver
Add failing test for issue gh-4728
r13934 [('In [24]: for i in range(10):','for i in range(10):'),
# Qt console prompts expand with spaces, not dots
(' ...: print i',' print i'),
(' ...: ', ''),
],
Pascal Bugnion
Fix input transformer bug when pasting ipython promts....
r19036 [('In [24]: for i in range(10):','for i in range(10):'),
Pascal Bugnion
Fixed error in comments of test for inputtransformer....
r19038 # Sometimes whitespace preceding '...' has been removed
Pascal Bugnion
Fix input transformer bug when pasting ipython promts....
r19036 ('...: print i',' print i'),
('...: ', ''),
],
Pascal Bugnion
Fixed whitespace bug when pasting IPython continuation prompt....
r19037 [('In [24]: for i in range(10):','for i in range(10):'),
# Space after last continuation prompt has been removed (issue #6674)
('...: print i',' print i'),
('...:', ''),
],
Thomas Kluyver
Move and combine transformer tests
r10095 [('In [2]: a="""','a="""'),
(' ...: 123"""','123"""'),
],
[('a="""','a="""'),
MinRK
adjust strip_prompts logic a bit further...
r12309 (' ...: 123','123'),
(' ...: 456"""','456"""'),
],
[('a="""','a="""'),
('In [1]: 123','123'),
(' ...: 456"""','456"""'),
Thomas Kluyver
Strip prompts even if the prompt isn't present on the first line....
r10652 ],
[('a="""','a="""'),
('123','123'),
(' ...: 456"""',' ...: 456"""'),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
],
Thomas Kluyver
First go at new input transformation system
r10090
Thomas Kluyver
Fix for \ at end of comment, and add tests
r10112 multiline_datastructure_prompt =
Thomas Kluyver
Move and combine transformer tests
r10095 [ [('>>> a = [1,','a = [1,'),
('... 2]','2]'),
],
],
Thomas Kluyver
Fix for \ at end of comment, and add tests
r10112
multiline_datastructure =
[ [('b = ("%s"', None),
('# comment', None),
('%foo )', 'b = ("%s"\n# comment\n%foo )'),
],
],
Thomas Kluyver
Move and combine transformer tests
r10095
Thomas Kluyver
help_end transformer shouldn't pick up ? in multiline string...
r12352 multiline_string =
[ [("'''foo?", None),
("bar'''", "'''foo?\nbar'''"),
],
],
Thomas Kluyver
Move and combine transformer tests
r10095 leading_indent =
[ [(' print "hi"','print "hi"'),
Thomas Kluyver
Fix tests in IPython.core
r10097 ],
[(' for a in range(5):','for a in range(5):'),
Thomas Kluyver
Move and combine transformer tests
r10095 (' a*2',' a*2'),
],
[(' a="""','a="""'),
(' 123"""','123"""'),
],
[('a="""','a="""'),
(' 123"""',' 123"""'),
],
],
cellmagic =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ [('%%foo a', None),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 (None, "get_ipython().run_cell_magic('foo', 'a', '')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [('%%bar 123', None),
('hello', None),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 (None , "get_ipython().run_cell_magic('bar', '123', 'hello')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [('a=5', 'a=5'),
('%%cellmagic', '%%cellmagic'),
MinRK
test that cell-magics are not transformed mid-cell
r11473 ],
Thomas Kluyver
Move and combine transformer tests
r10095 ],
escaped =
[ [('%abc def \\', None),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 ('ghi', "get_ipython().run_line_magic('abc', 'def ghi')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
[('%abc def \\', None),
('ghi\\', None),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 (None, "get_ipython().run_line_magic('abc', 'def ghi')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
],
assign_magic =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ [('a = %bc de \\', None),
('fg', "a = get_ipython().run_line_magic('bc', 'de fg')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [('a = %bc de \\', None),
('fg\\', None),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 (None, "a = get_ipython().run_line_magic('bc', 'de fg')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
],
assign_system =
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ [('a = !bc de \\', None),
('fg', "a = get_ipython().getoutput('bc de fg')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [('a = !bc de \\', None),
('fg\\', None),
Matthias Bussonnier
Remove all usage of u_format (no op), and remove function...
r25658 (None, "a = get_ipython().getoutput('bc de fg')"),
Thomas Kluyver
Move and combine transformer tests
r10095 ],
],
)
Thomas Kluyver
First go at new input transformation system
r10090
Thomas Kluyver
More input transformers
r10091
Thomas Kluyver
Move and combine transformer tests
r10095 def test_assign_system():
tt.check_pairs(transform_and_reset(ipt.assign_from_system), syntax['assign_system'])
def test_assign_magic():
tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic'])
Thomas Kluyver
More input transformers
r10091
def test_classic_prompt():
Thomas Kluyver
Move and combine transformer tests
r10095 tt.check_pairs(transform_and_reset(ipt.classic_prompt), syntax['classic_prompt'])
for example in syntax_ml['classic_prompt']:
transform_checker(example, ipt.classic_prompt)
Thomas Kluyver
Fix for \ at end of comment, and add tests
r10112 for example in syntax_ml['multiline_datastructure_prompt']:
Thomas Kluyver
Fix tests in IPython.core
r10097 transform_checker(example, ipt.classic_prompt)
Thomas Kluyver
More input transformers
r10091
Thomas Kluyver
Deactivate prompt transformers if the first line matches certain patterns...
r21954 # Check that we don't transform the second line if the first is obviously
# IPython syntax
transform_checker([
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('%foo', '%foo'),
('>>> bar', '>>> bar'),
Thomas Kluyver
Deactivate prompt transformers if the first line matches certain patterns...
r21954 ], ipt.classic_prompt)
Thomas Kluyver
More input transformers
r10091
def test_ipy_prompt():
Thomas Kluyver
Move and combine transformer tests
r10095 tt.check_pairs(transform_and_reset(ipt.ipy_prompt), syntax['ipy_prompt'])
for example in syntax_ml['ipy_prompt']:
transform_checker(example, ipt.ipy_prompt)
Thomas Kluyver
More input transformers
r10091
Thomas Kluyver
Deactivate prompt transformers if the first line matches certain patterns...
r21954 # Check that we don't transform the second line if we're inside a cell magic
transform_checker([
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ('%%foo', '%%foo'),
('In [1]: bar', 'In [1]: bar'),
Thomas Kluyver
Deactivate prompt transformers if the first line matches certain patterns...
r21954 ], ipt.ipy_prompt)
Thomas Kluyver
Simplify input transformers...
r10107 def test_assemble_logical_lines():
tests = \
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ [("a = \\", None),
("123", "a = 123"),
Thomas Kluyver
Simplify input transformers...
r10107 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("a = \\", None), # Test resetting when within a multi-line string
("12 *\\", None),
(None, "a = 12 *"),
Thomas Kluyver
Fix for \ at end of comment, and add tests
r10112 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("# foo\\", "# foo\\"), # Comments can't be continued like this
Thomas Kluyver
Simplify input transformers...
r10107 ],
]
for example in tests:
transform_checker(example, ipt.assemble_logical_lines)
def test_assemble_python_lines():
tests = \
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ [("a = '''", None),
("abc'''", "a = '''\nabc'''"),
Thomas Kluyver
Simplify input transformers...
r10107 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("a = '''", None), # Test resetting when within a multi-line string
("def", None),
(None, "a = '''\ndef"),
Thomas Kluyver
Simplify input transformers...
r10107 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("a = [1,", None),
("2]", "a = [1,\n2]"),
Thomas Kluyver
Simplify input transformers...
r10107 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("a = [1,", None), # Test resetting when within a multi-line string
("2,", None),
(None, "a = [1,\n2,"),
Thomas Kluyver
Simplify input transformers...
r10107 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("a = '''", None), # Test line continuation within a multi-line string
("abc\\", None),
("def", None),
("'''", "a = '''\nabc\\\ndef\n'''"),
Thomas Kluyver
Add failing test for line continuation in multiline string
r23183 ],
Thomas Kluyver
Fix for \ at end of comment, and add tests
r10112 ] + syntax_ml['multiline_datastructure']
Thomas Kluyver
Simplify input transformers...
r10107 for example in tests:
transform_checker(example, ipt.assemble_python_lines)
Thomas Kluyver
Move and combine transformer tests
r10095 def test_help_end():
tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
Thomas Kluyver
More input transformers
r10091
Thomas Kluyver
Move and combine transformer tests
r10095 def test_escaped_noesc():
Thomas Kluyver
Simplify input transformers...
r10107 tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_noesc'])
Thomas Kluyver
Transformers for assignment from %magic and \!system calls
r10092
Thomas Kluyver
Move and combine transformer tests
r10095 def test_escaped_shell():
Thomas Kluyver
Simplify input transformers...
r10107 tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_shell'])
Thomas Kluyver
Transformers for assignment from %magic and \!system calls
r10092
Thomas Kluyver
Move and combine transformer tests
r10095 def test_escaped_help():
Thomas Kluyver
Simplify input transformers...
r10107 tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_help'])
Thomas Kluyver
Move and combine transformer tests
r10095
def test_escaped_magic():
Thomas Kluyver
Simplify input transformers...
r10107 tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_magic'])
Thomas Kluyver
Move and combine transformer tests
r10095
def test_escaped_quote():
Thomas Kluyver
Simplify input transformers...
r10107 tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_quote'])
Thomas Kluyver
Move and combine transformer tests
r10095
def test_escaped_quote2():
Thomas Kluyver
Simplify input transformers...
r10107 tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_quote2'])
Thomas Kluyver
Move and combine transformer tests
r10095
def test_escaped_paren():
Thomas Kluyver
Simplify input transformers...
r10107 tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_paren'])
Thomas Kluyver
Move and combine transformer tests
r10095
def test_cellmagic():
for example in syntax_ml['cellmagic']:
transform_checker(example, ipt.cellmagic)
Thomas Kluyver
Allow IPythonInputSplitter to accept cell magics containing blank lines
r10252
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 line_example = [('%%bar 123', None),
('hello', None),
('' , "get_ipython().run_cell_magic('bar', '123', 'hello')"),
Thomas Kluyver
Allow IPythonInputSplitter to accept cell magics containing blank lines
r10252 ]
transform_checker(line_example, ipt.cellmagic, end_on_blank_line=True)
Thomas Kluyver
Fix tests in IPython.core
r10097
def test_has_comment():
tests = [('text', False),
('text #comment', True),
('text #comment\n', True),
('#comment', True),
('#comment\n', True),
('a = "#string"', False),
('a = "#string" # comment', True),
('a #comment not "string"', True),
]
tt.check_pairs(ipt.has_comment, tests)
Thomas Kluyver
Add TokenInputTransformer
r10103
@ipt.TokenInputTransformer.wrap
def decistmt(tokens):
"""Substitute Decimals for floats in a string of statements.
Based on an example from the tokenize module docs.
"""
result = []
for toknum, tokval, _, _, _ in tokens:
if toknum == tokenize.NUMBER and '.' in tokval: # replace NUMBER tokens
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 yield from [
Thomas Kluyver
Add TokenInputTransformer
r10103 (tokenize.NAME, 'Decimal'),
(tokenize.OP, '('),
(tokenize.STRING, repr(tokval)),
(tokenize.OP, ')')
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 ]
Thomas Kluyver
Add TokenInputTransformer
r10103 else:
yield (toknum, tokval)
def test_token_input_transformer():
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 tests = [('1.2', "Decimal ('1.2')"),
('"1.2"', '"1.2"'),
Thomas Kluyver
Add TokenInputTransformer
r10103 ]
tt.check_pairs(transform_and_reset(decistmt), tests)
ml_tests = \
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [ [("a = 1.2; b = '''x", None),
("y'''", "a =Decimal ('1.2');b ='''x\ny'''"),
Thomas Kluyver
Add TokenInputTransformer
r10103 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("a = [1.2,", None),
("3]", "a =[Decimal ('1.2'),\n3 ]"),
Thomas Kluyver
Add TokenInputTransformer
r10103 ],
Matthias Bussonnier
Apply pygrade --36plus on IPython/core/tests/test_inputtransformer.py....
r25659 [("a = '''foo", None), # Test resetting when within a multi-line string
("bar", None),
(None, "a = '''foo\nbar"),
Thomas Kluyver
Add TokenInputTransformer
r10103 ],
]
for example in ml_tests:
transform_checker(example, decistmt)