def test_tuple_dict(): data = ({"deserialized json": True}, {"deserialized yaml": True}) AS3TemplateConfiguration(data)
def test_list_dict(): data = [{"deserialized json": True}, {"deserialized yaml": True}] AS3TemplateConfiguration(data)
def test_str_globbing(): data = "tests/testdata/AS3TemplateConfiguration/file.*" AS3TemplateConfiguration(data)
def test_dict(): data = {"deserialized": True} AS3TemplateConfiguration(data)
def test_fail_globbing_notfile(): data = "tests/testdata/AS3TemplateConfiguration*" with pytest.raises(AS3TemplateConfigurationError): AS3TemplateConfiguration(data)
def test_str(): data = "tests/testdata/AS3TemplateConfiguration/file.yaml" AS3TemplateConfiguration(data)
def test_fail_file_missing(): data = "tests/testdata/AS3TemplateConfiguration/DOESNOTEXIST.yaml" with pytest.raises(AS3TemplateConfigurationError): AS3TemplateConfiguration(data)
def test_nofile(): """No configuration given, must load ninja.(json|yaml|yml) which doesnt exist""" with pytest.raises(AS3TemplateConfigurationError) as excInfo: AS3TemplateConfiguration(None) assert "No AS3 Ninja configuration file found" in str(excInfo.value)
def test_api_input_globbing_includes(): """Test complex input similar to what the API could see.""" JSON = """ { "template_configuration": [ {"inline_json": true}, "tests/testdata/AS3TemplateConfiguration/file.*", "tests/testdata/AS3TemplateConfiguration/include3.yaml", {"as3ninja": { "include": "tests/testdata/AS3TemplateConfiguration/include2.yaml" } }, "tests/testdata/AS3TemplateConfiguration/include1.yaml", "tests/testdata/AS3TemplateConfiguration/include3.yaml" ] } """ data = json.loads(JSON) as3tc = AS3TemplateConfiguration(**data) assert ( as3tc.dict()["inline_json"] is True ) # inline json is part of the configuration assert as3tc.dict()["file.yaml"] is True # file.* globbing includes file.yaml assert as3tc.dict()["file.json"] is True # file.* globbing includes file.json assert ( as3tc.dict()["include3.yaml"] is True ) # include3.yaml is part of the configuration assert ( as3tc.dict()["included3.yaml"] is True ) # included3.yaml is included by include3.yaml assert ( as3tc.dict()["include2.yaml"] is True ) # include2.yaml is part of the configuration but CANNOT include further files! # {"as3ninja": {"include": "../include2.yaml"}} is an include already and cannot # include further files: assert ( as3tc.dict().get("included2a.yaml", False) is False ) # nested includes are not supported assert ( as3tc.dict().get("included2b.yaml", False) is False ) # nested includes are not supported assert ( as3tc.dict().get("included2c.yaml", False) is False ) # nested includes are not supported assert ( as3tc.dict()["include1.yaml"] is True ) # include1.yaml is part of the configuration assert ( as3tc.dict()["included1.yaml"] is True ) # included1.yaml is included by include1.yaml and part of the configuration assert ( as3tc.dict()["data"] == "include3.yaml" ) # include3.yaml is the last included configuration, it does include further files # but these files have been included before, hence they are not included again # includes in perserved order assert as3tc.dict()["as3ninja"]["include"] == [ "tests/testdata/AS3TemplateConfiguration/included3.yaml", "tests/testdata/AS3TemplateConfiguration/include2.yaml", "tests/testdata/AS3TemplateConfiguration/included1.yaml", ]
def as3d_empty(): return AS3Declaration( declaration_template='{"json": true}', template_configuration=AS3TemplateConfiguration({"non empty": "dict"}), )
import json import pytest from jinja2.exceptions import TemplateSyntaxError from as3ninja.declaration import AS3Declaration from as3ninja.exceptions import ( AS3JSONDecodeError, AS3TemplateSyntaxError, AS3UndefinedError, ) from as3ninja.templateconfiguration import AS3TemplateConfiguration from tests.utils import fixture_tmpdir, format_json, load_file mock_template_configuration = AS3TemplateConfiguration({ "a": "aaa", "b": "bbb" }) mock_declaration_template: str = """{ "json": true, "a": "{{ninja.a}}", "b": "{{ninja.b}}" }""" mock_declaration: str = """{ "json": true, "a": "aaa", "b": "bbb" }""" mock_template_configuration2 = AS3TemplateConfiguration([ { "a": "aaa",