예제 #1
0
def test_faketree_add_assignment(patch, fake_tree, block):
    patch.object(FakeTree, 'assignment')
    patch.object(FakeTree, 'find_insert_pos', return_value=0)
    block.children = [1]
    block.child.return_value = None
    result = fake_tree.add_assignment('value', original_line=10)
    FakeTree.assignment.assert_called_with('value')
    assert block.children == [FakeTree.assignment(), 1]
    name = Token('NAME', FakeTree.assignment().path.child(0), line=10)
    assert result.data == 'path'
    assert result.children == [name]
예제 #2
0
def test_faketree_assignment(patch, tree, fake_tree):
    patch.many(FakeTree, ["path", "get_line", "set_line"])
    result = fake_tree.assignment(tree)
    FakeTree.get_line.assert_called_with(tree)
    line = FakeTree.get_line()
    FakeTree.set_line.assert_called_with(tree, line)
    FakeTree.path.assert_called_with(line=line)
    assert result.children[0] == FakeTree.path()
    tree = Tree("base_expression", [tree])
    subtree = [Token("EQUALS", "=", line=line), tree]
    expected = Tree("assignment_fragment", subtree)
    assert result.children[1] == expected
예제 #3
0
def test_faketree_assignment(patch, tree, fake_tree):
    patch.many(FakeTree, ['path', 'get_line', 'set_line'])
    result = fake_tree.assignment(tree)
    FakeTree.get_line.assert_called_with(tree)
    line = FakeTree.get_line()
    FakeTree.set_line.assert_called_with(tree, line)
    FakeTree.path.assert_called_with(line=line)
    assert result.children[0] == FakeTree.path()
    tree = Tree('base_expression', [tree])
    subtree = [Token('EQUALS', '=', line=line), tree]
    expected = Tree('assignment_fragment', subtree)
    assert result.children[1] == expected
예제 #4
0
def test_faketree_add_assignment_four_children_bottom(patch, fake_tree, block):
    patch.object(FakeTree, "assignment")
    patch.object(FakeTree, "find_insert_pos", return_value=-1)
    block.children = ["c1", "c2", "c3", fake_tree.block.last_child()]
    fake_tree.add_assignment("value", original_line=42)
    expected = ["c1", "c2", "c3", FakeTree.assignment(), block.last_child()]
    assert block.children == expected
예제 #5
0
def test_faketree_get_line(patch, tree, fake_tree):
    """
    Ensures FakeTree.get_line can get a new line
    """
    patch.object(FakeTree, "line")
    result = fake_tree.get_line(tree)
    assert result == FakeTree.line()
예제 #6
0
def test_faketree_add_assignment_four_children_bottom(patch, fake_tree, block):
    patch.object(FakeTree, 'assignment')
    patch.object(FakeTree, 'find_insert_pos', return_value=-1)
    block.children = ['c1', 'c2', 'c3', fake_tree.block.last_child()]
    fake_tree.add_assignment('value', original_line=42)
    expected = ['c1', 'c2', 'c3', FakeTree.assignment(), block.last_child()]
    assert block.children == expected
예제 #7
0
def test_faketree_add_assignment(patch, fake_tree, block):
    patch.object(FakeTree, 'assignment')
    patch.object(Tree, 'create_token_from_tok')
    patch.object(FakeTree, 'find_insert_pos', return_value=0)
    block.children = [1]
    block.child.return_value = None
    result = fake_tree.add_assignment('value', original_line=10)
    FakeTree.assignment.assert_called_with('value')
    assert block.children == [FakeTree.assignment(), 1]
    path_tok = FakeTree.assignment().path.child(0)
    Tree.create_token_from_tok.assert_called_with(path_tok, 'NAME',
                                                  path_tok.value)
    name = Tree.create_token_from_tok()
    name.line = 10
    assert result.data == 'path'
    assert result.children == [name]
예제 #8
0
def test_faketree_add_assignment(patch, fake_tree, block):
    patch.object(FakeTree, "assignment")
    patch.object(Tree, "create_token_from_tok")
    patch.object(FakeTree, "find_insert_pos", return_value=0)
    block.children = [1]
    block.child.return_value = None
    result = fake_tree.add_assignment("value", original_line=10)
    FakeTree.assignment.assert_called_with("value")
    assert block.children == [FakeTree.assignment(), 1]
    path_tok = FakeTree.assignment().path.child(0)
    Tree.create_token_from_tok.assert_called_with(
        path_tok, "NAME", path_tok.value
    )
    name = Tree.create_token_from_tok()
    name.line = 10
    assert result.data == "path"
    assert result.children == [name]
예제 #9
0
def test_faketree_path(patch, fake_tree):
    patch.object(FakeTree, "line")
    FakeTree.line.return_value = "fake.line"
    result = fake_tree.path()
    name = "__p-fake.line"
    assert result == Tree("path", [Token("NAME", name, line=FakeTree.line())])
예제 #10
0
def fake_tree(block):
    return FakeTree(block)
예제 #11
0
def test_faketree_path(patch, fake_tree):
    patch.object(FakeTree, 'line')
    FakeTree.line.return_value = 'fake.line'
    result = fake_tree.path()
    name = '__p-fake.line'
    assert result == Tree('path', [Token('NAME', name, line=FakeTree.line())])
예제 #12
0
def preprocessor(patch):
    patch.init(FakeTree)
    patch.object(Lowering, 'fake_tree', return_value=FakeTree(None))
    return Lowering(parser=None, features=None)