Пример #1
0
def render_directory(srcdir, dstdir, context, directory, recursive=False):
    templatedir = os.path.join(TEST_TEMPLATE_PATH, directory, "templates")
    rendereddir = os.path.join(TEST_TEMPLATE_PATH, directory, "rendered")

    copy_tree(templatedir, srcdir)

    if recursive:
        args = cli.parse_arguments(['-r', '-o', srcdir, dstdir])
    else:
        args = cli.parse_arguments(['-o', srcdir, dstdir])

    cli.render(srcdir, dstdir,
               cli.build_template_context(context),
               args)

    return templatedir, rendereddir
Пример #2
0
def test_filter_base64(common_environment):
    tmpfile = NamedTemporaryFile()
    templateFile = os.path.join(TEST_TEMPLATE_PATH, os.path.join("filters", "base64.jinja"))

    cli.render(templateFile, tmpfile.name,
               cli.build_template_context(common_environment),
               cli.parse_arguments(['-o', tmpfile.name, templateFile]))

    output = open(tmpfile.name)

    assert output.read().strip() == """CAMEL_CASE_VARIABLE_ENCODED=aGFuZGxldGhpc3Rvbw==
Пример #3
0
def test_extensions(common_environment):
    tmpfile = NamedTemporaryFile()
    templateFile = os.path.join(TEST_TEMPLATE_PATH, "extensions.jinja")
    cli.render(templateFile, tmpfile.name,
               cli.build_template_context(common_environment),
               cli.parse_arguments(['-o', tmpfile.name, templateFile]))

    output = open(tmpfile.name)
    assert output.read() == "en_US.UTF-8"
    output.close()
    tmpfile.close()
Пример #4
0
def test_error(common_environment, capsys):
    tmpfile = NamedTemporaryFile()
    templateFile = os.path.join(TEST_TEMPLATE_PATH, "error.jinja")

    with pytest.raises(TemplateSyntaxError):
        cli.render(templateFile, tmpfile.name,
                   cli.build_template_context(common_environment),
                   cli.parse_arguments(['-o', tmpfile.name, templateFile]))

    captured = capsys.readouterr()
    assert "error.jinja" in captured.err
    assert " 9: >>" in captured.err
Пример #5
0
def test_filter_boolean(common_environment):
    tmpfile = NamedTemporaryFile()
    templateFile = os.path.join(TEST_TEMPLATE_PATH, os.path.join("filters", "boolean.jinja"))

    cli.render(templateFile, tmpfile.name,
               cli.build_template_context(common_environment),
               cli.parse_arguments(['-o', tmpfile.name, templateFile]))

    output = open(tmpfile.name)
    lines = output.readlines()

    for num, line in enumerate(lines, start=1):
        assert len(line) == 0 or line.strip() == 'cool', ("test %d should have been truthy" % num)
Пример #6
0
def test_filter_readfile(common_environment):
    tmpfile = NamedTemporaryFile()
    test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  'templates', 'test.data')
    context = cli.build_template_context(dict(common_environment,
                                              TEST_DATA_PATH=test_data_path))
    templateFile = os.path.join(TEST_TEMPLATE_PATH, os.path.join("filters", "readfile.jinja"))

    cli.render(templateFile, tmpfile.name, context,
               cli.parse_arguments(['-o', tmpfile.name, templateFile]))

    output = open(tmpfile.name)
    assert output.read() == "TEST DATA\n"
Пример #7
0
def test_simple_template(common_environment, common_rendered):
    # The tmp_path fixture is not relaible across Python versions.
    # Do this ourselves.
    tmpfile = NamedTemporaryFile()
    templateFile = os.path.join(TEST_TEMPLATE_PATH, "simple.jinja")
    cli.render(templateFile, tmpfile.name,
               cli.build_template_context(common_environment),
               cli.parse_arguments(['-o', tmpfile.name, templateFile]))

    output = open(tmpfile.name)
    assert output.read().strip() == common_rendered
    output.close()
    tmpfile.close()
Пример #8
0
def test_include(common_environment, common_rendered):
    tmpfile = NamedTemporaryFile()
    templateFile = os.path.join(TEST_TEMPLATE_PATH, "include.jinja")
    cli.render(templateFile, tmpfile.name,
               cli.build_template_context(common_environment),
               cli.parse_arguments(['-o', tmpfile.name,
                                    '-b', os.path.join(
                                        os.path.dirname(__file__), 'templates'),
                                    templateFile]))

    output = open(tmpfile.name)
    assert output.read().strip() == "top\n" + common_rendered
    output.close()
    tmpfile.close()
Пример #9
0
def test_undefined(common_environment):
    tmpfile = NamedTemporaryFile()
    templateFile = os.path.join(TEST_TEMPLATE_PATH, "undefined.jinja")
    cli.render(templateFile, tmpfile.name,
               cli.build_template_context(common_environment),
               cli.parse_arguments(['-o', tmpfile.name, templateFile]))

    output = open(tmpfile.name)
    assert """7
term -> program -> foo(X)
term -> foo(X) -> bar
foo(X) -> bar -> baz



term -> foo is not defined
term -> foo -> bar is not defined""" == output.read()