def test_compiler_catch_block(patch, compiler, lines, tree): """ Ensures that catch blocks are compiled correctly. """ patch.object(Objects, 'names') patch.object(JSONCompiler, 'subtree') compiler.catch_block(tree, '1') lines.set_exit.assert_called_with(tree.line()) Objects.names.assert_called_with(tree.catch_statement) lines.set_scope.assert_called_with(tree.line(), '1', Objects.names()) lines.finish_scope.assert_called_with(tree.line()) kwargs = {'enter': tree.nested_block.line(), 'output': Objects.names(), 'parent': '1'} lines.append.assert_called_with('catch', tree.line(), **kwargs) compiler.subtree.assert_called_with(tree.nested_block, parent=tree.line())
def test_compiler_assignment_service(patch, compiler, lines, tree): patch.object(Objects, 'names') patch.object(JSONCompiler, 'service') lines.is_variable_defined.return_value = False compiler.assignment(tree, '1') service = tree.assignment_fragment.base_expression.service JSONCompiler.service.assert_called_with(service, None, '1') lines.set_name.assert_called_with(Objects.names())
def test_compiler_catch_block(patch, compiler, lines, tree): """ Ensures that catch blocks are compiled correctly. """ patch.object(Objects, 'names') patch.many(JSONCompiler, ['subtree', 'create_scope']) tree.catch_statement.children = ['catch', 'output'] compiler.catch_block(tree, '1') Objects.names.assert_called_with( Tree('catch_statement', tree.catch_statement.children[1:]) ) compiler.create_scope.assert_called_with(tree.position(), '1', Objects.names()) kwargs = {'enter': tree.nested_block.line(), 'output': Objects.names(), 'parent': '1'} lines.append.assert_called_with('catch', tree.position(), **kwargs) compiler.subtree.assert_called_with(tree.nested_block, parent=tree.position().line)
def test_compiler_assignment_unary(patch, compiler, lines, tree): """ Ensures a line like "x = value" is compiled correctly """ patch.many(Objects, ['names', 'entity', 'expression']) af = tree.assignment_fragment.base_expression af.service = None af.mutation = None lines.lines = {lines.last(): {'method': None}} compiler.assignment(tree, '1') Objects.names.assert_called_with(tree.path) Objects.expression.assert_called_with(af.expression) kwargs = {'args': [Objects.expression()], 'parent': '1'} lines.append.assert_called_with('expression', tree.position(), **kwargs) lines.set_name.assert_called_with(Objects.names())
def test_compiler_assignment_unary(patch, compiler, lines, tree): """ Ensures a line like "x = value" is compiled correctly """ patch.many(Objects, ["names", "entity", "expression"]) af = tree.assignment_fragment.base_expression af.service = None af.mutation = None lines.lines = {lines.last(): {"method": None}} compiler.assignment(tree, "1") Objects.names.assert_called_with(tree.path) Objects.expression.assert_called_with(af.expression) kwargs = {"args": [Objects.expression()], "parent": "1"} lines.append.assert_called_with("expression", tree.position(), **kwargs) lines.set_name.assert_called_with(Objects.names())
def test_compiler_catch_block(patch, compiler, lines, tree): """ Ensures that catch blocks are compiled correctly. """ patch.object(Objects, "names") patch.many(JSONCompiler, ["subtree", "create_scope"]) tree.catch_statement.children = ["catch", "output"] compiler.catch_block(tree, "1") Objects.names.assert_called_with( Tree("catch_statement", tree.catch_statement.children[1:]) ) compiler.create_scope.assert_called_with( tree.position(), "1", Objects.names() ) kwargs = { "enter": tree.nested_block.line(), "output": Objects.names(), "parent": "1", } lines.append.assert_called_with("catch", tree.position(), **kwargs) compiler.subtree.assert_called_with( tree.nested_block, parent=tree.position().line )