def test_classic_prompt(): 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) for example in syntax_ml['multiline_datastructure_prompt']: transform_checker(example, ipt.classic_prompt)
def test_translate_abbreviations(self): def do_translate(template): self.pm.in_template = template return self.pm.templates["in"] pairs = [(r"%n>", "{color.number}{count}{color.prompt}>"), (r"\T", "{time}"), (r"\n", "\n")] tt.check_pairs(do_translate, pairs)
def test_remove_comments(): tests = [('text', 'text'), ('text # comment', 'text '), ('text # comment\n', 'text \n'), ('text # comment \n', 'text \n'), ('line # c \nline\n','line \nline\n'), ('line # c \nline#c2 \nline\nline #c\n\n', 'line \nline\nline\nline \n\n'), ] tt.check_pairs(isp.remove_comments, tests)
def test_remove_comments(): tests = [ ("text", "text"), ("text # comment", "text "), ("text # comment\n", "text \n"), ("text # comment \n", "text \n"), ("line # c \nline\n", "line \nline\n"), ("line # c \nline#c2 \nline\nline #c\n\n", "line \nline\nline\nline \n\n"), ] tt.check_pairs(isp.remove_comments, tests)
def test_ipy_prompt(): 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) # Check that we don't transform the second line if we're inside a cell magic transform_checker([ (u'%%foo', '%%foo'), (u'In [1]: bar', 'In [1]: bar'), ], ipt.ipy_prompt)
def test_translate_abbreviations(self): def do_translate(template): self.pm.in_template = template return self.pm.templates['in'] pairs = [(r'%n>', '{color.number}{count}{color.prompt}>'), (r'\T', '{time}'), (r'\n', '\n') ] tt.check_pairs(do_translate, pairs)
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(isp.has_comment, tests)
def test_classic_prompt(): 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) for example in syntax_ml['multiline_datastructure_prompt']: transform_checker(example, ipt.classic_prompt) # Check that we don't transform the second line if the first is obviously # IPython syntax transform_checker([ (u'%foo', '%foo'), (u'>>> bar', '>>> bar'), ], ipt.classic_prompt)
def test_spaces(): tests = [('', 0), (' ', 1), ('\n', 0), (' \n', 1), ('x', 0), (' x', 1), (' x',2), (' x',4), # Note: tabs are counted as a single whitespace! ('\tx', 1), ('\t x', 2), ] tt.check_pairs(isp.num_ini_spaces, tests)
def test_spaces(): tests = [ ("", 0), (" ", 1), ("\n", 0), (" \n", 1), ("x", 0), (" x", 1), (" x", 2), (" x", 4), # Note: tabs are counted as a single whitespace! ("\tx", 1), ("\t x", 2), ] tt.check_pairs(isp.num_ini_spaces, tests)
def test_token_input_transformer(): tests = [(u'1.2', u_fmt(u"Decimal ({u}'1.2')")), (u'"1.2"', u'"1.2"'), ] tt.check_pairs(transform_and_reset(decistmt), tests) ml_tests = \ [ [(u"a = 1.2; b = '''x", None), (u"y'''", u_fmt(u"a =Decimal ({u}'1.2');b ='''x\ny'''")), ], [(u"a = [1.2,", None), (u"3]", u_fmt(u"a =[Decimal ({u}'1.2'),\n3 ]")), ], [(u"a = '''foo", None), # Test resetting when within a multi-line string (u"bar", None), (None, u"a = '''foo\nbar"), ], ] for example in ml_tests: transform_checker(example, decistmt)
def test_escaped_shell(): tt.check_pairs(isp.transform_escaped, syntax['escaped_shell'])
def test_assign_magic(): tt.check_pairs(isp.transform_assign_magic, syntax['assign_magic'])
def test_assign_system(): tt.check_pairs(isp.transform_assign_system, syntax['assign_system'])
def test_escaped_paren(): tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_paren'])
def test_coding_cookie(): tt.check_pairs(transform_and_reset(ipt.strip_encoding_cookie), syntax['strip_encoding_cookie']) for example in syntax_ml['strip_encoding_cookie']: transform_checker(example, ipt.strip_encoding_cookie)
def test_assign_magic(): tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic'])
def run(tests): """Loop through a list of (pre, post) inputs, where pre is the string handed to ipython, and post is how that string looks after it's been transformed (i.e. ipython's notion of _i)""" tt.check_pairs(ip.prefilter_manager.prefilter_lines, tests)
def test_split_user_input(): return tt.check_pairs(split_user_input, tests)
def test_end_help(): tt.check_pairs(isp.transform_help_end, syntax['end_help'])
def test_escaped_paren(): tt.check_pairs(isp.transform_escaped, syntax['escaped_paren'])
def test_escaped_quote2(): tt.check_pairs(isp.transform_escaped, syntax['escaped_quote2'])
def test_escaped_magic(): tt.check_pairs(isp.transform_escaped, syntax['escaped_magic'])
def test_escaped_help(): tt.check_pairs(isp.transform_escaped, syntax['escaped_help'])
def test_ipy_prompt(): 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)
def test_help_end(): tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
def test_assign_system(): tt.check_pairs(transform_and_reset(ipt.assign_from_system), syntax['assign_system'])
def test_escaped_quote(): tt.check_pairs(isp.transform_escaped, syntax["escaped_quote"])
def test_escaped_noesc(): tt.check_pairs(isp.transform_escaped, syntax["escaped_noesc"])
def test_classic_prompt(): 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) for example in syntax_ml['multiline_datastructure_prompt']: transform_checker(example, ipt.classic_prompt)