def test_simple_list(): as3d = AS3Declaration( declaration_template=mock_declaration_template2, template_configuration=mock_template_configuration2, ) assert as3d.declaration["a"] == "AAA" assert as3d.declaration["c"] == "CCC"
def test_remove_schema(self, template): expected_result = {"foo": "bar"} as3d = AS3Declaration( declaration_template=template, template_configuration={}, ) assert as3d.dict() == expected_result
def test_invalid_jinja_template_syntax(): template: str = """{ "a": "{{ninja.a}}" {% if ninja.b %} ,"b": "{{ninja.b}}" } """ config = {"a": "aaa", "b": "bbb"} with pytest.raises(AS3TemplateSyntaxError): AS3Declaration(declaration_template=template, template_configuration=config)
def test_invalid_json(): template: str = """{ "json": "this json template is invalid, the comma after b will throw a decode exception", "a": "{{ninja.a}}", "b": "{{ninja.b}}", } """ config = {"a": "aaa", "b": "bbb"} with pytest.raises(AS3JSONDecodeError): as3d = AS3Declaration(declaration_template=template, template_configuration=config)
def test_file_include_no_jinja2_searchpath(): template = """{ "main": "{{ninja.main}}", "include": {% include 'tests/testdata/declaration/transform/include.j2' %} }""" configuration = {"main": "MAIN", "include": "INCLUDE"} expected_result = {"main": "MAIN", "include": {"include": "INCLUDE"}} as3d = AS3Declaration(declaration_template=template, template_configuration=configuration) assert as3d.declaration == expected_result
def test_missing_jinja_variable(): template: str = """{ "json": "this json template is invalid, the comma after b will throw a decode exception", "a": "{{ninja.a}}" {% if this_is_a_variable %} ,"b": "{{ninja.b}}" {% endif %} } """ config = {"a": "aaa", "b": "bbb"} with pytest.raises(AS3UndefinedError): AS3Declaration(declaration_template=template, template_configuration=config)
def test_multi_template_syntax_error(): """https://github.com/simonkowallik/as3ninja/issues/4""" template = """{ "include": {% include './include.jinja2' %} }""" with pytest.raises(AS3TemplateSyntaxError) as exc: _ = AS3Declaration( declaration_template=template, template_configuration={}, jinja2_searchpath="tests/testdata/declaration/syntax_error/", ) assert "{% This line raises a Syntax Error %}<---- Error line:2" in str( exc.value)
def test_file_include_searchpath_configlist(): template = """{ "main": "{{ninja.main}}", "include": {% include './include.j2' %} }""" configuration = [{ "main": "MAIN", "include": "NONE" }, { "include": "INCLUDE" }] expected_result = {"main": "MAIN", "include": {"include": "INCLUDE"}} as3d = AS3Declaration( declaration_template=template, template_configuration=configuration, jinja2_searchpath="tests/testdata/declaration/transform/", ) assert as3d.declaration == expected_result
def as3d_interface2(): d = AS3Declaration( declaration_template=mock_declaration_template2, template_configuration=mock_template_configuration2, ) return d
def test_simple(): as3d = AS3Declaration( declaration_template=mock_declaration_template, template_configuration=mock_template_configuration, ) assert as3d.declaration["a"] == "aaa"
def test_fail_empty_init(): with pytest.raises(TypeError): AS3Declaration()
def test_missing_declaration_template_in_configuration(): with pytest.raises(KeyError): AS3Declaration(template_configuration=mock_template_configuration)
def test_missing_template_configuration(): with pytest.raises(TypeError): AS3Declaration(declaration_template=mock_declaration_template)
def test_declaration_template_in_configuration_inline(): with pytest.raises(ValueError): AS3Declaration(template_configuration= mock_template_configuration_with_template_inline)
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)
def as3d_empty(): return AS3Declaration( declaration_template='{"json": true}', template_configuration={"non empty": "dict"}, )