From 1eb56ef02a7fa825be99ddfb95f217a07dab1cdf Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 11 Nov 2012 14:38:56 -0500 Subject: - 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 --- test/test_inheritance.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'test/test_inheritance.py') diff --git a/test/test_inheritance.py b/test/test_inheritance.py index a953847..08a46b3 100644 --- a/test/test_inheritance.py +++ b/test/test_inheritance.py @@ -1,7 +1,6 @@ -from mako.template import Template -from mako import lookup, util +from mako import lookup, compat import unittest -from util import flatten_result, result_lines +from test.util import result_lines class InheritanceTest(unittest.TestCase): def test_basic(self): @@ -52,7 +51,7 @@ main_body ${parent.d()} full stack from the top: ${self.name} ${parent.name} ${parent.context['parent'].name} ${parent.context['parent'].context['parent'].name} """) - + collection.put_string('layout', """ <%inherit file="general"/> <%def name="d()">layout_d @@ -94,11 +93,11 @@ ${next.body()} 'full stack from the top:', 'self:main self:layout self:general self:base' ] - + def test_includes(self): """test that an included template also has its full hierarchy invoked.""" collection = lookup.TemplateLookup() - + collection.put_string("base", """ <%def name="a()">base_a This is the base. @@ -120,7 +119,7 @@ ${next.body()} """) assert result_lines(collection.get_template("index").render()) == [ - 'This is the base.', + 'This is the base.', 'this is index.', 'a is: base_a', 'This is the base.', @@ -134,7 +133,7 @@ ${next.body()} """test that templates used via <%namespace> have access to an inheriting 'self', and that the full 'self' is also exported.""" collection = lookup.TemplateLookup() - + collection.put_string("base", """ <%def name="a()">base_a <%def name="b()">base_b @@ -194,7 +193,7 @@ ${next.body()} <%def name="foo()"> ${next.body(**context.kwargs)} - + ${foo()} """) collection.put_string("index", """ @@ -202,8 +201,8 @@ ${next.body()} <%page args="x, y, z=7"/> print ${x}, ${y}, ${z} """) - - if util.py3k: + + if compat.py3k: assert result_lines(collection.get_template('index').render_unicode(x=5,y=10)) == [ "this is the base.", "pageargs: (type: ) [('x', 5), ('y', 10)]", @@ -215,14 +214,14 @@ ${next.body()} "pageargs: (type: ) [('x', 5), ('y', 10)]", "print 5, 10, 7" ] - + def test_pageargs_2(self): collection = lookup.TemplateLookup() collection.put_string("base", """ this is the base. - + ${next.body(**context.kwargs)} - + <%def name="foo(**kwargs)"> ${next.body(**kwargs)} @@ -245,7 +244,7 @@ ${next.body()} "pageargs: 12, 15, 8", "pageargs: 5, 10, 16" ] - + def test_pageargs_err(self): collection = lookup.TemplateLookup() collection.put_string("base", """ @@ -258,11 +257,11 @@ ${next.body()} print ${x}, ${y}, ${z} """) try: - print collection.get_template('index').render(x=5,y=10) + print(collection.get_template('index').render(x=5,y=10)) assert False except TypeError: assert True - + def test_toplevel(self): collection = lookup.TemplateLookup() collection.put_string("base", """ @@ -305,7 +304,7 @@ ${next.body()} 'this is the base.', 'this is index.' ] - + def test_in_call(self): collection = lookup.TemplateLookup() collection.put_string("/layout.html",""" @@ -332,7 +331,7 @@ ${next.body()} <%inherit file="/layout.html"/> """) - + collection.put_string("/subdir/renderedtemplate.html",""" Holy smokes! <%inherit file="/subdir/layout.html"/> -- cgit v1.2.3