Commit 6ddc457d by Chris Jerdonek

Add unit tests for Loader.load_file() and Loader.load_name().

parent 796d2639
...@@ -42,9 +42,9 @@ class Loader(object): ...@@ -42,9 +42,9 @@ class Loader(object):
Arguments: Arguments:
extension: the template file extension. Pass False for no extension: the template file extension, without the leading dot.
extension (i.e. to use extensionless template files). Pass False for no extension (e.g. to use extensionless template
Defaults to the package default. files). Defaults to the package default.
file_encoding: the name of the encoding to use when converting file file_encoding: the name of the encoding to use when converting file
contents to unicode. Defaults to the package default. contents to unicode. Defaults to the package default.
...@@ -119,7 +119,6 @@ class Loader(object): ...@@ -119,7 +119,6 @@ class Loader(object):
return self.unicode(b, encoding) return self.unicode(b, encoding)
# TODO: unit-test this method.
def load_file(self, file_name): def load_file(self, file_name):
""" """
Find and return the template with the given file name. Find and return the template with the given file name.
...@@ -135,7 +134,6 @@ class Loader(object): ...@@ -135,7 +134,6 @@ class Loader(object):
return self.read(path) return self.read(path)
# TODO: unit-test this method.
def load_name(self, name): def load_name(self, name):
""" """
Find and return the template with the given template name. Find and return the template with the given template name.
......
...@@ -14,6 +14,10 @@ from pystache import defaults ...@@ -14,6 +14,10 @@ from pystache import defaults
from pystache.loader import Loader from pystache.loader import Loader
# We use the same directory as the locator tests for now.
LOADER_DATA_DIR = os.path.join(DATA_DIR, 'locator')
class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
def setUp(self): def setUp(self):
...@@ -178,7 +182,7 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -178,7 +182,7 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
actual = loader.read(path, encoding='utf-8') actual = loader.read(path, encoding='utf-8')
self.assertString(actual, u'non-ascii: é') self.assertString(actual, u'non-ascii: é')
def test_loader__to_unicode__attribute(self): def test_read__to_unicode__attribute(self):
""" """
Test read(): to_unicode attribute respected. Test read(): to_unicode attribute respected.
...@@ -192,3 +196,14 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults): ...@@ -192,3 +196,14 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
#actual = loader.read(path) #actual = loader.read(path)
#self.assertString(actual, u'non-ascii: ') #self.assertString(actual, u'non-ascii: ')
def test_load_file(self):
loader = Loader(search_dirs=[DATA_DIR, LOADER_DATA_DIR])
template = loader.load_file('template.txt')
self.assertEqual(template, 'Test template file\n')
def test_load_name(self):
loader = Loader(search_dirs=[DATA_DIR, LOADER_DATA_DIR],
extension='txt')
template = loader.load_name('template')
self.assertEqual(template, 'Test template file\n')
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