Ejemplo n.º 1
0
def test_compile_file_as_script(tmpfile):
    subprocess.check_call(['cheetah-compile', tmpfile])
    pyfile = tmpfile.replace('.tmpl', '.py')
    module = _create_module_from_source(
        '\n'.join(io.open(pyfile).read().splitlines()[1:])
    )
    result = module.YelpCheetahTemplate().respond()
    assert 'Hello, world!' == result
Ejemplo n.º 2
0
def test_compile_file_as_script(tmpfile):
    subprocess.check_call(['cheetah-compile', tmpfile])
    pyfile = tmpfile.replace('.tmpl', '.py')
    module = _create_module_from_source(
        '\n'.join(io.open(pyfile).read().splitlines()[1:])
    )
    result = module.temp().respond()
    assert 'Hello, world!' == result
Ejemplo n.º 3
0
def test_create_module_from_source():
    my_module_source = textwrap.dedent(
        '''
        MODULE_CONSTANT = 9001


        def snowman_pls():
            return u'☃'


        def multiple_snowmans(i):
            return i * snowman_pls()
        '''
    )

    module = _create_module_from_source(my_module_source)
    assert module.MODULE_CONSTANT == 9001
    assert module.snowman_pls() == '☃'
    assert module.multiple_snowmans(3) == '☃☃☃'
Ejemplo n.º 4
0
def test_create_module_from_source():
    my_module_source = textwrap.dedent(
        '''
        MODULE_CONSTANT = 9001


        def snowman_pls():
            return u'☃'


        def multiple_snowmans(i):
            return i * snowman_pls()
        '''
    )

    module = _create_module_from_source(my_module_source)
    assert module.MODULE_CONSTANT == 9001
    assert module.snowman_pls() == '☃'
    assert module.multiple_snowmans(3) == '☃☃☃'
Ejemplo n.º 5
0
def test_template_exposes_global():
    src = compile_source('Hello World')
    module = _create_module_from_source(src)
    assert module.__YELP_CHEETAH__ is True