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_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_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_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)
Exemple #5
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)
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)
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
    # yap_ipython syntax
    transform_checker([
        (u'%foo', '%foo'),
        (u'>>> bar', '>>> bar'),
    ], ipt.classic_prompt)
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
    # yap_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)
Exemple #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)
def test_token_input_transformer():
    tests = [(u'1.2', u_fmt(u"Decimal ('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 ('1.2');b ='''x\ny'''")),
      ],
      [(u"a = [1.2,", None),
       (u"3]", u_fmt(u"a =[Decimal ('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_token_input_transformer():
    tests = [
        (u'1.2', u_fmt(u"Decimal ('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 ('1.2');b ='''x\ny'''")),
      ],
      [(u"a = [1.2,", None),
       (u"3]", u_fmt(u"a =[Decimal ('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)
Exemple #13
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)
def test_help_end():
    tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
def test_help_end():
    tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
def test_escaped_paren():
    tt.check_pairs(transform_and_reset(ipt.escaped_commands),
                   syntax['escaped_paren'])
Exemple #17
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)
Exemple #18
0
def test_split_user_input():
    return tt.check_pairs(split_user_input, tests)
def test_assign_magic():
    tt.check_pairs(transform_and_reset(ipt.assign_from_magic),
                   syntax['assign_magic'])
def test_assign_system():
    tt.check_pairs(transform_and_reset(ipt.assign_from_system),
                   syntax['assign_system'])
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'])
def test_escaped_paren():
    tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_paren'])