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)
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)
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
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
def test_print_as_print(): code = "print(a)" assert print_is_parsed_as_a_function(parse(code, False)) == False
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))
def test_print_as_name(): code = "print(a)" assert print_is_parsed_as_a_function(parse(code, True)) == True
def test_bb_class(): node = parse(classcode)[0] assert node_to_bounding_box(node) == ((1, 1), (7, 0))
def test_bb_funcdef(): node = parse(bigcode)[0] assert node_to_bounding_box(node) == ((1, 1), (4, 0))
def test_bb_name(): node = parse("var")[0] assert node_to_bounding_box(node) == ((1, 1), (1, 3))
def test_bb_string(): node = parse("\"hello\"")[0] assert path_to_bounding_box(node, []) == ((1, 1), (1, 7))
def test_auto_print_as_name(): code = "from __future__ import print_function\nprint(a)" assert print_is_parsed_as_a_function(parse(code)) == True
def test_bb_comment(): node = parse("# comment")[0] assert path_to_bounding_box(node, None) == ((1, 1), (1, 9))
def test_auto_print_as_print(): code = "print(a)" assert not print_is_parsed_as_a_function(parse(code))
def test_bb_funcdef(): node = parse(funcdefcode)[0] assert node_to_bounding_box(node) == ((1, 1), (3, 9))
def test_bb_class(): node = parse(classcode)[0] assert node_to_bounding_box(node) == ((1, 1), (6, 21))
def test_bb_split_assignment(): node = parse(splitcode)[0] assert node_to_bounding_box(node) == ((1, 1), (2, 5))