Exemple #1
0
def test_compile_file_destination(tmpfile, tmpdir):
    output_file = os.path.join(tmpdir.strpath, 'out.py')
    compile_file(tmpfile, target=output_file)
    assert os.path.exists(output_file)
    python_file_contents = io.open(output_file).read()
    assert 'class temp(' in python_file_contents
    assert "write('''Hello, world!''')" in python_file_contents
def test_compile_file_destination(tmpfile, tmpdir):
    output_file = os.path.join(tmpdir.strpath, 'out.py')
    compile_file(tmpfile, target=output_file)
    assert os.path.exists(output_file)
    python_file_contents = io.open(output_file).read()
    assert 'class YelpCheetahTemplate(' in python_file_contents
    assert "write('''Hello, world!''')" in python_file_contents
def test_non_utf8_raises_error(tmpfile):
    non_utf8_string = b'\x97\n'

    # Try and decode it
    with pytest.raises(UnicodeDecodeError):
        non_utf8_string.decode('UTF-8')

    with io.open(tmpfile, 'wb') as file_obj:
        file_obj.write(b'\x97\n')

    with pytest.raises(UnicodeDecodeError):
        compile_file(tmpfile)
Exemple #4
0
def test_non_utf8_raises_error(tmpfile):
    non_utf8_string = b'\x97\n'

    # Try and decode it
    with pytest.raises(UnicodeDecodeError):
        non_utf8_string.decode('UTF-8')

    with io.open(tmpfile, 'wb') as file_obj:
        file_obj.write(b'\x97\n')

    with pytest.raises(UnicodeDecodeError):
        compile_file(tmpfile)
def test_compile_file(tmpfile):
    compiled_python_file = compile_file(tmpfile)

    assert os.path.exists(compiled_python_file)
    python_file_contents = io.open(compiled_python_file).read()
    assert python_file_contents.splitlines()[0] == '# -*- coding: UTF-8 -*-'
    assert 'class YelpCheetahTemplate(' in python_file_contents
Exemple #6
0
def test_compile_file(tmpfile):
    compiled_python_file = compile_file(tmpfile)

    assert os.path.exists(compiled_python_file)
    python_file_contents = io.open(compiled_python_file).read()
    assert python_file_contents.splitlines()[0] == '# -*- coding: UTF-8 -*-'
    assert 'class temp(' in python_file_contents
def compile_template(filename, **kwargs):
    if not isinstance(filename, six.text_type):
        filename = filename.decode('UTF-8')
    print('Compiling {}'.format(filename))
    return compile_file(filename, **kwargs)
def test_compile_file_returns_target(tmpfile):
    ret = compile_file(tmpfile)
    assert ret == os.path.splitext(tmpfile)[0] + '.py'
def test_compile_file_filename_requires_text():
    with pytest.raises(TypeError):
        compile_file(b'not_text.tmpl')
Exemple #10
0
def compile_template(filename, **kwargs):
    if not isinstance(filename, five.text):
        filename = filename.decode('UTF-8')
    print('Compiling {0}'.format(filename))
    return compile_file(filename, **kwargs)
Exemple #11
0
def test_compile_file_complains_when_cls_name_is_specified():
    with pytest.raises(ValueError):
        compile_file('temp.tmpl', cls_name='foo')
Exemple #12
0
def test_compile_file_filename_requires_text():
    with pytest.raises(TypeError):
        compile_file(b'not_text.tmpl')
Exemple #13
0
def test_compile_file_returns_target(tmpfile):
    ret = compile_file(tmpfile)
    assert ret == os.path.splitext(tmpfile)[0] + '.py'