diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-19 10:33:00 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-19 10:33:00 -0500 |
commit | 6779081b32cfb237062da8bc623a27d47301ce4c (patch) | |
tree | fc3372c916cfc9efc61cccffde74528772532b37 /test/test_template.py | |
parent | 76e622b46ef71eddfbcd1232ee08b4e55c88c363 (diff) | |
download | mako-6779081b32cfb237062da8bc623a27d47301ce4c.tar.gz |
- now that trailing whitespace comes up in red, need to get rid of it
Diffstat (limited to 'test/test_template.py')
-rw-r--r-- | test/test_template.py | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/test/test_template.py b/test/test_template.py index dbfd068..3d489f7 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -22,7 +22,7 @@ class EncodingTest(TemplateTest): u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""", output_encoding='utf-8' ) - + def test_unicode_arg(self): val = u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""" self._do_memory_test( @@ -81,7 +81,7 @@ class EncodingTest(TemplateTest): ("## -*- coding: utf-8 -*-\n" + val).encode('utf-8'), u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""" ) - + def test_unicode_text(self): val = u"""<%text>Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »</%text>""" self._do_memory_test( @@ -102,7 +102,7 @@ class EncodingTest(TemplateTest): u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""", filters=flatten_result ) - + def test_unicode_literal_in_expr(self): if util.py3k: self._do_memory_test( @@ -149,7 +149,7 @@ class EncodingTest(TemplateTest): u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""", filters=lambda s:s.strip() ) - + def test_unicode_literal_in_controlline(self): if util.py3k: self._do_memory_test( @@ -177,7 +177,7 @@ class EncodingTest(TemplateTest): u"""hi, drôle de petite voix m’a réveillé.""", filters=lambda s:s.strip(), ) - + def test_unicode_literal_in_tag(self): self._do_file_test( "unicode_arguments.html", @@ -200,7 +200,7 @@ class EncodingTest(TemplateTest): ], filters=result_lines ) - + def test_unicode_literal_in_def(self): if util.py3k: self._do_memory_test( @@ -237,7 +237,7 @@ class EncodingTest(TemplateTest): u"""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP""", filters=flatten_result ) - + self._do_memory_test( u"""## -*- coding: utf-8 -*- <%def name="hello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')"> @@ -248,18 +248,18 @@ class EncodingTest(TemplateTest): u"""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP""", filters=flatten_result ) - + def test_input_encoding(self): """test the 'input_encoding' flag on Template, and that unicode objects arent double-decoded""" - + if util.py3k: self._do_memory_test( u"hello ${f('śląsk')}", u"hello śląsk", input_encoding='utf-8', template_args={'f':lambda x:x} - ) + ) self._do_memory_test( u"## -*- coding: utf-8 -*-\nhello ${f('śląsk')}", @@ -272,7 +272,7 @@ class EncodingTest(TemplateTest): u"hello śląsk", input_encoding='utf-8', template_args={'f':lambda x:x} - ) + ) self._do_memory_test( u"## -*- coding: utf-8 -*-\nhello ${f(u'śląsk')}", @@ -297,7 +297,7 @@ class EncodingTest(TemplateTest): u"hello śląsk", template_args={'x':u'śląsk'} ) - + def test_encoding(self): self._do_memory_test( u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""", @@ -313,7 +313,7 @@ class EncodingTest(TemplateTest): output_encoding='iso-8859-1', encoding_errors='replace', unicode_=False ) - + def test_read_unicode(self): lookup = TemplateLookup(directories=[template_base], filesystem_checks=True, output_encoding='utf-8') @@ -357,7 +357,7 @@ class PageArgsTest(TemplateTest): def test_basic(self): template = Template(""" <%page args="x, y, z=7"/> - + this is page, ${x}, ${y}, ${z} """) @@ -368,7 +368,7 @@ class PageArgsTest(TemplateTest): assert False except TypeError, e: assert True - + def test_inherits(self): lookup = TemplateLookup() lookup.put_string("base.tmpl", @@ -390,7 +390,7 @@ class PageArgsTest(TemplateTest): "bar foo var", filters=flatten_result, template_args={'variable':'var', 'bar':'bar', 'foo':'foo'} - + ) def test_includes(self): @@ -421,7 +421,7 @@ class PageArgsTest(TemplateTest): template_args={'variable':'var', 'bar':'bar', 'foo':'foo'} ) - + def test_with_context(self): template = Template(""" <%page args="x, y, z=7"/> @@ -434,12 +434,12 @@ class PageArgsTest(TemplateTest): 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" - + def test_canuse_builtin_names(self): template = Template(""" exception: ${Exception} @@ -465,7 +465,7 @@ class PageArgsTest(TemplateTest): assert flatten_result(lookup.get_template(template).render()) == "foo" assert flatten_result(lookup.get_template(template).render(id=5)) == "5" assert flatten_result(lookup.get_template(template).render(id=id)) == "<built-in function id>" - + def test_dict_locals(self): template = Template(""" <% @@ -501,8 +501,8 @@ class IncludeTest(TemplateTest): this is b. ${a}, ${b}, ${c} """) assert flatten_result(lookup.get_template("a").render(a=7,b=8)) == "this is a this is b. 7, 8, 5" - - def test_viakwargs(self): + + def test_viakwargs(self): lookup = TemplateLookup() lookup.put_string("a", """ this is a @@ -526,7 +526,7 @@ class IncludeTest(TemplateTest): this is b. ${a}, ${b}, ${c} """) assert flatten_result(lookup.get_template("a").render(a=7,b=8,i='b')) == "this is a this is b. 7, 8, 5" - + def test_within_ccall(self): lookup = TemplateLookup() lookup.put_string("a", """this is a""") @@ -553,7 +553,7 @@ class UndefinedVarsTest(TemplateTest): x: ${x} % endif """) - + assert result_lines(t.render(x=12)) == ["x: 12"] assert result_lines(t.render(y=12)) == ["undefined"] @@ -565,14 +565,14 @@ class UndefinedVarsTest(TemplateTest): x: ${x} % endif """, strict_undefined=True) - + assert result_lines(t.render(x=12)) == ['x: 12'] - + assert_raises( NameError, t.render, y=12 ) - + l = TemplateLookup(strict_undefined=True) l.put_string("a", "some template") l.put_string("b", """ @@ -585,41 +585,41 @@ class UndefinedVarsTest(TemplateTest): """) assert result_lines(t.render(x=12)) == ['x: 12'] - + assert_raises( NameError, t.render, y=12 ) - + def test_expression_declared(self): t = Template(""" ${",".join([t for t in ("a", "b", "c")])} """, strict_undefined=True) - + eq_(result_lines(t.render()), ['a,b,c']) t = Template(""" <%self:foo value="${[(val, n) for val, n in [(1, 2)]]}"/> - + <%def name="foo(value)"> ${value} </%def> - + """, strict_undefined=True) - + eq_(result_lines(t.render()), ['[(1, 2)]']) t = Template(""" <%call expr="foo(value=[(val, n) for val, n in [(1, 2)]])" /> - + <%def name="foo(value)"> ${value} </%def> - + """, strict_undefined=True) - + eq_(result_lines(t.render()), ['[(1, 2)]']) - + l = TemplateLookup(strict_undefined=True) l.put_string("i", "hi, ${pageargs['y']}") l.put_string("t", """ @@ -628,7 +628,7 @@ class UndefinedVarsTest(TemplateTest): eq_( result_lines(l.get_template("t").render()), ['hi, [0, 1, 2]'] ) - + l.put_string('q', """ <%namespace name="i" file="${(str([x for x in range(3)][2]) + 'i')[-1]}" /> ${i.body(y='x')} @@ -652,19 +652,19 @@ class UndefinedVarsTest(TemplateTest): # is treated as an "undefined", so is pulled from the context. t = Template(""" t is: ${t} - + ${",".join([t for t in ("a", "b", "c")])} """) - + eq_( result_lines(t.render(t="T")), ['t is: T', 'a,b,c'] ) - + def test_traditional_assignment_plus_undeclared(self): t = Template(""" t is: ${t} - + <% t = 12 %> @@ -673,22 +673,22 @@ class UndefinedVarsTest(TemplateTest): UnboundLocalError, t.render, t="T" ) - + def test_list_comprehensions_plus_undeclared_strict(self): # with strict, a list comprehension now behaves # like the undeclared case above. t = Template(""" t is: ${t} - + ${",".join([t for t in ("a", "b", "c")])} """, strict_undefined=True) - + eq_( result_lines(t.render(t="T")), ['t is: T', 'a,b,c'] ) - - + + class ControlTest(TemplateTest): def test_control(self): t = Template(""" @@ -706,7 +706,7 @@ class ControlTest(TemplateTest): "no x does not have test", "yes x has test" ] - + def test_blank_control(self): self._do_memory_test( """ @@ -716,7 +716,7 @@ class ControlTest(TemplateTest): "", filters=lambda s:s.strip() ) - + def test_multiline_control(self): t = Template(""" % for x in \\ @@ -726,7 +726,7 @@ class ControlTest(TemplateTest): """) #print t.code assert flatten_result(t.render()) == "1 2 3" - + class GlobalsTest(TemplateTest): def test_globals(self): self._do_memory_test( @@ -741,7 +741,7 @@ class GlobalsTest(TemplateTest): ) class RichTracebackTest(TemplateTest): - + def _do_test_traceback(self, utf8, memory, syntax): if memory: if syntax: @@ -825,7 +825,7 @@ class ModuleDirTest(TemplateTest): class FilenameToURITest(TemplateTest): def test_windows_paths(self): """test that windows filenames are handled appropriately by Template.""" - + current_path = os.path import ntpath os.path = ntpath @@ -834,11 +834,11 @@ class FilenameToURITest(TemplateTest): def _compile_from_file(self, path, filename): self.path = path return Template("foo bar").module - + t1 = NoCompileTemplate( filename="c:\\foo\\template.html", module_directory="c:\\modules\\") - + eq_(t1.uri, "/foo/template.html") eq_(t1.path, "c:\\modules\\foo\\template.html.py") @@ -846,7 +846,7 @@ class FilenameToURITest(TemplateTest): filename="c:\\path\\to\\templates\\template.html", uri = "/bar/template.html", module_directory="c:\\modules\\") - + eq_(t1.uri, "/bar/template.html") eq_(t1.path, "c:\\modules\\bar\\template.html.py") @@ -882,16 +882,16 @@ class FilenameToURITest(TemplateTest): finally: os.path = current_path - - - + + + class ModuleTemplateTest(TemplateTest): def test_module_roundtrip(self): lookup = TemplateLookup() template = Template(""" <%inherit file="base.html"/> - + % for x in range(5): ${x} % endfor @@ -904,30 +904,30 @@ class ModuleTemplateTest(TemplateTest): lookup.put_template("base.html", base) lookup.put_template("template.html", template) - + assert result_lines(template.render()) == [ "This is base.", "0", "1", "2", "3", "4" ] - + lookup = TemplateLookup() template = ModuleTemplate(template.module, lookup=lookup) base = ModuleTemplate(base.module, lookup=lookup) lookup.put_template("base.html", base) lookup.put_template("template.html", template) - + assert result_lines(template.render()) == [ "This is base.", "0", "1", "2", "3", "4" ] - - + + class PreprocessTest(TemplateTest): def test_old_comments(self): t = Template(""" im a template # old style comment # more old style comment - + ## new style comment - # not a comment - ## not a comment |