Пример #1
0
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()
Пример #2
0
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
Пример #3
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()
Пример #4
0
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())])
Пример #5
0
def fake_tree(block):
    return FakeTree(block)
Пример #6
0
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
Пример #7
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())])
Пример #8
0
def preprocessor(patch):
    patch.init(FakeTree)
    patch.object(Preprocessor, 'fake_tree', return_value=FakeTree(None))
    return Preprocessor()