Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
def test_escaped_shell():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_shell'])
Ejemplo n.º 13
0
def test_assign_magic():
    tt.check_pairs(isp.transform_assign_magic, syntax['assign_magic'])
Ejemplo n.º 14
0
def test_assign_system():
    tt.check_pairs(isp.transform_assign_system, syntax['assign_system'])
Ejemplo n.º 15
0
def test_escaped_paren():
    tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_paren'])
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
def test_assign_magic():
    tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic'])
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
def test_split_user_input():
    return tt.check_pairs(split_user_input, tests)
Ejemplo n.º 20
0
def test_end_help():
    tt.check_pairs(isp.transform_help_end, syntax['end_help'])
Ejemplo n.º 21
0
def test_escaped_paren():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_paren'])
Ejemplo n.º 22
0
def test_escaped_quote2():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_quote2'])
Ejemplo n.º 23
0
def test_escaped_magic():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_magic'])
Ejemplo n.º 24
0
def test_escaped_magic():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_magic'])
Ejemplo n.º 25
0
def test_escaped_paren():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_paren'])
Ejemplo n.º 26
0
def test_assign_magic():
    tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic'])
Ejemplo n.º 27
0
def test_escaped_help():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_help'])
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
0
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)
Ejemplo n.º 30
0
def test_help_end():
    tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
Ejemplo n.º 31
0
def test_help_end():
    tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
Ejemplo n.º 32
0
def test_escaped_paren():
    tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_paren'])
Ejemplo n.º 33
0
def test_assign_system():
    tt.check_pairs(transform_and_reset(ipt.assign_from_system),
                   syntax['assign_system'])
Ejemplo n.º 34
0
def test_escaped_quote():
    tt.check_pairs(isp.transform_escaped, syntax["escaped_quote"])
Ejemplo n.º 35
0
def test_assign_system():
    tt.check_pairs(isp.transform_assign_system, syntax['assign_system'])
Ejemplo n.º 36
0
def test_escaped_noesc():
    tt.check_pairs(isp.transform_escaped, syntax["escaped_noesc"])
Ejemplo n.º 37
0
def test_end_help():
    tt.check_pairs(isp.transform_help_end, syntax['end_help'])
Ejemplo n.º 38
0
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)
Ejemplo n.º 39
0
def test_escaped_help():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_help'])
Ejemplo n.º 40
0
def test_assign_magic():
    tt.check_pairs(isp.transform_assign_magic, syntax['assign_magic'])
Ejemplo n.º 41
0
def test_escaped_quote2():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_quote2'])
Ejemplo n.º 42
0
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)
Ejemplo n.º 43
0
def test_split_user_input():
    return tt.check_pairs(split_user_input, tests)
Ejemplo n.º 44
0
def test_assign_system():
    tt.check_pairs(transform_and_reset(ipt.assign_from_system), syntax['assign_system'])
Ejemplo n.º 45
0
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)
Ejemplo n.º 46
0
def test_escaped_shell():
    tt.check_pairs(isp.transform_escaped, syntax['escaped_shell'])