def test_compiler_service_command(patch, compiler, tree): patch.object(Objects, 'arguments') patch.many(Compiler, ['add_line', 'output']) compiler.service(tree) line = tree.line() service = tree.child().child().value assert compiler.outputs[tree.line()] == Compiler.output() compiler.add_line.assert_called_with('execute', line, service=service, command=tree.node().child(), parent=None, output=Compiler.output(), args=Objects.arguments())
def test_compiler_service_command(patch, compiler, lines, tree): patch.object(Objects, 'arguments') patch.object(Compiler, 'output') compiler.service(tree, None, 'parent') line = tree.line() service = tree.path.extract_path() command = tree.service_fragment.command.child() lines.set_scope.assert_called_with(line, 'parent', Compiler.output()) lines.execute.assert_called_with(line, service, command, Objects.arguments(), Compiler.output(), None, 'parent')
def test_compiler_foreach_block(patch, compiler, lines, tree): patch.init(Tree) patch.object(Objects, 'entity') patch.many(Compiler, ['subtree', 'output']) compiler.foreach_block(tree, '1') assert Objects.entity.call_count == 1 compiler.output.assert_called_with(tree.foreach_statement.output) args = [Objects.entity()] lines.set_scope.assert_called_with(tree.line(), '1', Compiler.output()) lines.append.assert_called_with('for', tree.line(), args=args, enter=tree.nested_block.line(), output=Compiler.output(), parent='1') compiler.subtree.assert_called_with(tree.nested_block, parent=tree.line())
def test_compiler_foreach_block_parent(patch, compiler, tree): patch.object(Objects, 'path') patch.many(Compiler, ['add_line', 'subtree', 'output']) compiler.foreach_block(tree, parent='1') args = [Objects.path()] compiler.add_line.assert_called_with('for', tree.line(), args=args, enter=tree.node().line(), output=Compiler.output(), parent='1')
def test_compiler_when_path(patch, compiler, lines, tree): patch.object(Objects, 'path') patch.object(Compiler, 'output') tree.service = None compiler.when(tree, 'nested_block', '1') Objects.path.assert_called_with(tree.path) Compiler.output.assert_called_with(tree.output) lines.append.assert_called_with('when', tree.line(), args=[Objects.path()], output=Compiler.output(), parent='1')
def test_compiler_service_nested_block(patch, magic, compiler, lines, tree): patch.object(Objects, 'arguments') patch.object(Compiler, 'output') tree.node.return_value = None nested_block = magic() compiler.service(tree, nested_block, 'parent') line = tree.line() service = tree.path.extract_path() command = tree.service_fragment.command.child() lines.execute.assert_called_with(line, service, command, Objects.arguments(), Compiler.output(), nested_block.line(), 'parent')
def test_compiler_foreach_block(patch, compiler, lines, tree): patch.init(Tree) patch.object(Objects, 'path') patch.many(Compiler, ['subtree', 'output']) compiler.foreach_block(tree, '1') Tree.__init__.assert_called_with('path', [tree.foreach_statement.child()]) assert Objects.path.call_count == 1 compiler.output.assert_called_with(tree.foreach_statement.output) args = [Objects.path()] lines.append.assert_called_with('for', tree.line(), args=args, enter=tree.nested_block.line(), output=Compiler.output(), parent='1') compiler.subtree.assert_called_with(tree.nested_block, parent=tree.line())
def test_compiler_service(patch, compiler, lines, tree): """ Ensures that service trees can be compiled """ patch.object(Objects, 'arguments') patch.object(Compiler, 'output') tree.node.return_value = None compiler.service(tree, None, 'parent') line = tree.line() service = tree.path.extract_path() command = tree.service_fragment.command.child() Objects.arguments.assert_called_with(tree.service_fragment) Compiler.output.assert_called_with(tree.service_fragment.output) lines.execute.assert_called_with(line, service, command, Objects.arguments(), Compiler.output(), None, 'parent')
def test_compiler_service(patch, compiler, tree): """ Ensures that service trees can be compiled """ patch.object(Objects, 'arguments') patch.many(Compiler, ['add_line', 'output']) tree.node.return_value = None compiler.service(tree) line = tree.line() service = tree.child().child().value Objects.arguments.assert_called_with(tree.node()) Compiler.output.assert_called_with(tree.node()) compiler.add_line.assert_called_with('execute', line, service=service, command=tree.node(), parent=None, args=Objects.arguments(), output=Compiler.output())
def test_compiler_function_output(patch, tree): patch.object(Compiler, 'output') result = Compiler.function_output(tree) tree.node.assert_called_with('function_output.types') assert result == Compiler.output()
def test_compiler_output_none(): assert Compiler.output(None) == []
def test_compiler_output(tree): tree.children = [Token('token', 'output')] result = Compiler.output(tree) assert result == ['output']