aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_call.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-11-11 14:38:56 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-11-11 14:38:56 -0500
commit1eb56ef02a7fa825be99ddfb95f217a07dab1cdf (patch)
treebf0857b7f42dec7db03910799eed7e5dda5e7c2b /test/test_call.py
parent4ab9664a515c265238d420b0373f7225fe2e53c7 (diff)
downloadexternal_python_mako-1eb56ef02a7fa825be99ddfb95f217a07dab1cdf.tar.gz
external_python_mako-1eb56ef02a7fa825be99ddfb95f217a07dab1cdf.tar.bz2
external_python_mako-1eb56ef02a7fa825be99ddfb95f217a07dab1cdf.zip
- first pass at running a py3k compatible base in py2k as well.
having some weird unicode issues I can't debug; the meaning of str.encode() seems to be changing globally somehow
Diffstat (limited to 'test/test_call.py')
-rw-r--r--test/test_call.py63
1 files changed, 31 insertions, 32 deletions
diff --git a/test/test_call.py b/test/test_call.py
index 0bb6079..e735a72 100644
--- a/test/test_call.py
+++ b/test/test_call.py
@@ -1,6 +1,6 @@
from mako.template import Template
from mako import util
-from util import result_lines, flatten_result
+from .util import result_lines, flatten_result
from test import TemplateTest, eq_
class CallTest(TemplateTest):
@@ -9,7 +9,7 @@ class CallTest(TemplateTest):
<%def name="foo()">
hi im foo ${caller.body(y=5)}
</%def>
-
+
<%call expr="foo()" args="y, **kwargs">
this is the body, y is ${y}
</%call>
@@ -23,16 +23,16 @@ class CallTest(TemplateTest):
<%def name="bar()">
this is bar
</%def>
-
+
<%def name="comp1()">
this comp1 should not be called
</%def>
-
+
<%def name="foo()">
foo calling comp1: ${caller.comp1(x=5)}
foo calling body: ${caller.body()}
</%def>
-
+
<%call expr="foo()">
<%def name="comp1(x)">
this is comp1, ${x}
@@ -46,10 +46,10 @@ class CallTest(TemplateTest):
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}
@@ -57,26 +57,26 @@ class CallTest(TemplateTest):
${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']
)
-
+
def test_ccall_caller(self):
t = Template("""
<%def name="outer_func()">
@@ -104,7 +104,7 @@ class CallTest(TemplateTest):
"INNER END",
"OUTER END",
]
-
+
def test_stack_pop(self):
t = Template("""
<%def name="links()" buffered="True">
@@ -130,7 +130,7 @@ class CallTest(TemplateTest):
"</h1>",
"Some links"
]
-
+
def test_conditional_call(self):
"""test that 'caller' is non-None only if the immediate <%def> was called via <%call>"""
@@ -169,12 +169,12 @@ class CallTest(TemplateTest):
"BBB",
"CCC"
]
-
+
def test_chained_call(self):
"""test %calls that are chained through their targets"""
t = Template("""
<%def name="a()">
- this is a.
+ this is a.
<%call expr="b()">
this is a's ccall. heres my body: ${caller.body()}
</%call>
@@ -184,11 +184,11 @@ class CallTest(TemplateTest):
whats in the body's caller's body ?
${context.caller_stack[-2].body()}
</%def>
-
+
<%call expr="a()">
heres the main templ call
</%call>
-
+
""")
assert result_lines(t.render()) == [
'this is a.',
@@ -225,7 +225,7 @@ class CallTest(TemplateTest):
"bar:",
"this is bar body: 10"
]
-
+
def test_nested_call_2(self):
t = Template("""
x is ${x}
@@ -240,13 +240,13 @@ class CallTest(TemplateTest):
<%call expr="foo()">
<%def name="foosub(x)">
this is foo body: ${x}
-
+
<%call expr="bar()">
<%def name="barsub()">
this is bar body: ${x}
</%def>
</%call>
-
+
</%def>
</%call>
@@ -278,7 +278,7 @@ class CallTest(TemplateTest):
''')
assert flatten_result(template.render()) == "foo"
-
+
def test_nested_call_4(self):
base = """
<%def name="A()">
@@ -340,7 +340,7 @@ class CallTest(TemplateTest):
t = Template("""
<%def name="embedded()">
<%def name="a()">
- this is a.
+ this is a.
<%call expr="b()">
this is a's ccall. heres my body: ${caller.body()}
</%call>
@@ -366,7 +366,7 @@ class CallTest(TemplateTest):
"whats in the body's caller's body ?",
'heres the main templ call'
]
-
+
def test_call_in_nested(self):
t = Template("""
<%def name="a()">
@@ -407,7 +407,7 @@ class CallTest(TemplateTest):
context.write("a is done")
return ''
%>
-
+
<%def name="b()">
this is b
our body: ${caller.body()}
@@ -430,8 +430,7 @@ class CallTest(TemplateTest):
</%call>
- """)
- #print t.code
+ """)
assert result_lines(t.render()) == [
"test 1",
"this is a",
@@ -452,7 +451,7 @@ class CallTest(TemplateTest):
"this is aa is done",
"this is aa is done"
]
-
+
def test_call_in_nested_2(self):
t = Template("""
<%def name="a()">
@@ -483,14 +482,14 @@ class CallTest(TemplateTest):
class SelfCacheTest(TemplateTest):
"""this test uses a now non-public API."""
-
+
def test_basic(self):
t = Template("""
<%!
cached = None
%>
<%def name="foo()">
- <%
+ <%
global cached
if cached:
return "cached: " + cached
@@ -503,7 +502,7 @@ class SelfCacheTest(TemplateTest):
return cached
%>
</%def>
-
+
${foo()}
${foo()}
""")
@@ -512,4 +511,4 @@ class SelfCacheTest(TemplateTest):
"cached:",
"this is foo"
]
-
+