diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-03-23 13:23:44 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-03-23 13:23:44 -0700 |
commit | a27c29158c9a8fe1c03abc9cc715a5f304c93ab7 (patch) | |
tree | d1f8137778876f080b374c39245aed203193b86d | |
parent | d54cc252df3472323504fcc732f3de8152f5b694 (diff) | |
download | pystache-a27c29158c9a8fe1c03abc9cc715a5f304c93ab7.tar.gz |
Made search_dirs an optional argument to Loader.__init__().
-rw-r--r-- | pystache/custom_template.py | 12 | ||||
-rw-r--r-- | tests/test_custom_template.py | 24 |
2 files changed, 28 insertions, 8 deletions
diff --git a/pystache/custom_template.py b/pystache/custom_template.py index 1500014..a16e49a 100644 --- a/pystache/custom_template.py +++ b/pystache/custom_template.py @@ -13,6 +13,7 @@ from .reader import Reader from .renderer import Renderer +# TODO: rename this to Template? class CustomizedTemplate(object): """ @@ -126,16 +127,19 @@ class Loader(object): """ - def __init__(self, search_dirs, locator=None, reader=None): + def __init__(self, search_dirs=None, locator=None, reader=None): + if locator is None: + locator = TemplateLocator() + if reader is None: reader = Reader() - if locator is None: - locator = TemplateLocator() + if search_dirs is None: + search_dirs = [] + self.locator = locator self.reader = reader self.search_dirs = search_dirs - self.locator = locator # TODO: make this private. def get_relative_template_location(self, view): diff --git a/tests/test_custom_template.py b/tests/test_custom_template.py index 40134ae..71b8e5d 100644 --- a/tests/test_custom_template.py +++ b/tests/test_custom_template.py @@ -13,6 +13,7 @@ from examples.simple import Simple from examples.complex_view import ComplexView from examples.lambdas import Lambdas from examples.inverted import Inverted, InvertedLists +from pystache import CustomizedTemplate as Template from pystache import Renderer from pystache import View from pystache.custom_template import Loader @@ -142,16 +143,19 @@ class LoaderTests(unittest.TestCase, AssertIsMixin): """ def test_init__defaults(self): - loader = Loader([]) + loader = Loader() + + # Check the locator attribute. + locator = loader.locator + self.assertEquals(locator.template_extension, 'mustache') # Check the reader attribute. reader = loader.reader self.assertEquals(reader.decode_errors, 'strict') self.assertEquals(reader.encoding, sys.getdefaultencoding()) - # Check the locator attribute. - locator = loader.locator - self.assertEquals(locator.template_extension, 'mustache') + # Check search_dirs. + self.assertEquals(loader.search_dirs, []) def test_init__search_dirs(self): search_dirs = ['a', 'b'] @@ -171,6 +175,18 @@ class LoaderTests(unittest.TestCase, AssertIsMixin): self.assertIs(loader.locator, locator) + def test_load__template__basic(self): + """ + Test the template attribute. + + """ + template = Template() + template.template = "abc" + + loader = Loader() + self.assertEquals(loader.load(template), "wxy") + + # TODO: migrate these tests into the LoaderTests class. # TODO: rename the get_template() tests to test load(). |