def test_templates_runnable_using_env(tmpdir): tmpl_filename = os.path.join(tmpdir.strpath, 'my_template.tmpl') tmpl_py_filename = os.path.join(tmpdir.strpath, 'my_template.py') with io.open(tmpl_filename, 'w') as template: template.write('$foo\n' '$bar\n') compile_template(tmpl_filename) ret = run_python(tmpl_py_filename, env={'foo': 'herp', 'bar': 'derp'}) assert ret.strip() == 'herp\nderp'
def test_templates_runnable_using_env(tmpdir): tmpl_filename = os.path.join(tmpdir.strpath, 'my_template.tmpl') tmpl_py_filename = os.path.join(tmpdir.strpath, 'my_template.py') with io.open(tmpl_filename, 'w') as template: template.write( '$foo\n' '$bar\n' ) compile_template(tmpl_filename) ret = run_python(tmpl_py_filename, env={'foo': 'herp', 'bar': 'derp'}) assert ret.strip() == 'herp\nderp'
def test_compile_multiple_files_by_directory(template_writer, tmpdir): tmpl1 = template_writer.write('foo') tmpl2 = template_writer.write('bar') compile_all([tmpdir.strpath]) assert run_python(tmpl1.replace('.tmpl', '.py')) == 'foo' assert run_python(tmpl2.replace('.tmpl', '.py')) == 'bar'
def test_compile_multiple_files(template_writer): tmpl1 = template_writer.write('foo') tmpl2 = template_writer.write('bar') compile_all([tmpl1, tmpl2]) assert run_python(tmpl1.replace('.tmpl', '.py')) == 'foo' assert run_python(tmpl2.replace('.tmpl', '.py')) == 'bar'
def _test_compile_template(tmpl_file): tmpl_py = compile_template(tmpl_file) assert os.path.exists(tmpl_py) ret = run_python(tmpl_py) assert ret == 'Hello world'