def test_declaration_asjson(as3d_interface1, as3d_interface2): assert isinstance(as3d_interface1.declaration_asjson, str) assert format_json(as3d_interface1.declaration_asjson) == format_json( mock_declaration) assert isinstance(as3d_interface2.declaration_asjson, str) assert format_json(as3d_interface2.declaration_asjson) == format_json( mock_declaration2)
def test_yaml_simple_longoptions(fixture_clicker): """ python3 -mas3ninja transform --configuration-file examples/simple/ninja.yaml --declaration-template examples/simple/template.j2 """ result = fixture_clicker.invoke( cli, [ "transform", "--configuration-file", "examples/simple/ninja.yaml", "--declaration-template", "examples/simple/template.j2", ], ) assert result.exit_code == 0 assert format_json(result.output) == format_json( load_file("examples/simple/declaration.json"))
def test_yaml_datatypes(fixture_clicker): """ python3 -mas3ninja transform --no-validate -c examples/yaml_datatypes/config.yaml -t examples/yaml_datatypes/template.j2 """ result = fixture_clicker.invoke( cli, [ "transform", "--no-validate", "-c", "examples/yaml_datatypes/config.yaml", "-t", "examples/yaml_datatypes/template.j2", ], ) assert result.exit_code == 0 assert format_json(result.output) == format_json( load_file("examples/yaml_datatypes/output.json"))
def test_ninjutsu(self): declaration_template: str = """{ {% set myns = namespace() -%} {% set myns.var = "some value" -%} {{ninja.bfile | readfile | ninjutsu}} }""" template_configuration: dict = { "a": "from_config", "bfile": "tests/testdata/filters/ninjutsu.j2", } expected_result = '{"from_config": "from_config", "from_context": "some value"}' env = self._get_env( declaration_template=declaration_template, template_configuration=template_configuration, ) result = env.get_template("template").render() assert format_json(result) == format_json(expected_result)
def test_yaml_simple_configoverlay(fixture_clicker): """ python3 -mas3ninja transform -c examples/simple/ninja.yaml -c examples/simple/overlay.json -t examples/simple/template.j2 """ result = fixture_clicker.invoke( cli, [ "transform", "-c", "examples/simple/ninja.yaml", "-c", "examples/simple/overlay.json", "-t", "examples/simple/template.j2", ], ) assert result.exit_code == 0 assert format_json(result.output) == format_json( load_file("examples/simple/declaration_with_overlay.json"))
def test_yaml_simple_outputfile(fixture_tmpdir, fixture_clicker): """ python3 -mas3ninja transform -c examples/simple/ninja.yaml -t examples/simple/template.j2 -o /tmp/output.json """ tmpdir = fixture_tmpdir result = fixture_clicker.invoke( cli, [ "transform", "-c", "examples/simple/ninja.yaml", "-t", "examples/simple/template.j2", "-o", f"{tmpdir}/output.json", ], ) assert result.exit_code == 0 assert format_json(load_file(f"{tmpdir}/output.json")) == format_json( load_file("examples/simple/declaration.json"))
def test_declaration_template_file_in_configuration(): as3d = AS3Declaration( template_configuration=mock_template_configuration_with_template) assert isinstance(as3d.declaration, dict) assert format_json( as3d.declaration_asjson) == format_json(mock_declaration2)