Commit 4d8d41bb by Chris Jerdonek

Renamed CustomLoader to SpecLoader.

parent 1542217e
...@@ -119,10 +119,9 @@ class View(TemplateSpec): ...@@ -119,10 +119,9 @@ class View(TemplateSpec):
return renderer.render(template, self.context) return renderer.render(template, self.context)
# TODO: finalize this class's name.
# TODO: get this class fully working with test cases, and then refactor # TODO: get this class fully working with test cases, and then refactor
# and replace the View class. # and replace the View class.
class CustomLoader(object): class SpecLoader(object):
""" """
Supports loading a custom-specified template. Supports loading a custom-specified template.
......
...@@ -16,7 +16,7 @@ from examples.inverted import Inverted, InvertedLists ...@@ -16,7 +16,7 @@ from examples.inverted import Inverted, InvertedLists
from pystache import TemplateSpec as Template from pystache import TemplateSpec as Template
from pystache import Renderer from pystache import Renderer
from pystache import View from pystache import View
from pystache.template_spec import CustomLoader from pystache.template_spec import SpecLoader
from pystache.locator import Locator from pystache.locator import Locator
from pystache.loader import Loader from pystache.loader import Loader
from .common import AssertIsMixin from .common import AssertIsMixin
...@@ -136,15 +136,15 @@ class ViewTestCase(unittest.TestCase): ...@@ -136,15 +136,15 @@ class ViewTestCase(unittest.TestCase):
self.assertEquals(view.render(), """one, two, three, empty list""") self.assertEquals(view.render(), """one, two, three, empty list""")
class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): class SpecLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
""" """
Tests template_spec.CustomLoader. Tests template_spec.SpecLoader.
""" """
def test_init__defaults(self): def test_init__defaults(self):
custom = CustomLoader() custom = SpecLoader()
# Check the loader attribute. # Check the loader attribute.
loader = custom.loader loader = custom.loader
...@@ -157,13 +157,13 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -157,13 +157,13 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
def test_init__search_dirs(self): def test_init__search_dirs(self):
search_dirs = ['a', 'b'] search_dirs = ['a', 'b']
loader = CustomLoader(search_dirs) loader = SpecLoader(search_dirs)
self.assertEquals(loader.search_dirs, ['a', 'b']) self.assertEquals(loader.search_dirs, ['a', 'b'])
def test_init__loader(self): def test_init__loader(self):
loader = Loader() loader = Loader()
custom = CustomLoader([], loader=loader) custom = SpecLoader([], loader=loader)
self.assertIs(custom.loader, loader) self.assertIs(custom.loader, loader)
...@@ -179,7 +179,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -179,7 +179,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
custom = Template() custom = Template()
custom.template = "abc" custom.template = "abc"
self._assert_template(CustomLoader(), custom, u"abc") self._assert_template(SpecLoader(), custom, u"abc")
def test_load__template__type_unicode(self): def test_load__template__type_unicode(self):
""" """
...@@ -189,7 +189,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -189,7 +189,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
custom = Template() custom = Template()
custom.template = u"abc" custom.template = u"abc"
self._assert_template(CustomLoader(), custom, u"abc") self._assert_template(SpecLoader(), custom, u"abc")
def test_load__template__unicode_non_ascii(self): def test_load__template__unicode_non_ascii(self):
""" """
...@@ -199,7 +199,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -199,7 +199,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
custom = Template() custom = Template()
custom.template = u"é" custom.template = u"é"
self._assert_template(CustomLoader(), custom, u"é") self._assert_template(SpecLoader(), custom, u"é")
def test_load__template__with_template_encoding(self): def test_load__template__with_template_encoding(self):
""" """
...@@ -209,10 +209,10 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -209,10 +209,10 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
custom = Template() custom = Template()
custom.template = u'é'.encode('utf-8') custom.template = u'é'.encode('utf-8')
self.assertRaises(UnicodeDecodeError, self._assert_template, CustomLoader(), custom, u'é') self.assertRaises(UnicodeDecodeError, self._assert_template, SpecLoader(), custom, u'é')
custom.template_encoding = 'utf-8' custom.template_encoding = 'utf-8'
self._assert_template(CustomLoader(), custom, u'é') self._assert_template(SpecLoader(), custom, u'é')
# TODO: make this test complete. # TODO: make this test complete.
def test_load__template__correct_loader(self): def test_load__template__correct_loader(self):
...@@ -221,7 +221,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -221,7 +221,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
This test tests that the correct reader is called with the correct This test tests that the correct reader is called with the correct
arguments. This is a catch-all test to supplement the other arguments. This is a catch-all test to supplement the other
test cases. It tests CustomLoader.load() independent of reader.unicode() test cases. It tests SpecLoader.load() independent of reader.unicode()
being implemented correctly (and tested). being implemented correctly (and tested).
""" """
...@@ -238,7 +238,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -238,7 +238,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
return u"foo" return u"foo"
loader = MockLoader() loader = MockLoader()
custom_loader = CustomLoader() custom_loader = SpecLoader()
custom_loader.loader = loader custom_loader.loader = loader
view = Template() view = Template()
...@@ -251,7 +251,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin): ...@@ -251,7 +251,7 @@ class CustomLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
self.assertEquals(loader.encoding, "encoding-foo") self.assertEquals(loader.encoding, "encoding-foo")
# TODO: migrate these tests into the CustomLoaderTests class. # TODO: migrate these tests into the SpecLoaderTests class.
# TODO: rename the get_template() tests to test load(). # TODO: rename the get_template() tests to test load().
# TODO: condense, reorganize, and rename the tests so that it is # TODO: condense, reorganize, and rename the tests so that it is
# clear whether we have full test coverage (e.g. organized by # clear whether we have full test coverage (e.g. organized by
...@@ -260,7 +260,7 @@ class TemplateSpecTests(unittest.TestCase): ...@@ -260,7 +260,7 @@ class TemplateSpecTests(unittest.TestCase):
# TODO: rename this method to _make_loader(). # TODO: rename this method to _make_loader().
def _make_locator(self): def _make_locator(self):
locator = CustomLoader(search_dirs=[DATA_DIR]) locator = SpecLoader(search_dirs=[DATA_DIR])
return locator return locator
def _assert_template_location(self, view, expected): def _assert_template_location(self, view, expected):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment