diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-05 18:13:47 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-05 18:13:47 +0000 |
| commit | 876c371f4e12abf9f1126420ae261c37f4b09c57 (patch) | |
| tree | de7eaf944ad198757a90626dc5fb55c7aa78fabe /test | |
| parent | a1d018c13bd498b679e091b3a29c479727a6d937 (diff) | |
| download | external_python_mako-876c371f4e12abf9f1126420ae261c37f4b09c57.tar.gz external_python_mako-876c371f4e12abf9f1126420ae261c37f4b09c57.tar.bz2 external_python_mako-876c371f4e12abf9f1126420ae261c37f4b09c57.zip | |
- defs declared within a <%namespace> section, an
uncommon feature, have been improved. The defs
no longer get doubly-rendered in the body() scope,
and now allow local variable assignment without
breakage. [ticket:109]
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_namespace.py | 94 |
1 files changed, 77 insertions, 17 deletions
diff --git a/test/test_namespace.py b/test/test_namespace.py index 6351caa..1600ca9 100644 --- a/test/test_namespace.py +++ b/test/test_namespace.py @@ -1,25 +1,85 @@ from mako.template import Template from mako import lookup from util import flatten_result, result_lines -import unittest - -class NamespaceTest(unittest.TestCase): - def test_inline(self): - t = Template(""" - <%namespace name="x"> - <%def name="a()"> - this is x a - </%def> - <%def name="b()"> - this is x b, and heres ${a()} - </%def> - </%namespace> +from test import TemplateTest + +class NamespaceTest(TemplateTest): + def test_inline_crossreference(self): + self._do_memory_test( + """ + <%namespace name="x"> + <%def name="a()"> + this is x a + </%def> + <%def name="b()"> + this is x b, and heres ${a()} + </%def> + </%namespace> - ${x.a()} + ${x.a()} - ${x.b()} -""") - assert flatten_result(t.render()) == "this is x a this is x b, and heres this is x a" + ${x.b()} + """, + "this is x a this is x b, and heres this is x a", + filters=flatten_result + ) + + def test_inline_assignment(self): + self._do_memory_test( + """ + <%namespace name="x"> + <%def name="a()"> + <% + x = 5 + %> + this is x: ${x} + </%def> + </%namespace> + + ${x.a()} + + """, + "this is x: 5", + filters=flatten_result + ) + + def test_inline_arguments(self): + self._do_memory_test( + """ + <%namespace name="x"> + <%def name="a(x, y)"> + <% + result = x * y + %> + result: ${result} + </%def> + </%namespace> + + ${x.a(5, 10)} + + """, + "result: 50", + filters=flatten_result + ) + + def test_inline_not_duped(self): + self._do_memory_test( + """ + <%namespace name="x"> + <%def name="a()"> + foo + </%def> + </%namespace> + + <% + assert x.a is not UNDEFINED, "namespace x.a wasn't defined" + assert a is UNDEFINED, "name 'a' is in the body locals" + %> + + """, + "", + filters=flatten_result + ) def test_template(self): collection = lookup.TemplateLookup() |
