Пример #1
0
 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"
Пример #2
0
    def test_remove_schema(self, template):
        expected_result = {"foo": "bar"}

        as3d = AS3Declaration(
            declaration_template=template,
            template_configuration={},
        )
        assert as3d.dict() == expected_result
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
    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
Пример #6
0
 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)
Пример #7
0
    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)
Пример #8
0
    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
Пример #9
0
def as3d_interface2():
    d = AS3Declaration(
        declaration_template=mock_declaration_template2,
        template_configuration=mock_template_configuration2,
    )
    return d
Пример #10
0
 def test_simple():
     as3d = AS3Declaration(
         declaration_template=mock_declaration_template,
         template_configuration=mock_template_configuration,
     )
     assert as3d.declaration["a"] == "aaa"
Пример #11
0
 def test_fail_empty_init():
     with pytest.raises(TypeError):
         AS3Declaration()
Пример #12
0
 def test_missing_declaration_template_in_configuration():
     with pytest.raises(KeyError):
         AS3Declaration(template_configuration=mock_template_configuration)
Пример #13
0
 def test_missing_template_configuration():
     with pytest.raises(TypeError):
         AS3Declaration(declaration_template=mock_declaration_template)
Пример #14
0
 def test_declaration_template_in_configuration_inline():
     with pytest.raises(ValueError):
         AS3Declaration(template_configuration=
                        mock_template_configuration_with_template_inline)
Пример #15
0
 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)
Пример #16
0
def as3d_empty():
    return AS3Declaration(
        declaration_template='{"json": true}',
        template_configuration={"non empty": "dict"},
    )