summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-03-24 14:27:07 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-03-24 14:27:07 -0700
commitc2a31361f3e4e579a10a18794295ee08cb11cfa9 (patch)
tree8fa51fb0afd4ed4bb514f38789442dd221e6c808
parent830eaa7b77fdf3220e5570dc84047ae11998198b (diff)
downloadpystache-c2a31361f3e4e579a10a18794295ee08cb11cfa9.tar.gz
More progress on LoaderTests: template attribute.
-rw-r--r--pystache/custom_template.py2
-rw-r--r--tests/test_custom_template.py49
2 files changed, 43 insertions, 8 deletions
diff --git a/pystache/custom_template.py b/pystache/custom_template.py
index 52435e7..31a4888 100644
--- a/pystache/custom_template.py
+++ b/pystache/custom_template.py
@@ -123,7 +123,7 @@ class View(CustomizedTemplate):
class Loader(object):
"""
- Supports loading the template of a CustomizedTemplate instance.
+ Supports loading a custom-specified template.
"""
diff --git a/tests/test_custom_template.py b/tests/test_custom_template.py
index 3e53190..c03dcd7 100644
--- a/tests/test_custom_template.py
+++ b/tests/test_custom_template.py
@@ -139,7 +139,7 @@ class ViewTestCase(unittest.TestCase):
class LoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
"""
- Tests the custom_template.Loader class.
+ Tests custom_template.Loader.
"""
@@ -176,16 +176,51 @@ class LoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
self.assertIs(loader.locator, locator)
- def test_load__template__basic(self):
+ def _assert_template(self, loader, custom, expected):
+ self.assertString(loader.load(custom), expected)
+
+ def test_load__template__type_str(self):
"""
- Test the template attribute.
+ Test the template attribute: str string.
"""
- template = Template()
- template.template = "abc"
+ custom = Template()
+ custom.template = "abc"
- loader = Loader()
- self.assertString(loader.load(template), u"abc")
+ self._assert_template(Loader(), custom, u"abc")
+
+ def test_load__template__type_unicode(self):
+ """
+ Test the template attribute: unicode string.
+
+ """
+ custom = Template()
+ custom.template = u"abc"
+
+ self._assert_template(Loader(), custom, u"abc")
+
+ def test_load__template__unicode_non_ascii(self):
+ """
+ Test the template attribute: non-ascii unicode string.
+
+ """
+ custom = Template()
+ custom.template = u"é"
+
+ self._assert_template(Loader(), custom, u"é")
+
+ def test_load__template__with_template_encoding(self):
+ """
+ Test the template attribute: with template encoding attribute.
+
+ """
+ custom = Template()
+ custom.template = u'é'.encode('utf-8')
+
+ self.assertRaises(UnicodeDecodeError, self._assert_template, Loader(), custom, u'é')
+
+ custom.template_encoding = 'utf-8'
+ self._assert_template(Loader(), custom, u'é')
# TODO: migrate these tests into the LoaderTests class.