Exemple #1
0
def test_custom_file_extension_is_assocated_with_user_defined_engine():
    test_fixture = os.path.join("tests", "fixtures", "mobanengine",
                                "sample_template_type.yml")
    template_types = open_yaml(test_fixture)
    ENGINES.register_options(template_types["template_types"])
    template_type = ENGINES.get_primary_key("demo_file_suffix")
    eq_("custom_jinja", template_type)
Exemple #2
0
def test_get_user_defined_engine():
    test_fixture = os.path.join("tests", "fixtures", "mobanengine",
                                "sample_template_type.yml")
    template_types = open_yaml(test_fixture)
    ENGINES.register_options(template_types["template_types"])
    engine = ENGINES.get_engine("custom_jinja", ".", ".")
    eq_(engine.engine.__class__, Engine)
Exemple #3
0
def test_built_in_jinja2_file_extension_still_works():
    test_fixture = os.path.join("tests", "fixtures", "mobanengine",
                                "sample_template_type.yml")
    template_types = open_yaml(test_fixture)
    ENGINES.register_options(template_types["template_types"])
    template_type = ENGINES.get_primary_key("jj2")
    eq_("jinja2", template_type)
Exemple #4
0
def test_nested_global_template_variables():
    output = "test.txt"
    path = os.path.join("tests", "fixtures", "globals")
    engine = ENGINES.get_engine("jinja2", [path], path)
    engine.render_to_file("nested.template", "variables.yml", output)
    with open(output, "r") as output_file:
        content = output_file.read()
        eq_(content, "template: nested.template\ntarget: test.txt\nhere")
    os.unlink(output)
Exemple #5
0
def test_file_tests():
    output = "test.txt"
    path = os.path.join("tests", "fixtures", "jinja_tests")
    engine = ENGINES.get_engine("jinja2", [path], path)
    engine.render_to_file("file_tests.template", "file_tests.yml", output)
    with open(output, "r") as output_file:
        content = output_file.read()
        eq_(content, "yes\nhere")
    os.unlink(output)
Exemple #6
0
def test_string_template():
    output = "test.txt"
    path = os.path.join("tests", "fixtures")
    engine = ENGINES.get_engine("jinja2", [path], path)
    engine.render_string_to_file("{{simple}}", "simple.yaml", output)
    with open(output, "r") as output_file:
        content = output_file.read()
        eq_(content, "yaml")
    os.unlink(output)
Exemple #7
0
def test_do_templates_with_more_shared_data():
    base_dir = os.path.join("tests", "fixtures")
    engine = ENGINES.get_engine("jinja2", base_dir,
                                os.path.join(base_dir, "config"))
    engine._render_with_finding_data_first(
        {os.path.join(base_dir, "child.yaml"): [("a.jj2", "test")]})
    with open("test", "r") as f:
        content = f.read()
        assert content == "hello world ox"
    os.unlink("test")
Exemple #8
0
def test_environ_variables_as_data():
    test_var = "TEST_ENVIRONMENT_VARIABLE"
    test_value = "foo"
    os.environ[test_var] = test_value
    output = "test.txt"
    path = os.path.join("tests", "fixtures", "environ_vars_as_data")
    engine = ENGINES.get_engine("jinja2", [path], path)
    engine.render_to_file("test.template", "this_does_not_exist.yml", output)
    with open(output, "r") as output_file:
        content = output_file.read()
        eq_(content, "foo")
    os.unlink(output)
Exemple #9
0
def test_do_templates_2(_do_templates_with_more_shared_templates):
    jobs = [
        TemplateTarget("1.template", "data1.yml", "1.output"),
        TemplateTarget("1.template", "data2.yml", "2.output"),
        TemplateTarget("1.template", "data3.yml", "3.output"),
        TemplateTarget("1.template", "data4.yml", "4.output"),
        TemplateTarget("1.template", "data5.yml", "6.output"),
    ]
    expected = {
        "1.template": [
            ("data1.yml", "1.output"),
            ("data2.yml", "2.output"),
            ("data3.yml", "3.output"),
            ("data4.yml", "4.output"),
            ("data5.yml", "6.output"),
        ]
    }
    engine = ENGINES.get_engine("jinja2", ".", ".")
    engine.render_to_files(jobs)
    _do_templates_with_more_shared_templates.assert_called_with(expected)
Exemple #10
0
def test_do_templates_1(_do_templates_with_more_shared_data):
    jobs = [
        TemplateTarget("1.template", "data.yml", "1.output"),
        TemplateTarget("2.template", "data.yml", "2.output"),
        TemplateTarget("3.template", "data.yml", "3.output"),
        TemplateTarget("4.template", "data.yml", "4.output"),
        TemplateTarget("5.template", "data.yml", "6.output"),
    ]
    expected = {
        "data.yml": [
            ("1.template", "1.output"),
            ("2.template", "2.output"),
            ("3.template", "3.output"),
            ("4.template", "4.output"),
            ("5.template", "6.output"),
        ]
    }
    engine = ENGINES.get_engine("jinja2", ".", ".")
    engine.render_to_files(jobs)
    _do_templates_with_more_shared_data.assert_called_with(expected)
Exemple #11
0
def test_do_templates_1(_do_templates_with_more_shared_data):
    jobs = [
        ("1.template", "data.yml", "1.output"),
        ("2.template", "data.yml", "2.output"),
        ("3.template", "data.yml", "3.output"),
        ("4.template", "data.yml", "4.output"),
        ("5.template", "data.yml", "6.output"),
    ]
    expected = {
        "data.yml": [
            ("1.template", "1.output"),
            ("2.template", "2.output"),
            ("3.template", "3.output"),
            ("4.template", "4.output"),
            ("5.template", "6.output"),
        ]
    }
    engine = ENGINES.get_engine("jinja2", ".", ".")
    engine.render_to_files(jobs)
    _do_templates_with_more_shared_data.assert_called_with(expected)
    if os.path.exists(".moban.hashes"):
        os.unlink(".moban.hashes")
def test_handlebars_template_type():
    engine = ENGINES.get_engine("hbs", [], "")
    assert engine.engine_cls == EngineHandlebars
Exemple #13
0
def test_unknown_template_type():
    ENGINES.get_engine("unknown_template_type", [], "")
Exemple #14
0
def test_default_mako_type(_):  # fake mako
    engine = ENGINES.get_engine("fake", [], "")
    assert engine.engine_cls.__name__ == "FakeEngine"
Exemple #15
0
def test_default_template_type():
    engine = ENGINES.get_engine("jj2", [], "")
    assert engine.engine_cls == Engine
Exemple #16
0
def test_template_toolkit_eninge_type():
    engine = ENGINES.get_engine("template_toolkit", [], "")
    assert engine.engine_cls == EngineTemplateToolkit
Exemple #17
0
def test_haml_engine_type():
    engine = ENGINES.get_engine("haml", [], "")
    assert engine.engine_cls == EngineHaml
    pass
Exemple #18
0
def test_default_mako_type():  # fake mako
    engine = ENGINES.get_engine("mako", [], "")
    assert engine.engine_cls.__name__ == "MakoEngine"
Exemple #19
0
def test_default_mako_type(_):  # fake mako
    engine = ENGINES.get_engine("fake", [], "")
    assert engine.engine.__class__ == FakeEngine