Commit a27c2915 by Chris Jerdonek

Made search_dirs an optional argument to Loader.__init__().

parent d54cc252
...@@ -13,6 +13,7 @@ from .reader import Reader ...@@ -13,6 +13,7 @@ from .reader import Reader
from .renderer import Renderer from .renderer import Renderer
# TODO: rename this to Template?
class CustomizedTemplate(object): class CustomizedTemplate(object):
""" """
...@@ -126,16 +127,19 @@ class Loader(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: if reader is None:
reader = Reader() reader = Reader()
if locator is None: if search_dirs is None:
locator = TemplateLocator() search_dirs = []
self.locator = locator
self.reader = reader self.reader = reader
self.search_dirs = search_dirs self.search_dirs = search_dirs
self.locator = locator
# TODO: make this private. # TODO: make this private.
def get_relative_template_location(self, view): def get_relative_template_location(self, view):
......
...@@ -13,6 +13,7 @@ from examples.simple import Simple ...@@ -13,6 +13,7 @@ from examples.simple import Simple
from examples.complex_view import ComplexView from examples.complex_view import ComplexView
from examples.lambdas import Lambdas from examples.lambdas import Lambdas
from examples.inverted import Inverted, InvertedLists from examples.inverted import Inverted, InvertedLists
from pystache import CustomizedTemplate as Template
from pystache import Renderer from pystache import Renderer
from pystache import View from pystache import View
from pystache.custom_template import Loader from pystache.custom_template import Loader
...@@ -142,16 +143,19 @@ class LoaderTests(unittest.TestCase, AssertIsMixin): ...@@ -142,16 +143,19 @@ class LoaderTests(unittest.TestCase, AssertIsMixin):
""" """
def test_init__defaults(self): 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. # Check the reader attribute.
reader = loader.reader reader = loader.reader
self.assertEquals(reader.decode_errors, 'strict') self.assertEquals(reader.decode_errors, 'strict')
self.assertEquals(reader.encoding, sys.getdefaultencoding()) self.assertEquals(reader.encoding, sys.getdefaultencoding())
# Check the locator attribute. # Check search_dirs.
locator = loader.locator self.assertEquals(loader.search_dirs, [])
self.assertEquals(locator.template_extension, 'mustache')
def test_init__search_dirs(self): def test_init__search_dirs(self):
search_dirs = ['a', 'b'] search_dirs = ['a', 'b']
...@@ -171,6 +175,18 @@ class LoaderTests(unittest.TestCase, AssertIsMixin): ...@@ -171,6 +175,18 @@ class LoaderTests(unittest.TestCase, AssertIsMixin):
self.assertIs(loader.locator, locator) 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: migrate these tests into the LoaderTests class.
# TODO: rename the get_template() tests to test load(). # TODO: rename the get_template() tests to test load().
......
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