diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-11-11 15:20:48 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-11-11 15:20:48 -0500 |
commit | 800f3b13ed9c1ea52fbd6544dc902ebd7a721733 (patch) | |
tree | 08e80e47a427c49f3b0540c3c6b4d35aee7e707f | |
parent | 3bbeaef7d5576fcefd1ccec3661ce7e3fd454094 (diff) | |
download | mako-800f3b13ed9c1ea52fbd6544dc902ebd7a721733.tar.gz |
2.4-3.3 pass in place
-rw-r--r-- | mako/ext/beaker_cache.py | 10 | ||||
-rw-r--r-- | mako/pyparser.py | 4 | ||||
-rw-r--r-- | test/test_block.py | 118 | ||||
-rw-r--r-- | test/test_cache.py | 2 | ||||
-rw-r--r-- | test/test_call.py | 2 | ||||
-rw-r--r-- | test/test_decorators.py | 12 | ||||
-rw-r--r-- | test/test_loop.py | 8 | ||||
-rw-r--r-- | test/test_namespace.py | 118 | ||||
-rw-r--r-- | test/test_tgplugin.py | 4 |
9 files changed, 139 insertions, 139 deletions
diff --git a/mako/ext/beaker_cache.py b/mako/ext/beaker_cache.py index ed1a31c..c9fbf0a 100644 --- a/mako/ext/beaker_cache.py +++ b/mako/ext/beaker_cache.py @@ -7,11 +7,11 @@ from mako.cache import CacheImpl _beaker_cache = None class BeakerCacheImpl(CacheImpl): """A :class:`.CacheImpl` provided for the Beaker caching system. - + This plugin is used by default, based on the default value of ``'beaker'`` for the ``cache_impl`` parameter of the :class:`.Template` or :class:`.TemplateLookup` classes. - + """ def __init__(self, cache): @@ -19,7 +19,7 @@ class BeakerCacheImpl(CacheImpl): if _beaker_cache is None: try: from beaker import cache as beaker_cache - except ImportError as e: + except ImportError: raise exceptions.RuntimeException( "the Beaker package is required to use cache " "functionality.") @@ -60,11 +60,11 @@ class BeakerCacheImpl(CacheImpl): def put(self, key, value, **kw): cache, kw = self._get_cache(**kw) cache.put(key, value, **kw) - + def get(self, key, **kw): cache, kw = self._get_cache(**kw) return cache.get(key, **kw) - + def invalidate(self, key, **kw): cache, kw = self._get_cache(**kw) cache.remove_value(key, **kw) diff --git a/mako/pyparser.py b/mako/pyparser.py index f772dae..164b106 100644 --- a/mako/pyparser.py +++ b/mako/pyparser.py @@ -33,7 +33,7 @@ else: try: import _ast util.restore__ast(_ast) - from . import _ast_util + from mako import _ast_util except ImportError: _ast = None from compiler import parse as compiler_parse @@ -48,7 +48,7 @@ def parse(code, mode='exec', **exception_kwargs): if _ast: return _ast_util.parse(code, '<unknown>', mode) else: - if isinstance(code, compat.text_types): + if isinstance(code, compat.text_type): code = code.encode('ascii', 'backslashreplace') return compiler_parse(code, mode) except Exception: diff --git a/test/test_block.py b/test/test_block.py index 0f5cf17..da3de15 100644 --- a/test/test_block.py +++ b/test/test_block.py @@ -2,7 +2,7 @@ from mako.template import Template from mako.lookup import TemplateLookup from mako import exceptions from test import TemplateTest, assert_raises, assert_raises_message -from .util import flatten_result, result_lines +from test.util import flatten_result, result_lines @@ -22,13 +22,13 @@ class BlockTest(TemplateTest): def test_anonymous_block_in_call(self): template = Template(""" - + <%self:foo x="5"> <%block> this is the block x </%block> </%self:foo> - + <%def name="foo(x)"> foo: ${caller.body()} @@ -45,13 +45,13 @@ class BlockTest(TemplateTest): exceptions.CompileException, "Named block 'y' not allowed inside of <%call> tag", Template,""" - + <%self:foo x="5"> <%block name="y"> this is the block </%block> </%self:foo> - + <%def name="foo(x)"> foo: ${caller.body()} @@ -68,9 +68,9 @@ class BlockTest(TemplateTest): <%block name="x"> block </%block> - - foob - + + foob + <%block name="x"> block </%block> @@ -87,9 +87,9 @@ class BlockTest(TemplateTest): <%block name="x"> block </%block> - - foob - + + foob + <%block name="x"> block </%block> @@ -107,9 +107,9 @@ class BlockTest(TemplateTest): <%block name="x"> block </%block> - - foob - + + foob + <%block name="x"> block </%block> @@ -126,9 +126,9 @@ class BlockTest(TemplateTest): <%block name="x"> block </%block> - - foob - + + foob + <%def name="x()"> block </%def> @@ -145,12 +145,12 @@ class BlockTest(TemplateTest): block </%def> - foob - + foob + <%block name="x"> block </%block> - + """ ) @@ -162,7 +162,7 @@ class BlockTest(TemplateTest): </%block> below """) - self._do_test(template, ["above", "the header", "below"], + self._do_test(template, ["above", "the header", "below"], filters=result_lines) def test_inherited_block_no_render(self): @@ -180,12 +180,12 @@ class BlockTest(TemplateTest): <%block name="header"> the header </%block> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "index header", "below"], + self._do_test(l.get_template("index"), + ["above", "index header", "below"], filters=result_lines) def test_no_named_in_def(self): @@ -208,7 +208,7 @@ class BlockTest(TemplateTest): <%block name="title"> index title </%block> - + <%block name="header"> index header ${parent.header()} @@ -223,12 +223,12 @@ class BlockTest(TemplateTest): the title </%block> </%block> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "index header", "base header", "index title", "below"], + self._do_test(l.get_template("index"), + ["above", "index header", "base header", "index title", "below"], filters=result_lines) def test_inherited_block_nested_inner_only(self): @@ -239,7 +239,7 @@ class BlockTest(TemplateTest): <%block name="title"> index title </%block> - + """ ) l.put_string("base",""" @@ -250,12 +250,12 @@ class BlockTest(TemplateTest): the title </%block> </%block> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "base header", "index title", "below"], + self._do_test(l.get_template("index"), + ["above", "base header", "index title", "below"], filters=result_lines) def test_noninherited_block_no_render(self): @@ -273,12 +273,12 @@ class BlockTest(TemplateTest): <%block name="header"> the header </%block> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "the header", "some thing", "below"], + self._do_test(l.get_template("index"), + ["above", "the header", "some thing", "below"], filters=result_lines) def test_no_conflict_nested_one(self): @@ -298,12 +298,12 @@ class BlockTest(TemplateTest): <%block name="header"> the header </%block> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "inner header", "below"], + self._do_test(l.get_template("index"), + ["above", "inner header", "below"], filters=result_lines) def test_nested_dupe_names_raise(self): @@ -346,13 +346,13 @@ class BlockTest(TemplateTest): <%block name="header"> the header </%block> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "index header", "middle anon", - "index anon", "below"], + self._do_test(l.get_template("index"), + ["above", "index header", "middle anon", + "index anon", "below"], filters=result_lines) def test_filter(self): @@ -361,7 +361,7 @@ class BlockTest(TemplateTest): <html> </%block> """) - self._do_test(template, ['<html>'], + self._do_test(template, ['<html>'], filters=result_lines) def test_anon_in_named(self): @@ -413,7 +413,7 @@ class BlockTest(TemplateTest): self._test_block_in_block(template) def _test_block_in_block(self, template): - self._do_test(template, + self._do_test(template, ["outer above", "inner", "outer below"], filters=result_lines ) @@ -424,7 +424,7 @@ class BlockTest(TemplateTest): <%block>${i}</%block> % endfor """) - self._do_test(t, + self._do_test(t, ["1", "2", "3"], filters=result_lines ) @@ -439,7 +439,7 @@ class BlockTest(TemplateTest): <%block>false</%block> % endif """) - self._do_test(t, + self._do_test(t, ["true"], filters=result_lines ) @@ -459,12 +459,12 @@ class BlockTest(TemplateTest): <%block name="header"> the header </%block> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "inner header", "below"], + self._do_test(l.get_template("index"), + ["above", "inner header", "below"], filters=result_lines) def test_def_overridden_by_block(self): @@ -483,20 +483,20 @@ class BlockTest(TemplateTest): <%def name="header()"> the header </%def> - + ${next.body()} below """) - self._do_test(l.get_template("index"), - ["above", "inner header", "below"], + self._do_test(l.get_template("index"), + ["above", "inner header", "below"], filters=result_lines) def test_block_args(self): l = TemplateLookup() l.put_string("caller", """ - + <%include file="callee" args="val1='3', val2='4'"/> - + """) l.put_string("callee", """ <%page args="val1, val2"/> @@ -511,7 +511,7 @@ class BlockTest(TemplateTest): ) def test_block_variables_contextual(self): - t = Template(""" + t = Template(""" <%block name="foob" > foob, ${val1}, ${val2} </%block> @@ -524,7 +524,7 @@ class BlockTest(TemplateTest): ) def test_block_args_contextual(self): - t = Template(""" + t = Template(""" <%page args="val1"/> <%block name="foob" args="val1"> foob, ${val1}, ${val2} @@ -538,7 +538,7 @@ class BlockTest(TemplateTest): ) def test_block_pageargs_contextual(self): - t = Template(""" + t = Template(""" <%block name="foob"> foob, ${pageargs['val1']}, ${pageargs['val2']} </%block> @@ -553,9 +553,9 @@ class BlockTest(TemplateTest): def test_block_pageargs(self): l = TemplateLookup() l.put_string("caller", """ - + <%include file="callee" args="val1='3', val2='4'"/> - + """) l.put_string("callee", """ <%block name="foob"> diff --git a/test/test_cache.py b/test/test_cache.py index 40539fb..3f6f1b8 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -2,7 +2,7 @@ from mako.template import Template from mako.lookup import TemplateLookup from mako import lookup import shutil, unittest, os, time -from .util import result_lines +from test.util import result_lines from test import TemplateTest, template_base, module_base from test import eq_ diff --git a/test/test_call.py b/test/test_call.py index e735a72..5071222 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 test.util import result_lines, flatten_result from test import TemplateTest, eq_ class CallTest(TemplateTest): diff --git a/test/test_decorators.py b/test/test_decorators.py index 74e674c..a3fa8f5 100644 --- a/test/test_decorators.py +++ b/test/test_decorators.py @@ -1,7 +1,7 @@ from mako.template import Template from mako import lookup import unittest -from .util import flatten_result, result_lines +from test.util import flatten_result, result_lines class DecoratorTest(unittest.TestCase): def test_toplevel(self): @@ -12,11 +12,11 @@ class DecoratorTest(unittest.TestCase): return "BAR" + runtime.capture(context, fn, *args, **kw) + "BAR" return decorate %> - + <%def name="foo(y, x)" decorator="bar"> this is foo ${y} ${x} </%def> - + ${foo(1, x=5)} """) @@ -56,7 +56,7 @@ class DecoratorTest(unittest.TestCase): %> <%def name="foo()"> - + <%def name="bar()" decorator="bat"> this is bar </%def> @@ -67,7 +67,7 @@ class DecoratorTest(unittest.TestCase): """) assert flatten_result(template.render()) == "BAT this is bar BAT" - + def test_toplevel_decorated_name(self): template = Template(""" <%! @@ -107,4 +107,4 @@ class DecoratorTest(unittest.TestCase): """) assert flatten_result(template.render()) == "function bar this is bar" - + diff --git a/test/test_loop.py b/test/test_loop.py index acff53f..bdfbaea 100644 --- a/test/test_loop.py +++ b/test/test_loop.py @@ -10,7 +10,7 @@ from mako.runtime import LoopStack, LoopContext from mako import exceptions from test import assert_raises_message from test import TemplateTest, eq_ -from .util import flatten_result, result_lines +from test.util import flatten_result, result_lines class TestLoop(unittest.TestCase): @@ -208,7 +208,7 @@ class TestLoopFlags(TemplateTest): self._do_memory_test( """ the loop: ${loop} - """, + """, "the loop: hi", template_args=dict(loop='hi'), filters=flatten_result, @@ -237,7 +237,7 @@ class TestLoopFlags(TemplateTest): % for i in (1, 2, 3): ${i} ${loop.index} % endfor - """, + """, "1 0 2 1 3 2", template_args=dict(loop='hi'), filters=flatten_result, @@ -269,7 +269,7 @@ class TestLoopFlags(TemplateTest): % for i in (1, 2, 3): ${i} ${loop.index} % endfor - """, + """, "1 0 2 1 3 2", template_args=dict(), filters=flatten_result, diff --git a/test/test_namespace.py b/test/test_namespace.py index 5f6d253..90964b5 100644 --- a/test/test_namespace.py +++ b/test/test_namespace.py @@ -1,6 +1,6 @@ from mako.template import Template from mako import lookup -from .util import flatten_result, result_lines +from test.util import flatten_result, result_lines from test import TemplateTest, eq_ class NamespaceTest(TemplateTest): @@ -15,9 +15,9 @@ class NamespaceTest(TemplateTest): this is x b, and heres ${a()} </%def> </%namespace> - + ${x.a()} - + ${x.b()} """, "this is x a this is x b, and heres this is x a", @@ -98,13 +98,13 @@ class NamespaceTest(TemplateTest): flatten_result(collection.get_template('a').render(b_def='b')), "a. b: b." ) - + def test_template(self): collection = lookup.TemplateLookup() collection.put_string('main.html', """ <%namespace name="comp" file="defs.html"/> - + this is main. ${comp.def1("hi")} ${comp.def2("there")} """) @@ -113,14 +113,14 @@ class NamespaceTest(TemplateTest): <%def name="def1(s)"> def1: ${s} </%def> - + <%def name="def2(x)"> def2: ${x} </%def> """) assert flatten_result(collection.get_template('main.html').render()) == "this is main. def1: hi def2: there" - + def test_module(self): collection = lookup.TemplateLookup() @@ -168,7 +168,7 @@ class NamespaceTest(TemplateTest): """) assert flatten_result(collection.get_template('main.html').render()) == "this is main. this is foo1. this is foo2, x is hi" - + def test_context(self): """test that namespace callables get access to the current context""" collection = lookup.TemplateLookup() @@ -191,7 +191,7 @@ class NamespaceTest(TemplateTest): """) assert flatten_result(collection.get_template('main.html').render(x="context x")) == "this is main. def1: x is context x def2: x is there" - + def test_overload(self): collection = lookup.TemplateLookup() @@ -238,13 +238,13 @@ class NamespaceTest(TemplateTest): collection = lookup.TemplateLookup() collection.put_string("main.html", """ <%namespace name="foo" file="ns.html"/> - + this is main. ${bar()} <%def name="bar()"> this is bar, foo is ${foo.bar()} </%def> """) - + collection.put_string("ns.html", """ <%def name="bar()"> this is ns.html->bar @@ -274,24 +274,24 @@ class NamespaceTest(TemplateTest): this is ns.html->bar </%def> """) - + collection.put_string("index.html", """ <%namespace name="main" file="main.html"/> - + this is index ${main.bar()} """) - assert result_lines(collection.get_template("index.html").render()) == [ + assert result_lines(collection.get_template("index.html").render()) == [ "this is index", "this is bar, foo is" , "this is ns.html->bar" ] - + def test_dont_pollute_self(self): # test that get_namespace() doesn't modify the original context # incompatibly - + collection = lookup.TemplateLookup() collection.put_string("base.html", """ @@ -334,13 +334,13 @@ class NamespaceTest(TemplateTest): "name via bar:", "self:page.html" ] - + def test_inheritance(self): """test namespace initialization in a base inherited template that doesnt otherwise access the namespace""" collection = lookup.TemplateLookup() collection.put_string("base.html", """ <%namespace name="foo" file="ns.html" inheritable="True"/> - + ${next.body()} """) collection.put_string("ns.html", """ @@ -351,11 +351,11 @@ class NamespaceTest(TemplateTest): collection.put_string("index.html", """ <%inherit file="base.html"/> - + this is index ${self.foo.bar()} """) - + assert result_lines(collection.get_template("index.html").render()) == [ "this is index", "this is ns.html->bar" @@ -367,7 +367,7 @@ class NamespaceTest(TemplateTest): <%def name="foo()"> base.foo </%def> - + <%def name="bat()"> base.bat </%def> @@ -381,11 +381,11 @@ class NamespaceTest(TemplateTest): ${parent.bat()} ${self.bat()} </%def> - + <%def name="foo()"> lib.foo </%def> - + """) collection.put_string("front.html", """ @@ -424,7 +424,7 @@ class NamespaceTest(TemplateTest): <% self.attr.lala = "base lala" %> - + ${self.attr.basefoo} ${self.attr.foofoo} ${self.attr.onlyfoo} @@ -448,7 +448,7 @@ class NamespaceTest(TemplateTest): "base lala", "foo lala", ] - + def test_attr_raise(self): l = lookup.TemplateLookup() @@ -459,19 +459,19 @@ class NamespaceTest(TemplateTest): l.put_string("bar.html", """ <%namespace name="foo" file="foo.html"/> - + ${foo.notfoo()} """) self.assertRaises(AttributeError, l.get_template("bar.html").render) - + def test_custom_tag_1(self): template = Template(""" - + <%def name="foo(x, y)"> foo: ${x} ${y} </%def> - + <%self:foo x="5" y="${7+8}"/> """) assert result_lines(template.render()) == ['foo: 5 15'] @@ -482,32 +482,32 @@ class NamespaceTest(TemplateTest): <%def name="foo(x, y)"> foo: ${x} ${y} </%def> - + <%def name="bat(g)"><% return "the bat! %s" % g %></%def> - + <%def name="bar(x)"> ${caller.body(z=x)} </%def> """) - + collection.put_string("index.html", """ <%namespace name="myns" file="base.html"/> - + <%myns:foo x="${'some x'}" y="some y"/> - + <%myns:bar x="${myns.bat(10)}" args="z"> record: ${z} </%myns:bar> - + """) - + assert result_lines(collection.get_template("index.html").render()) == [ - 'foo: some x some y', + 'foo: some x some y', 'record: the bat! 10' ] - + def test_custom_tag_3(self): collection = lookup.TemplateLookup() collection.put_string("base.html", """ @@ -530,14 +530,14 @@ class NamespaceTest(TemplateTest): call body </%self.foo:bar> """) - + assert result_lines(collection.get_template("index.html").render()) == [ "this is index", "this is ns.html->bar", "caller body:", "call body" ] - + def test_custom_tag_case_sensitive(self): t = Template(""" <%def name="renderPanel()"> @@ -549,21 +549,21 @@ class NamespaceTest(TemplateTest): hi </%self:renderPanel> </%def> - + <%self:renderTablePanel/> """) assert result_lines(t.render()) == ['panel', 'hi'] - - + + def test_expr_grouping(self): """test that parenthesis are placed around string-embedded expressions.""" - + template = Template(""" <%def name="bar(x, y)"> ${x} ${y} </%def> - + <%self:bar x=" ${foo} " y="x${g and '1' or '2'}y"/> """, input_encoding='utf-8') @@ -573,7 +573,7 @@ class NamespaceTest(TemplateTest): "x2y" ] - + def test_ccall(self): collection = lookup.TemplateLookup() collection.put_string("base.html", """ @@ -652,11 +652,11 @@ class NamespaceTest(TemplateTest): <%def name="foo()"> this is foo </%def> - + <%def name="bar()"> this is bar </%def> - + <%def name="lala()"> this is lala </%def> @@ -689,7 +689,7 @@ class NamespaceTest(TemplateTest): "this is b", "this is x" ] - + def test_import_calledfromdef(self): l = lookup.TemplateLookup() l.put_string("a", """ @@ -712,29 +712,29 @@ class NamespaceTest(TemplateTest): t = l.get_template("b") assert flatten_result(t.render()) == "im table" - + def test_closure_import(self): collection = lookup.TemplateLookup() collection.put_string("functions.html",""" <%def name="foo()"> this is foo </%def> - + <%def name="bar()"> this is bar </%def> """) - + collection.put_string("index.html", """ <%namespace file="functions.html" import="*"/> <%def name="cl1()"> ${foo()} </%def> - + <%def name="cl2()"> ${bar()} </%def> - + ${cl1()} ${cl2()} """) @@ -750,26 +750,26 @@ class NamespaceTest(TemplateTest): this is foo </%def> </%namespace> - + ${foo()} - + """) assert flatten_result(t.render()) == "this is foo" - + def test_ccall_import(self): collection = lookup.TemplateLookup() collection.put_string("functions.html",""" <%def name="foo()"> this is foo </%def> - + <%def name="bar()"> this is bar. ${caller.body()} ${caller.lala()} </%def> """) - + collection.put_string("index.html", """ <%namespace name="func" file="functions.html" import="*"/> <%call expr="bar()"> diff --git a/test/test_tgplugin.py b/test/test_tgplugin.py index 560c2fe..3ba5c75 100644 --- a/test/test_tgplugin.py +++ b/test/test_tgplugin.py @@ -1,7 +1,7 @@ import unittest from mako.ext.turbogears import TGPlugin -from .util import flatten_result, result_lines +from test.util import flatten_result, result_lines from test import TemplateTest, template_base tl = TGPlugin(options=dict(directories=[template_base]), extension='html') @@ -36,7 +36,7 @@ class TestTGPlugin(TemplateTest): ] assert tl.load_template('subdir.index').module_id == '_subdir_index_html' - + def test_string(self): t = tl.load_template('foo', "hello world") assert t.render() == "hello world" |