def test_compiler_compile(patch, magic): patch.many(JSONCompiler, ['parse_tree']) patch.object(Lines, 'entrypoint') tree = magic() result = JSONCompiler(story=None).compile(tree) JSONCompiler.parse_tree.assert_called_with(tree) lines = JSONCompiler(story=None).lines expected = {'tree': lines.lines, 'version': version, 'services': lines.get_services(), 'functions': lines.functions, 'entrypoint': lines.entrypoint()} assert result == expected
def test_compiler_compile(patch, magic): patch.many(JSONCompiler, ["parse_tree"]) patch.object(Lines, "entrypoint") tree = magic() result = JSONCompiler(story=None).compile(tree) JSONCompiler.parse_tree.assert_called_with(tree) lines = JSONCompiler(story=None).lines expected = { "tree": lines.lines, "version": version, "services": lines.get_services(), "functions": lines.functions, "entrypoint": lines.entrypoint(), } assert result == expected
def test_compiler_chained_mutations(patch, magic, tree): patch.object(Objects, 'mutation_fragment') mutation = magic() tree.find_data.return_value = [mutation] result = JSONCompiler(story=None).chained_mutations(tree) Objects.mutation_fragment.assert_called_with(mutation.mutation_fragment) assert result == [Objects.mutation_fragment()]
def test_compiler_extract_values(patch, tree): patch.object(Objects, 'entity') tree.expression = None result = JSONCompiler(story=None).extract_values(tree) tree.child.assert_called_with(1) Objects.entity.assert_called_with(tree.child()) assert result == [Objects.entity()]
def test_compiler_extract_values_mutation(patch, tree): patch.many(Objects, ['values', 'mutation_fragment']) result = JSONCompiler(story=None).extract_values(tree) Objects.values.assert_called_with(tree.expression.values) Objects.mutation_fragment.assert_called_with(tree.expression.mutation) assert result == [Objects.values(), Objects.mutation_fragment()]
def test_compiler_extract_values_expression(patch, tree): patch.object(Objects, 'expression') tree.expression.mutation = None result = JSONCompiler(story=None).extract_values(tree) Objects.expression.assert_called_with(tree.expression) assert result == [Objects.expression()]
def test_compiler_init(patch): patch.init(Lines) compiler = JSONCompiler(story=None) assert isinstance(compiler.lines, Lines)
def compiler(patch, lines): patch.init(Lines) compiler = JSONCompiler(story=None) compiler.lines = lines return compiler