Example #1
0
def test_compiler_return_statement_entity(patch, compiler, lines, tree):
    """
    Ensures Compiler.return_statement can compile return statements that return
    entities.
    """
    patch.object(JSONCompiler, 'fake_base_expression')
    compiler.return_statement(tree, '1')
    position = tree.position()
    JSONCompiler.fake_base_expression.assert_called_with(
        tree.base_expression, '1')
    kwargs = {'args': [JSONCompiler.fake_base_expression()], 'parent': '1'}
    lines.append.assert_called_with('return', position, **kwargs)
Example #2
0
def test_compiler_return_statement_entity(patch, compiler, lines, tree):
    """
    Ensures Compiler.return_statement can compile return statements that return
    entities.
    """
    patch.object(JSONCompiler, "fake_base_expression")
    compiler.return_statement(tree, "1")
    position = tree.position()
    JSONCompiler.fake_base_expression.assert_called_with(
        tree.base_expression, "1"
    )
    kwargs = {"args": [JSONCompiler.fake_base_expression()], "parent": "1"}
    lines.append.assert_called_with("return", position, **kwargs)
Example #3
0
def test_compiler_elseif_block(patch, compiler, lines, tree):
    patch.many(JSONCompiler, ['subtree', 'fake_base_expression',
                              'create_scope'])
    compiler.elseif_block(tree, '1')
    exp = tree.elseif_statement.base_expression
    JSONCompiler.fake_base_expression.assert_called_with(exp, '1')
    args = [JSONCompiler.fake_base_expression()]
    compiler.create_scope.assert_called_with(tree.position(), '1')
    lines.append.assert_called_with('elif', tree.position(), args=args,
                                    enter=tree.nested_block.line(),
                                    parent='1')
    compiler.subtree.assert_called_with(tree.nested_block,
                                        parent=tree.position().line)
Example #4
0
def test_compiler_if_block(patch, compiler, lines, tree):
    patch.many(JSONCompiler, ['subtree', 'fake_base_expression'])
    tree.elseif_block = None
    tree.else_block = None
    tree.extract.return_value = []
    compiler.if_block(tree, '1')
    exp = tree.if_statement.base_expression
    JSONCompiler.fake_base_expression.assert_called_with(exp, '1')
    nested_block = tree.nested_block
    args = [JSONCompiler.fake_base_expression()]
    lines.set_scope.assert_called_with(tree.line(), '1')
    lines.finish_scope.assert_called_with(tree.line())
    lines.append.assert_called_with('if', tree.line(), args=args,
                                    enter=nested_block.line(), parent='1')
    compiler.subtree.assert_called_with(nested_block, parent=tree.line())
Example #5
0
def test_compiler_elseif_block(patch, compiler, lines, tree):
    patch.many(
        JSONCompiler, ["subtree", "fake_base_expression", "create_scope"]
    )
    compiler.elseif_block(tree, "1")
    exp = tree.elseif_statement.base_expression
    JSONCompiler.fake_base_expression.assert_called_with(exp, "1")
    args = [JSONCompiler.fake_base_expression()]
    compiler.create_scope.assert_called_with(tree.position(), "1")
    lines.append.assert_called_with(
        "elif",
        tree.position(),
        args=args,
        enter=tree.nested_block.line(),
        parent="1",
    )
    compiler.subtree.assert_called_with(
        tree.nested_block, parent=tree.position().line
    )
Example #6
0
def test_compiler_if_block(patch, compiler, lines, tree):
    patch.many(
        JSONCompiler, ["subtree", "fake_base_expression", "create_scope"]
    )
    tree.elseif_block = None
    tree.else_block = None
    tree.extract.return_value = []
    compiler.if_block(tree, "1")
    exp = tree.if_statement.base_expression
    JSONCompiler.fake_base_expression.assert_called_with(exp, "1")
    nested_block = tree.nested_block
    args = [JSONCompiler.fake_base_expression()]
    compiler.create_scope.assert_called_with(tree.position(), "1")
    lines.append.assert_called_with(
        "if", tree.position(), args=args, enter=nested_block.line(), parent="1"
    )
    compiler.subtree.assert_called_with(
        nested_block, parent=tree.position().line
    )