本文整理汇总了Python中test.util.flatten_result函数的典型用法代码示例。如果您正苦于以下问题:Python flatten_result函数的具体用法?Python flatten_result怎么用?Python flatten_result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flatten_result函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nested_call_4
def test_nested_call_4(self):
base = """
<%def name="A()">
A_def
${caller.body()}
</%def>
<%def name="B()">
B_def
${caller.body()}
</%def>
"""
template = Template(base + """
<%def name="C()">
C_def
<%self:B>
<%self:A>
A_body
</%self:A>
B_body
${caller.body()}
</%self:B>
</%def>
<%self:C>
C_body
</%self:C>
""")
eq_(
flatten_result(template.render()),
"C_def B_def A_def A_body B_body C_body"
)
template = Template(base + """
<%def name="C()">
C_def
<%self:B>
B_body
${caller.body()}
<%self:A>
A_body
</%self:A>
</%self:B>
</%def>
<%self:C>
C_body
</%self:C>
""")
eq_(
flatten_result(template.render()),
"C_def B_def B_body C_body A_def A_body"
)
示例2: test_basic
def test_basic(self):
template = Template("""
<%page args="x, y, z=7"/>
this is page, ${x}, ${y}, ${z}
""")
assert flatten_result(template.render(x=5, y=10)) == "this is page, 5, 10, 7"
assert flatten_result(template.render(x=5, y=10, z=32)) == "this is page, 5, 10, 32"
assert_raises(TypeError, template.render, y=10)
示例3: test_builtins
def test_builtins(self):
t = Template("""
${"this is <text>" | h}
""")
assert flatten_result(t.render()) == "this is <text>"
t = Template("""
http://foo.com/arg1=${"hi! this is a string." | u}
""")
assert flatten_result(t.render()) == "http://foo.com/arg1=hi%21+this+is+a+string."
示例4: test_unicode_file_lookup
def test_unicode_file_lookup(self):
lookup = TemplateLookup(directories=[template_base], output_encoding="utf-8", default_filters=["decode.utf8"])
if compat.py3k:
template = lookup.get_template("/chs_unicode_py3k.html")
else:
template = lookup.get_template("/chs_unicode.html")
eq_(flatten_result(template.render_unicode(name="毛泽东")), u("毛泽东 是 新中国的主席<br/> Welcome 你 to 北京."))
示例5: test_overload
def test_overload(self):
collection = lookup.TemplateLookup()
collection.put_string('main.html', """
<%namespace name="comp" file="defs.html">
<%def name="def1(x, y)">
overridden def1 ${x}, ${y}
</%def>
</%namespace>
this is main. ${comp.def1("hi", "there")}
${comp.def2("there")}
""")
collection.put_string('defs.html', """
<%def name="def1(s)">
def1: ${s}
</%def>
<%def name="def2(x)">
def2: ${x}
</%def>
""")
assert flatten_result(collection.get_template('main.html').render()) == "this is main. overridden def1 hi, there def2: there"
示例6: test_scope_ten
def test_scope_ten(self):
t = Template("""
<%def name="a()">
<%def name="b()">
<%
y = 19
%>
b/c: ${c()}
b/y: ${y}
</%def>
<%def name="c()">
c/y: ${y}
</%def>
<%
# we assign to "y". but the 'enclosing
# scope' of "b" and "c" is from
# the "y" on the outside
y = 10
%>
a/y: ${y}
a/b: ${b()}
</%def>
<%
y = 7
%>
main/a: ${a()}
main/y: ${y}
""")
eq_(
flatten_result(t.render()),
"main/a: a/y: 10 a/b: b/c: c/y: 10 b/y: 19 main/y: 7"
)
示例7: test_scope_five
def test_scope_five(self):
"""test that variables are pulled from
'enclosing' scope before context."""
# same as test four, but adds a scope around it.
t = Template("""
<%def name="enclosing()">
<%
x = 5
%>
<%def name="a()">
this is a. x is ${x}.
</%def>
<%def name="b()">
<%
x = 9
%>
this is b. x is ${x}.
calling a. ${a()}
</%def>
${b()}
</%def>
${enclosing()}
""")
eq_(
flatten_result(t.render()),
"this is b. x is 9. calling a. this is a. x is 5."
)
示例8: test_scope_eight
def test_scope_eight(self):
"""test that the initial context counts
as 'enclosing' scope, for nested defs"""
t = Template("""
<%def name="enclosing()">
<%def name="a()">
a: x is ${x}
</%def>
<%def name="b()">
<%
x = 10
%>
b. x is ${x}. ${a()}
</%def>
${b()}
</%def>
${enclosing()}
""")
eq_(
flatten_result(t.render(x=5)),
"b. x is 10. a: x is 5"
)
示例9: test_inter_def
def test_inter_def(self):
"""test defs calling each other"""
template = Template("""
${b()}
<%def name="a()">\
im a
</%def>
<%def name="b()">
im b
and heres a: ${a()}
</%def>
<%def name="c()">
im c
</%def>
""")
# check that "a" is declared in "b", but not in "c"
if compat.py3k:
assert "a" not in template.module.render_c.__code__.co_varnames
assert "a" in template.module.render_b.__code__.co_varnames
else:
assert "a" not in template.module.render_c.func_code.co_varnames
assert "a" in template.module.render_b.func_code.co_varnames
# then test output
eq_(
flatten_result(template.render()),
"im b and heres a: im a"
)
示例10: test_outer_scope
def test_outer_scope(self):
t = Template("""
<%def name="a()">
a: x is ${x}
</%def>
<%def name="b()">
<%def name="c()">
<%
x = 10
%>
c. x is ${x}. ${a()}
</%def>
b. ${c()}
</%def>
${b()}
x is ${x}
""")
eq_(
flatten_result(t.render(x=5)),
"b. c. x is 10. a: x is 5 x is 5"
)
示例11: test_crlf
def test_crlf(self):
template = util.read_file(self._file_path("crlf.html"))
nodes = Lexer(template).parse()
self._compare(
nodes,
TemplateNode({}, [
Text('<html>\r\n\r\n', (1, 1)),
PageTag('page', {
'args': "a=['foo',\n 'bar']"
}, (3, 1), []),
Text('\r\n\r\nlike the name says.\r\n\r\n', (4, 26)),
ControlLine('for', 'for x in [1,2,3]:', False, (8, 1)),
Text(' ', (9, 1)),
Expression('x', [], (9, 9)),
ControlLine('for', 'endfor', True, (10, 1)),
Text('\r\n', (11, 1)),
Expression("trumpeter == 'Miles' and "
"trumpeter or \\\n 'Dizzy'",
[], (12, 1)),
Text('\r\n\r\n', (13, 15)),
DefTag('def', {'name': 'hi()'}, (15, 1), [
Text('\r\n hi!\r\n', (15, 19))]),
Text('\r\n\r\n</html>\r\n', (17, 8))
])
)
assert flatten_result(Template(template).render()) \
== """<html> like the name says. 1 2 3 Dizzy </html>"""
示例12: test_unbuffered_def
def test_unbuffered_def(self):
t = Template("""
<%def name="foo()" buffered="False">
this is foo
</%def>
${"hi->" + foo() + "<-hi"}
""")
assert flatten_result(t.render()) == "this is foo hi-><-hi"
示例13: test_overrides_builtins
def test_overrides_builtins(self):
template = Template("""
<%page args="id"/>
this is page, id is ${id}
""")
assert flatten_result(template.render(id="im the id")) == "this is page, id is im the id"
示例14: test_capture
def test_capture(self):
t = Template("""
<%def name="foo()" buffered="False">
this is foo
</%def>
${"hi->" + capture(foo) + "<-hi"}
""")
assert flatten_result(t.render()) == "hi-> this is foo <-hi"
示例15: test_with_context
def test_with_context(self):
template = Template("""
<%page args="x, y, z=7"/>
this is page, ${x}, ${y}, ${z}, ${w}
""")
#print template.code
assert flatten_result(template.render(x=5, y=10, w=17)) == "this is page, 5, 10, 7, 17"