本文整理汇总了Python中test.eq_函数的典型用法代码示例。如果您正苦于以下问题:Python eq_函数的具体用法?Python eq_怎么用?Python eq_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eq_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fileargs_lookup
def test_fileargs_lookup(self):
l = lookup.TemplateLookup(cache_dir=module_base, cache_type='file')
l.put_string("test", """
<%!
callcount = [0]
%>
<%def name="foo()" cached="True">
this is foo
<%
callcount[0] += 1
%>
</%def>
${foo()}
${foo()}
${foo()}
callcount: ${callcount}
""")
t = l.get_template('test')
m = self._install_mock_cache(t)
assert result_lines(l.get_template('test').render()) == [
'this is foo',
'this is foo',
'this is foo',
'callcount: [1]',
]
eq_(m.kwargs, {'dir': module_base, 'type': 'file'})
示例2: test_fileargs_pagetag
def test_fileargs_pagetag(self):
t = Template("""
<%%page cache_dir='%s' cache_type='dbm'/>
<%%!
callcount = [0]
%%>
<%%def name="foo()" cached="True">
this is foo
<%%
callcount[0] += 1
%%>
</%%def>
${foo()}
${foo()}
${foo()}
callcount: ${callcount}
""" % module_base)
m = self._install_mock_cache(t)
assert result_lines(t.render()) == [
'this is foo',
'this is foo',
'this is foo',
'callcount: [1]',
]
eq_(m.kwargs, {'dir': module_base, 'type': 'dbm'})
示例3: test_metadata_two
def test_metadata_two(self):
t = Template("""
Text
Text
% if bar:
${expression}
% endif
<%block name="foo">
hi block
</%block>
""", uri="/some/template")
eq_(
ModuleInfo.get_module_source_metadata(t.code, full_line_map=True),
{
'full_line_map': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 5, 5, 5, 7, 7, 7,
7, 7, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8],
'source_encoding': 'ascii',
'filename': None,
'line_map': {33: 10, 39: 8, 45: 8, 14: 0, 51: 45, 23: 1,
24: 4, 25: 5, 26: 5, 27: 5, 28: 7},
'uri': '/some/template'}
)
示例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_locate_identifiers
def test_locate_identifiers(self):
"""test the location of identifiers in a python code string"""
code = """
a = 10
b = 5
c = x * 5 + a + b + q
(g,h,i) = (1,2,3)
[u,k,j] = [4,5,6]
foo.hoho.lala.bar = 7 + gah.blah + u + blah
for lar in (1,2,3):
gh = 5
x = 12
("hello world, ", a, b)
("Another expr", c)
"""
parsed = ast.PythonCode(code, **exception_kwargs)
eq_(
parsed.declared_identifiers,
set(['a', 'b', 'c', 'g', 'h', 'i', 'u',
'k', 'j', 'gh', 'lar', 'x'])
)
eq_(
parsed.undeclared_identifiers,
set(['x', 'q', 'foo', 'gah', 'blah'])
)
parsed = ast.PythonCode("x + 5 * (y-z)", **exception_kwargs)
assert parsed.undeclared_identifiers == set(['x', 'y', 'z'])
assert parsed.declared_identifiers == set()
示例6: test_locate_identifiers_10
def test_locate_identifiers_10(self):
code = """
lambda q: q + 5
"""
parsed = ast.PythonCode(code, **exception_kwargs)
eq_(parsed.declared_identifiers, set())
eq_(parsed.undeclared_identifiers, set())
示例7: test_locate_identifiers_7
def test_locate_identifiers_7(self):
code = """
import foo.bar
"""
parsed = ast.PythonCode(code, **exception_kwargs)
eq_(parsed.declared_identifiers, set(['foo']))
eq_(parsed.undeclared_identifiers, set())
示例8: 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"]
)
示例9: test_fileargs_implicit
def test_fileargs_implicit(self):
l = lookup.TemplateLookup(module_directory=module_base)
l.put_string(
"test",
"""
<%!
callcount = [0]
%>
<%def name="foo()" cached="True" cache_type='dbm'>
this is foo
<%
callcount[0] += 1
%>
</%def>
${foo()}
${foo()}
${foo()}
callcount: ${callcount}
""",
)
m = self._install_mock_cache(l.get_template("test"))
assert result_lines(l.get_template("test").render()) == [
"this is foo",
"this is foo",
"this is foo",
"callcount: [1]",
]
eq_(m.kwargs, {"type": "dbm"})
示例10: 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."
)
示例11: 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"
)
示例12: 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"
)
示例13: test_new_syntax
def test_new_syntax(self):
"""test foo:bar syntax, including multiline args and expression eval."""
# note the trailing whitespace in the bottom ${} expr, need to strip
# that off < python 2.7
t = Template("""
<%def name="foo(x, y, q, z)">
${x}
${y}
${q}
${",".join("%s->%s" % (a, b) for a, b in z)}
</%def>
<%self:foo x="this is x" y="${'some ' + 'y'}" q="
this
is
q"
z="${[
(1, 2),
(3, 4),
(5, 6)
]
}"/>
""")
eq_(
result_lines(t.render()),
['this is x', 'some y', 'this', 'is', 'q', '1->2,3->4,5->6']
)
示例14: test_args_complete
def test_args_complete(self):
t = Template(
"""
<%%def name="foo()" cached="True" cache_timeout="30" cache_dir="%s"
cache_type="file" cache_key='somekey'>
this is foo
</%%def>
${foo()}
"""
% module_base
)
m = self._install_mock_cache(t)
t.render()
eq_(m.kwargs, {"dir": module_base, "type": "file", "timeout": 30})
t2 = Template(
"""
<%%page cached="True" cache_timeout="30" cache_dir="%s"
cache_type="file" cache_key='somekey'/>
hi
"""
% module_base
)
m = self._install_mock_cache(t2)
t2.render()
eq_(m.kwargs, {"dir": module_base, "type": "file", "timeout": 30})
示例15: test_fileargs_lookup
def test_fileargs_lookup(self):
l = lookup.TemplateLookup(cache_dir=module_base, cache_type="file")
l.put_string(
"test",
"""
<%!
callcount = [0]
%>
<%def name="foo()" cached="True">
this is foo
<%
callcount[0] += 1
%>
</%def>
${foo()}
${foo()}
${foo()}
callcount: ${callcount}
""",
)
t = l.get_template("test")
m = self._install_mock_cache(t)
assert result_lines(l.get_template("test").render()) == [
"this is foo",
"this is foo",
"this is foo",
"callcount: [1]",
]
eq_(m.kwargs, {"dir": module_base, "type": "file"})