Пример #1
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)
Пример #2
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)
Пример #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)
Пример #4
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(ipt.has_comment, tests)
Пример #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)
Пример #6
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(ipt.has_comment, tests)
Пример #7
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
    # yap_ipython syntax
    transform_checker([
        (u'%foo', '%foo'),
        (u'>>> bar', '>>> bar'),
    ], ipt.classic_prompt)
Пример #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
    # yap_ipython syntax
    transform_checker([
        (u'%foo', '%foo'),
        (u'>>> bar', '>>> bar'),
    ], ipt.classic_prompt)
Пример #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)
Пример #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)
Пример #11
0
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)
Пример #12
0
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)
Пример #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)
Пример #14
0
def test_help_end():
    tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
Пример #15
0
def test_help_end():
    tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help'])
Пример #16
0
def test_escaped_paren():
    tt.check_pairs(transform_and_reset(ipt.escaped_commands),
                   syntax['escaped_paren'])
Пример #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)
Пример #18
0
def test_split_user_input():
    return tt.check_pairs(split_user_input, tests)
Пример #19
0
def test_assign_magic():
    tt.check_pairs(transform_and_reset(ipt.assign_from_magic),
                   syntax['assign_magic'])
Пример #20
0
def test_assign_system():
    tt.check_pairs(transform_and_reset(ipt.assign_from_system),
                   syntax['assign_system'])
Пример #21
0
def test_assign_system():
    tt.check_pairs(transform_and_reset(ipt.assign_from_system), syntax['assign_system'])
Пример #22
0
def test_assign_magic():
    tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic'])
Пример #23
0
def test_escaped_paren():
    tt.check_pairs(transform_and_reset(ipt.escaped_commands), syntax['escaped_paren'])