本文整理汇总了Python中test.util.result_lines函数的典型用法代码示例。如果您正苦于以下问题:Python result_lines函数的具体用法?Python result_lines怎么用?Python result_lines使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了result_lines函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_utf8_format_exceptions_pygments
def test_utf8_format_exceptions_pygments(self):
"""test that htmlentityreplace formatting is applied to
exceptions reported with format_exceptions=True"""
l = TemplateLookup(format_exceptions=True)
if compat.py3k:
l.put_string("foo.html", """# -*- coding: utf-8 -*-\n${'привет' + foobar}""")
else:
l.put_string("foo.html", """# -*- coding: utf-8 -*-\n${u'привет' + foobar}""")
if compat.py3k:
assert '<table class="error syntax-highlightedtable"><tr><td '\
'class="linenos"><div class="linenodiv"><pre>2</pre>'\
'</div></td><td class="code"><div class="error '\
'syntax-highlighted"><pre><span class="cp">${</span>'\
'<span class="s">'привет'</span> <span class="o">+</span> '\
'<span class="n">foobar</span><span class="cp">}</span>'\
'<span class="x"></span>' in \
result_lines(l.get_template("foo.html").render().decode('utf-8'))
else:
assert '<table class="error syntax-highlightedtable"><tr><td '\
'class="linenos"><div class="linenodiv"><pre>2</pre>'\
'</div></td><td class="code"><div class="error '\
'syntax-highlighted"><pre><span class="cp">${</span>'\
'<span class="s">u'прив'\
'ет'</span> <span class="o">+</span> '\
'<span class="n">foobar</span><span class="cp">}</span>'\
'<span class="x"></span>' in \
result_lines(l.get_template("foo.html").render().decode('utf-8'))
示例2: test_strict
def test_strict(self):
t = Template("""
% if x is UNDEFINED:
undefined
% else:
x: ${x}
% endif
""", strict_undefined=True)
assert result_lines(t.render(x=12)) == ['x: 12']
assert_raises(
NameError,
t.render, y=12
)
l = TemplateLookup(strict_undefined=True)
l.put_string("a", "some template")
l.put_string("b", """
<%namespace name='a' file='a' import='*'/>
% if x is UNDEFINED:
undefined
% else:
x: ${x}
% endif
""")
assert result_lines(t.render(x=12)) == ['x: 12']
assert_raises(
NameError,
t.render, y=12
)
示例3: test_dynamic_key_with_funcargs
def test_dynamic_key_with_funcargs(self):
t = Template("""
<%def name="foo(num=5)" cached="True" cache_key="foo_${str(num)}">
hi
</%def>
${foo()}
""")
m = self._install_mock_cache(t)
t.render()
t.render()
assert result_lines(t.render()) == ['hi']
assert m.key == "foo_5"
t = Template("""
<%def name="foo(*args, **kwargs)" cached="True"
cache_key="foo_${kwargs['bar']}">
hi
</%def>
${foo(1, 2, bar='lala')}
""")
m = self._install_mock_cache(t)
t.render()
assert result_lines(t.render()) == ['hi']
assert m.key == "foo_lala"
t = Template('''
<%page args="bar='hi'" cache_key="foo_${bar}" cached="True"/>
hi
''')
m = self._install_mock_cache(t)
t.render()
assert result_lines(t.render()) == ['hi']
assert m.key == "foo_hi"
示例4: test_interpret_expression_from_arg_two
def test_interpret_expression_from_arg_two(self):
"""test that cache_key=${foo} gets its value from
the 'foo' argument regardless of it being passed
from the context.
This is here testing that there's no change
to existing behavior before and after #191.
"""
t = Template("""
<%def name="layout(foo)" cached="True" cache_key="${foo}">
foo: ${value}
</%def>
${layout(3)}
""", cache_impl="plain")
eq_(
result_lines(t.render(foo='foo', value=1)),
["foo: 1"]
)
eq_(
result_lines(t.render(foo='bar', value=2)),
["foo: 1"]
)
示例5: test_pageargs
def test_pageargs(self):
collection = lookup.TemplateLookup()
collection.put_string("base", """
this is the base.
<%
sorted_ = pageargs.items()
sorted_ = sorted(sorted_)
%>
pageargs: (type: ${type(pageargs)}) ${sorted_}
<%def name="foo()">
${next.body(**context.kwargs)}
</%def>
${foo()}
""")
collection.put_string("index", """
<%inherit file="base"/>
<%page args="x, y, z=7"/>
print ${x}, ${y}, ${z}
""")
if compat.py3k:
assert result_lines(collection.get_template('index').render_unicode(x=5,y=10)) == [
"this is the base.",
"pageargs: (type: <class 'dict'>) [('x', 5), ('y', 10)]",
"print 5, 10, 7"
]
else:
assert result_lines(collection.get_template('index').render_unicode(x=5,y=10)) == [
"this is the base.",
"pageargs: (type: <type 'dict'>) [('x', 5), ('y', 10)]",
"print 5, 10, 7"
]
示例6: test_module_roundtrip
def test_module_roundtrip(self):
lookup = TemplateLookup()
template = Template("""
<%inherit file="base.html"/>
% for x in range(5):
${x}
% endfor
""", lookup=lookup)
base = Template("""
This is base.
${self.body()}
""", lookup=lookup)
lookup.put_template("base.html", base)
lookup.put_template("template.html", template)
assert result_lines(template.render()) == [
"This is base.", "0", "1", "2", "3", "4"
]
lookup = TemplateLookup()
template = ModuleTemplate(template.module, lookup=lookup)
base = ModuleTemplate(base.module, lookup=lookup)
lookup.put_template("base.html", base)
lookup.put_template("template.html", template)
assert result_lines(template.render()) == [
"This is base.", "0", "1", "2", "3", "4"
]
示例7: test_dynamic_key_with_context
def test_dynamic_key_with_context(self):
t = Template(
"""
<%block name="foo" cached="True" cache_key="${mykey}">
some block
</%block>
"""
)
m = self._install_mock_cache(t)
t.render(mykey="thekey")
t.render(mykey="thekey")
eq_(result_lines(t.render(mykey="thekey")), ["some block"])
eq_(m.key, "thekey")
t = Template(
"""
<%def name="foo()" cached="True" cache_key="${mykey}">
some def
</%def>
${foo()}
"""
)
m = self._install_mock_cache(t)
t.render(mykey="thekey")
t.render(mykey="thekey")
eq_(result_lines(t.render(mykey="thekey")), ["some def"])
eq_(m.key, "thekey")
示例8: test_render
def test_render(self):
assert result_lines(tl.render({}, template='/index.html')) == [
"this is index"
]
assert result_lines(tl.render({}, template=compat.u('/index.html'))) == [
"this is index"
]
示例9: test_undefined
def test_undefined(self):
t = Template("""
% if x is UNDEFINED:
undefined
% else:
x: ${x}
% endif
""")
assert result_lines(t.render(x=12)) == ["x: 12"]
assert result_lines(t.render(y=12)) == ["undefined"]
示例10: test_lookup
def test_lookup(self):
l = TemplateLookup(cache_impl='mock')
l.put_string("x", """
<%page cached="True" />
${y}
""")
t = l.get_template("x")
self._install_mock_cache(t)
assert result_lines(t.render(y=5)) == ["5"]
assert result_lines(t.render(y=7)) == ["5"]
assert isinstance(t.cache.impl, MockCacheImpl)
示例11: test_preprocess2
def test_preprocess2(self):
t = """
%call foo():
hi
%endcall
"""
s = """
<%call expr="foo()">
hi
</%call>
"""
t = convert_calls(t)
assert_equals(result_lines(t), result_lines(s))
示例12: test_preprocess
def test_preprocess(self):
t = """
% def foo():
hi
% enddef
"""
s = """
<%def name="foo()">
hi
</%def>
"""
t = convert_defs(t)
assert_equals(result_lines(t), result_lines(s))
示例13: test_invalidate
def test_invalidate(self):
t = Template("""
<%%def name="foo()" cached="True">
foo: ${x}
</%%def>
<%%def name="bar()" cached="True" cache_type='dbm' cache_dir='%s'>
bar: ${x}
</%%def>
${foo()} ${bar()}
""" % module_base)
self._install_mock_cache(t)
assert result_lines(t.render(x=1)) == ["foo: 1", "bar: 1"]
assert result_lines(t.render(x=2)) == ["foo: 1", "bar: 1"]
t.cache.invalidate_def('foo')
assert result_lines(t.render(x=3)) == ["foo: 3", "bar: 1"]
t.cache.invalidate_def('bar')
assert result_lines(t.render(x=4)) == ["foo: 3", "bar: 4"]
t = Template("""
<%%page cached="True" cache_type="dbm" cache_dir="%s"/>
page: ${x}
""" % module_base)
self._install_mock_cache(t)
assert result_lines(t.render(x=1)) == ["page: 1"]
assert result_lines(t.render(x=2)) == ["page: 1"]
t.cache.invalidate_body()
assert result_lines(t.render(x=3)) == ["page: 3"]
assert result_lines(t.render(x=4)) == ["page: 3"]
示例14: test_ccall_caller
def test_ccall_caller(self):
t = Template("""
<%def name="outer_func()">
OUTER BEGIN
<%call expr="caller.inner_func()">
INNER CALL
</%call>
OUTER END
</%def>
<%call expr="outer_func()">
<%def name="inner_func()">
INNER BEGIN
${caller.body()}
INNER END
</%def>
</%call>
""")
#print t.code
assert result_lines(t.render()) == [
"OUTER BEGIN",
"INNER BEGIN",
"INNER CALL",
"INNER END",
"OUTER END",
]
示例15: test_basic
def test_basic(self):
t = Template("""
<%!
cached = None
%>
<%def name="foo()">
<%
global cached
if cached:
return "cached: " + cached
__M_writer = context._push_writer()
%>
this is foo
<%
buf, __M_writer = context._pop_buffer_and_writer()
cached = buf.getvalue()
return cached
%>
</%def>
${foo()}
${foo()}
""")
assert result_lines(t.render()) == [
"this is foo",
"cached:",
"this is foo"
]