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]
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
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
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
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()
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
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]
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]
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())])
def fake_tree(block): return FakeTree(block)
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())])
def preprocessor(patch): patch.init(FakeTree) patch.object(Lowering, 'fake_tree', return_value=FakeTree(None)) return Lowering(parser=None, features=None)