コード例 #1
0
def test_get_user_defined_engine():
    test_fixture = fs.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)
コード例 #2
0
def test_custom_file_extension_is_assocated_with_user_defined_engine():
    test_fixture = fs.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)
コード例 #3
0
def test_built_in_jinja2_file_extension_still_works():
    test_fixture = fs.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)
コード例 #4
0
def handle_custom_extensions(list_of_definitions):
    user_extensions = defaultdict(set)
    if list_of_definitions:
        for definition in list_of_definitions:
            key, value = definition.split("=")
            user_extensions[key].add(value)
    ENGINES.register_extensions(user_extensions)
コード例 #5
0
def handle_command_line(options):
    """
    act upon command options
    """
    options = data_loader.merge(options, constants.DEFAULT_OPTIONS)
    engine = ENGINES.get_engine(
        options[constants.LABEL_TEMPLATE_TYPE],
        options[constants.LABEL_TMPL_DIRS],
        options[constants.LABEL_CONFIG_DIR],
    )
    if options[constants.LABEL_TEMPLATE] is None:
        content = options[constants.POSITIONAL_LABEL_TEMPLATE]
        if content is None:
            if not sys.stdin.isatty() and sys.platform != "win32":
                content = sys.stdin.read().strip()
        if content is None:
            raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE)

        engine.render_string_to_file(
            content,
            options[constants.LABEL_CONFIG],
            options[constants.LABEL_OUTPUT],
        )
    else:
        engine.render_to_file(
            options[constants.LABEL_TEMPLATE],
            options[constants.LABEL_CONFIG],
            options[constants.LABEL_OUTPUT],
        )
    engine.report()
    hashstore.HASH_STORE.save_hashes()
    exit_code = reporter.convert_to_shell_exit_code(
        engine.number_of_templated_files())
    return exit_code
コード例 #6
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_string_template():
    output = "test.txt"
    path = fs.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)
コード例 #7
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_nested_global_template_variables():
    output = "test.txt"
    path = fs.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)
コード例 #8
0
def test_handlebars_file_tests():
    output = "test.txt"
    path = os.path.join("tests", "fixtures", "handlebars_tests")
    engine = ENGINES.get_engine("hbs", [path], path)
    engine.render_to_file("file_tests.template", "file_tests.json", output)
    with open(output, "r") as output_file:
        content = output_file.read()
        eq_(content, "here")
    os.unlink(output)
コード例 #9
0
def test_do_templates_with_more_shared_data():
    base_dir = fs.path.join("tests", "fixtures")
    engine = ENGINES.get_engine("jinja2", base_dir,
                                fs.path.join(base_dir, "config"))
    engine._render_with_finding_data_first(
        {fs.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")
コード例 #10
0
def test_velocity_string_template():
    string_template = "Hello $hello"
    output = "test.txt"
    path = os.path.join("tests", "fixtures", "velocity_tests")
    engine = ENGINES.get_engine("velocity", [path], path)
    engine.render_string_to_file(string_template, "file_tests.json", output)
    with open(output, "r") as output_file:
        expected = "Hello World!"
        content = output_file.read()
        eq_(content, expected)
    os.unlink(output)
コード例 #11
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_render_string_to_file():
    output = "test.txt"
    path = fs.path.join("tests", "fixtures", "jinja_tests")
    engine = ENGINES.get_engine("jinja2", [path], path)
    engine.render_string_to_file("{{test}}", "file_tests.yml", output)
    with open(output, "r") as output_file:
        content = output_file.read()
        eq_(content, "here")
    eq_(engine.file_count, 1)
    eq_(engine.templated_count, 1)
    os.unlink(output)
コード例 #12
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_environ_variables_as_data():
    test_var = "TEST_ENVIRONMENT_VARIABLE"
    test_value = "foo"
    os.environ[test_var] = test_value
    output = "test.txt"
    path = fs.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)
コード例 #13
0
def test_velocity_file_test():
    output = "test.txt"
    path = os.path.join("tests", "fixtures", "velocity_tests")
    engine = ENGINES.get_engine("velocity", [path], path)
    engine.render_to_file("file_tests.velocity", "file_tests.json", output)
    with open(output, "r") as output_file:
        expected_path = os.path.join("tests", "fixtures", "velocity_tests",
                                     "expected_output.txt")
        with open(expected_path) as expected_file:
            expected = expected_file.read()
            content = output_file.read()
            eq_(content, expected)
    os.unlink(output)
コード例 #14
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)
コード例 #15
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)
コード例 #16
0
ファイル: test_copy_engine.py プロジェクト: pgajdos/moban
 def setUp(self):
     template_path = fs.path.join("tests", "fixtures")
     template_fs = file_system.get_multi_fs([template_path])
     ContentForwardEngine = ENGINES.load_me_now("copy")
     self.engine = ContentForwardEngine(template_fs)
コード例 #17
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_default_template_type():
    engine = ENGINES.get_engine("jj2", [], "")
    assert engine.engine.__class__ == Engine
コード例 #18
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_default_mako_type(_):  # fake mako
    engine = ENGINES.get_engine("fake", [], "")
    assert engine.engine.__class__ == FakeEngine
コード例 #19
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_unknown_template_type():
    ENGINES.get_engine("unknown_template_type", [], "")
コード例 #20
0
ファイル: test_moban_factory.py プロジェクト: pgajdos/moban
def test_non_existent_tmpl_directries():
    ENGINES.get_engine("jj2", "idontexist", "")
コード例 #21
0
def test_handlebars_template_type():
    engine = ENGINES.get_engine("hbs", [], "")
    assert engine.engine.__class__.__name__ == "EngineHandlebars"
コード例 #22
0
def test_velocity_engine_type():
    engine = ENGINES.get_engine("velocity", [], "")
    assert engine.engine.__class__.__name__ == "EngineVelocity"