summaryrefslogtreecommitdiff
path: root/pystache/tests/test_renderer.py
diff options
context:
space:
mode:
Diffstat (limited to 'pystache/tests/test_renderer.py')
-rw-r--r--pystache/tests/test_renderer.py81
1 files changed, 54 insertions, 27 deletions
diff --git a/pystache/tests/test_renderer.py b/pystache/tests/test_renderer.py
index f04c799..04e9691 100644
--- a/pystache/tests/test_renderer.py
+++ b/pystache/tests/test_renderer.py
@@ -319,37 +319,37 @@ class RendererTests(unittest.TestCase, AssertStringMixin):
renderer.string_encoding = 'utf_8'
self.assertEqual(renderer.render(template), u"déf")
- def test_make_load_partial(self):
+ def test_make_resolve_partial(self):
"""
- Test the _make_load_partial() method.
+ Test the _make_resolve_partial() method.
"""
renderer = Renderer()
renderer.partials = {'foo': 'bar'}
- load_partial = renderer._make_load_partial()
+ resolve_partial = renderer._make_resolve_partial()
- actual = load_partial('foo')
+ actual = resolve_partial('foo')
self.assertEqual(actual, 'bar')
self.assertEqual(type(actual), unicode, "RenderEngine requires that "
- "load_partial return unicode strings.")
+ "resolve_partial return unicode strings.")
- def test_make_load_partial__unicode(self):
+ def test_make_resolve_partial__unicode(self):
"""
- Test _make_load_partial(): that load_partial doesn't "double-decode" Unicode.
+ Test _make_resolve_partial(): that resolve_partial doesn't "double-decode" Unicode.
"""
renderer = Renderer()
renderer.partials = {'partial': 'foo'}
- load_partial = renderer._make_load_partial()
- self.assertEqual(load_partial("partial"), "foo")
+ resolve_partial = renderer._make_resolve_partial()
+ self.assertEqual(resolve_partial("partial"), "foo")
# Now with a value that is already unicode.
renderer.partials = {'partial': u'foo'}
- load_partial = renderer._make_load_partial()
+ resolve_partial = renderer._make_resolve_partial()
# If the next line failed, we would get the following error:
# TypeError: decoding Unicode is not supported
- self.assertEqual(load_partial("partial"), "foo")
+ self.assertEqual(resolve_partial("partial"), "foo")
def test_render_path(self):
"""
@@ -406,7 +406,7 @@ class RendererTests(unittest.TestCase, AssertStringMixin):
# we no longer need to exercise all rendering code paths through
# the Renderer. It suffices to test rendering paths through the
# RenderEngine for the same amount of code coverage.
-class Renderer_MakeRenderEngineTests(unittest.TestCase, AssertExceptionMixin):
+class Renderer_MakeRenderEngineTests(unittest.TestCase, AssertStringMixin, AssertExceptionMixin):
"""
Check the RenderEngine returned by Renderer._make_render_engine().
@@ -420,11 +420,11 @@ class Renderer_MakeRenderEngineTests(unittest.TestCase, AssertExceptionMixin):
"""
return _make_renderer()
- ## Test the engine's load_partial attribute.
+ ## Test the engine's resolve_partial attribute.
- def test__load_partial__returns_unicode(self):
+ def test__resolve_partial__returns_unicode(self):
"""
- Check that load_partial returns unicode (and not a subclass).
+ Check that resolve_partial returns unicode (and not a subclass).
"""
class MyUnicode(unicode):
@@ -436,43 +436,70 @@ class Renderer_MakeRenderEngineTests(unittest.TestCase, AssertExceptionMixin):
engine = renderer._make_render_engine()
- actual = engine.load_partial('str')
+ actual = engine.resolve_partial('str')
self.assertEqual(actual, "foo")
self.assertEqual(type(actual), unicode)
# Check that unicode subclasses are not preserved.
- actual = engine.load_partial('subclass')
+ actual = engine.resolve_partial('subclass')
self.assertEqual(actual, "abc")
self.assertEqual(type(actual), unicode)
- def test__load_partial__not_found__default(self):
+ def test__resolve_partial__not_found__default(self):
"""
- Check that load_partial provides a nice message when a template is not found.
+ Check that resolve_partial returns the empty string when a template is not found.
"""
renderer = Renderer()
engine = renderer._make_render_engine()
- load_partial = engine.load_partial
+ resolve_partial = engine.resolve_partial
- self.assertException(TemplateNotFoundError, "File 'foo.mustache' not found in dirs: ['.']",
- load_partial, "foo")
+ self.assertString(resolve_partial('foo'), u'')
- def test__load_partial__not_found__dict(self):
+# TODO: add this test case back when we add support to Renderer for strict mode.
+# def test__resolve_partial__not_found__default(self):
+# """
+# Check that resolve_partial provides a nice message when a template is not found.
+
+# """
+# renderer = Renderer()
+
+# engine = renderer._make_render_engine()
+# resolve_partial = engine.resolve_partial
+
+# self.assertException(TemplateNotFoundError, "File 'foo.mustache' not found in dirs: ['.']",
+# resolve_partial, "foo")
+
+ def test__resolve_partial__not_found__dict(self):
"""
- Check that load_partial provides a nice message when a template is not found.
+ Check that resolve_partial returns the empty string when a template is not found.
"""
renderer = Renderer()
renderer.partials = {}
engine = renderer._make_render_engine()
- load_partial = engine.load_partial
+ resolve_partial = engine.resolve_partial
+
+ self.assertString(resolve_partial('foo'), u'')
+
+# TODO: add this test case back when we add support to Renderer for strict mode.
+# def test__resolve_partial__not_found__dict(self):
+# """
+# Check that resolve_partial provides a nice message when a template is not found.
+
+# """
+# renderer = Renderer()
+# renderer.partials = {}
+
+# engine = renderer._make_render_engine()
+# resolve_partial = engine.resolve_partial
# Include dict directly since str(dict) is different in Python 2 and 3:
# <type 'dict'> versus <class 'dict'>, respectively.
- self.assertException(TemplateNotFoundError, "Name 'foo' not found in partials: %s" % dict,
- load_partial, "foo")
+# self.assertException(TemplateNotFoundError, "Name 'foo' not found in partials: %s" % dict,
+# resolve_partial, "foo")
## Test the engine's literal attribute.