Exemple #1
0
def test_compiler_if_block(patch, compiler):
    patch.object(Objects, 'expression')
    patch.many(Compiler, ['add_line', 'subtree'])
    tree = Tree('if_block', [Tree('if_statement', []),
                             Tree('nested_block', [])])
    compiler.if_block(tree)
    Objects.expression.assert_called_with(tree.node('if_statement'))
    nested_block = tree.node('nested_block')
    args = Objects.expression()
    compiler.add_line.assert_called_with('if', tree.line(), args=args,
                                         enter=nested_block.line(),
                                         parent=None)
    compiler.subtree.assert_called_with(nested_block, parent=tree.line())
Exemple #2
0
def test_compiler_if_block_with_else(patch, compiler):
    patch.object(Objects, 'expression')
    patch.many(Compiler, ['add_line', 'subtree', 'subtrees'])
    tree = Tree('if_block', [Tree('nested_block', []),
                             Tree('else_block', [])])
    compiler.if_block(tree)
    compiler.subtrees.assert_called_with(tree.node('else_block'))
Exemple #3
0
def test_tree_node_nested(patch):
    patch.object(Tree, 'walk')
    tree = Tree('rule', [])
    result = tree.node('inner.nested')
    assert len(Tree.walk.call_args_list) == 2
    assert Tree.walk.call_args_list[0] == call(tree, 'inner')
    assert Tree.walk.call_args_list[1] == call(Tree.walk(), 'nested')
    assert result == Tree.walk()
Exemple #4
0
def test_tree_node_nested(patch):
    patch.object(Tree, "walk")
    tree = Tree("rule", [])
    result = tree.node("inner.nested")
    assert len(Tree.walk.call_args_list) == 2
    assert Tree.walk.call_args_list[0] == call(tree, "inner")
    assert Tree.walk.call_args_list[1] == call(Tree.walk(), "nested")
    assert result == Tree.walk()
Exemple #5
0
def test_tree_node(patch):
    patch.object(Tree, 'walk')
    tree = Tree('rule', [])
    result = tree.node('inner')
    Tree.walk.assert_called_with(tree, 'inner')
    assert result == Tree.walk()
Exemple #6
0
def test_tree_attributes(patch):
    patch.object(Tree, 'node')
    tree = Tree('master', [])
    result = tree.branch
    Tree.node.assert_called_with('branch')
    assert result == Tree.node()
Exemple #7
0
def test_tree_node(patch):
    patch.object(Tree, "walk")
    tree = Tree("rule", [])
    result = tree.node("inner")
    Tree.walk.assert_called_with(tree, "inner")
    assert result == Tree.walk()
Exemple #8
0
def test_tree_attributes(patch):
    patch.object(Tree, "node")
    tree = Tree("master", [])
    result = tree.branch
    Tree.node.assert_called_with("branch")
    assert result == Tree.node()