def test_faketree_add_assignment(patch, fake_tree, block): patch.object(FakeTree, 'assignment') block.child.return_value = None result = fake_tree.add_assignment('value') FakeTree.assignment.assert_called_with('value') assert block.children == [FakeTree.assignment(), block.child()] assert result == FakeTree.assignment()
def test_faketree_assignment(patch, tree, fake_tree): patch.many(FakeTree, ['path', 'get_line']) result = fake_tree.assignment(tree) FakeTree.get_line.assert_called_with(tree) line = FakeTree.get_line() FakeTree.path.assert_called_with(line=line) assert tree.child().child().line == line assert result.children[0] == FakeTree.path() subtree = [Token('EQUALS', '=', line=line), tree] expected = Tree('assignment_fragment', subtree) assert result.children[1] == 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_path(patch, fake_tree): patch.object(uuid, 'uuid4') patch.object(FakeTree, 'line') result = fake_tree.path() name = '${}'.format(uuid.uuid4().hex[:8]) assert result == Tree('path', [Token('NAME', name, line=FakeTree.line())])
def fake_tree(block): return FakeTree(block)
def test_faketree_add_assignment_more_children(patch, fake_tree, block): patch.object(FakeTree, 'assignment') fake_tree.add_assignment('value') expected = [block.child(), FakeTree.assignment(), block.child()] assert block.children == expected
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(Preprocessor, 'fake_tree', return_value=FakeTree(None)) return Preprocessor()