예제 #1
0
def test_path_walker_assignment():
    node = parse("a = 1")
    # Indentation is purely visual sugar
    walker = PathWalkerTester([
        ('>', [0]),
        ('>', [0, 'target']),
        ('>', [0, 'target', 'value']),
        ('<', [0, 'target', 'value']),
        ('<', [0, 'target']),
        ('>', [0, 'first_formatting']),
        ('>', [0, 'first_formatting', 0]),
        ('>', [0, 'first_formatting', 0, 'value']),
        ('<', [0, 'first_formatting', 0, 'value']),
        ('<', [0, 'first_formatting', 0]),
        ('<', [0, 'first_formatting']),
        ('>', [0, '=']),
        ('<', [0, '=']),
        ('>', [0, 'second_formatting']),
        ('>', [0, 'second_formatting', 0]),
        ('>', [0, 'second_formatting', 0, 'value']),
        ('<', [0, 'second_formatting', 0, 'value']),
        ('<', [0, 'second_formatting', 0]),
        ('<', [0, 'second_formatting']),
        ('>', [0, 'value']),
        ('>', [0, 'value', 'value']),
        ('<', [0, 'value', 'value']),
        ('<', [0, 'value']),
        ('<', [0]),
    ])

    walker.walk(node)
예제 #2
0
def test_path_walker_assignment():
    node = parse("a = 1")
    # Indentation is purely visual sugar
    walker = PathWalkerTester([
        ('>', [0]),
        ('>', [0, 'target']),
        ('>', [0, 'target', 'value']),
        ('<', [0, 'target', 'value']),
        ('<', [0, 'target']),
        ('>', [0, 'first_formatting']),
        ('>', [0, 'first_formatting', 0]),
        ('>', [0, 'first_formatting', 0, 'value']),
        ('<', [0, 'first_formatting', 0, 'value']),
        ('<', [0, 'first_formatting', 0]),
        ('<', [0, 'first_formatting']),
        ('>', [0, '=']),
        ('<', [0, '=']),
        ('>', [0, 'second_formatting']),
        ('>', [0, 'second_formatting', 0]),
        ('>', [0, 'second_formatting', 0, 'value']),
        ('<', [0, 'second_formatting', 0, 'value']),
        ('<', [0, 'second_formatting', 0]),
        ('<', [0, 'second_formatting']),
        ('>', [0, 'value']),
        ('>', [0, 'value', 'value']),
        ('<', [0, 'value', 'value']),
        ('<', [0, 'value']),
        ('<', [0]),
    ])

    walker.walk(node)
예제 #3
0
def test_bc_l1_def_first_formatting():
    tree = parse(bigcode)
    path = [0, "first_formatting"]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0, "value"]
    check_path(bigcode, [(1, 4)], path)
예제 #4
0
def test_bc_l1_def_first_formatting():
    tree = parse(bigcode)
    path = [0, "first_formatting"]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0, "value"]
    check_path(bigcode, [(1, 4)], path)
예제 #5
0
def check_path(code, positions, target_path):
    tree = parse(code)

    for (line, column) in positions:
        path = position_to_path(tree, line, column)
        assert path == target_path

        if path is None:
            assert position_to_node(tree, line, column) is None
            return

        node = path_to_node(tree, path)
        assert isinstance(node, string_instance)

        assert position_to_node(tree, line, column) is node

    if target_path is not None:
        bounding_box = (positions[0], positions[-1])
        assert path_to_bounding_box(tree, path) == bounding_box
예제 #6
0
def check_path(code, positions, target_path):
    tree = parse(code)

    for position in positions:
        path = position_to_path(tree, position)
        assert path == target_path

        if path is None:
            assert position_to_node(tree, position) is None
            return

        node = path_to_node(tree, path)
        assert isinstance(node, string_instance)

        assert position_to_node(tree, position) is node

    if target_path is not None:
        bounding_box = (positions[0], positions[-1])
        assert path_to_bounding_box(tree, path) == bounding_box
예제 #7
0
def test_print_as_print():
    code = "print(a)"
    assert print_is_parsed_as_a_function(parse(code, False)) == False
예제 #8
0
def test_bc_l1_def_second_formatting():
    path = [0, "second_formatting"]
    tree = parse(bigcode)
    assert path_to_bounding_box(tree, path) == ((1, 8), (1, 7))
예제 #9
0
def test_print_as_name():
    code = "print(a)"
    assert print_is_parsed_as_a_function(parse(code, True)) == True
예제 #10
0
def test_bb_class():
    node = parse(classcode)[0]
    assert node_to_bounding_box(node) == ((1, 1), (7, 0))
예제 #11
0
파일: test_path.py 프로젝트: PyCQA/baron
def test_bb_funcdef():
    node = parse(bigcode)[0]
    assert node_to_bounding_box(node) == ((1, 1), (4, 0))
예제 #12
0
def test_bb_name():
    node = parse("var")[0]
    assert node_to_bounding_box(node) == ((1, 1), (1, 3))
예제 #13
0
def test_bb_string():
    node = parse("\"hello\"")[0]
    assert path_to_bounding_box(node, []) == ((1, 1), (1, 7))
예제 #14
0
def test_bb_name():
    node = parse("var")[0]
    assert node_to_bounding_box(node) == ((1, 1), (1, 3))
예제 #15
0
def test_print_as_print():
    code = "print(a)"
    assert print_is_parsed_as_a_function(parse(code, False)) == False
예제 #16
0
def test_print_as_name():
    code = "print(a)"
    assert print_is_parsed_as_a_function(parse(code, True)) == True
예제 #17
0
def test_auto_print_as_name():
    code = "from __future__ import print_function\nprint(a)"
    assert print_is_parsed_as_a_function(parse(code)) == True
예제 #18
0
def test_bb_comment():
    node = parse("# comment")[0]
    assert path_to_bounding_box(node, None) == ((1, 1), (1, 9))
예제 #19
0
def test_bb_comment():
    node = parse("# comment")[0]
    assert path_to_bounding_box(node, None) == ((1, 1), (1, 9))
예제 #20
0
def test_auto_print_as_print():
    code = "print(a)"
    assert not print_is_parsed_as_a_function(parse(code))
예제 #21
0
def test_bb_string():
    node = parse("\"hello\"")[0]
    assert path_to_bounding_box(node, []) == ((1, 1), (1, 7))
예제 #22
0
def test_bb_funcdef():
    node = parse(funcdefcode)[0]
    assert node_to_bounding_box(node) == ((1, 1), (3, 9))
예제 #23
0
def test_bb_funcdef():
    node = parse(bigcode)[0]
    assert node_to_bounding_box(node) == ((1, 1), (4, 0))
예제 #24
0
def test_bb_class():
    node = parse(classcode)[0]
    assert node_to_bounding_box(node) == ((1, 1), (6, 21))
예제 #25
0
def test_bb_split_assignment():
    node = parse(splitcode)[0]
    assert node_to_bounding_box(node) == ((1, 1), (2, 5))
예제 #26
0
def test_bb_split_assignment():
    node = parse(splitcode)[0]
    assert node_to_bounding_box(node) == ((1, 1), (2, 5))
예제 #27
0
def test_bc_l1_def_second_formatting():
    path = [0, "second_formatting"]
    tree = parse(bigcode)
    assert path_to_bounding_box(tree, path) == ((1, 8), (1, 7))
예제 #28
0
def test_auto_print_as_name():
    code = "from __future__ import print_function\nprint(a)"
    assert print_is_parsed_as_a_function(parse(code)) == True