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)
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)
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)
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)
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")
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)
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)
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)
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_haml_engine_type(): engine = ENGINES.get_engine("haml", [], "") assert engine.engine_cls == EngineHaml pass
def test_unknown_template_type(): ENGINES.get_engine("unknown_template_type", [], "")
def test_default_mako_type(_): # fake mako engine = ENGINES.get_engine("fake", [], "") assert engine.engine_cls.__name__ == "FakeEngine"
def test_default_template_type(): engine = ENGINES.get_engine("jj2", [], "") assert engine.engine_cls == Engine
def test_default_mako_type(_): # fake mako engine = ENGINES.get_engine("fake", [], "") assert engine.engine.__class__ == FakeEngine
def test_template_toolkit_eninge_type(): engine = ENGINES.get_engine("template_toolkit", [], "") assert engine.engine_cls == EngineTemplateToolkit
def test_default_mako_type(): # fake mako engine = ENGINES.get_engine("mako", [], "") assert engine.engine_cls.__name__ == "MakoEngine"
def test_handlebars_template_type(): engine = ENGINES.get_engine("hbs", [], "") assert engine.engine_cls == EngineHandlebars