summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-07-23 07:50:48 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-07-23 07:50:48 -0700
commit6ddc457d034a64f3247e4a2f9658525c5ed3c857 (patch)
treeab56dc5cf7e5c09214143ab5316fe2ec62110ecc /pystache
parent796d26392fe2d2b6e71e91ea6017d7e9c10b44b9 (diff)
downloadpystache-6ddc457d034a64f3247e4a2f9658525c5ed3c857.tar.gz
Add unit tests for Loader.load_file() and Loader.load_name().
Diffstat (limited to 'pystache')
-rw-r--r--pystache/loader.py8
-rw-r--r--pystache/tests/test_loader.py17
2 files changed, 19 insertions, 6 deletions
diff --git a/pystache/loader.py b/pystache/loader.py
index 018ea62..5855392 100644
--- a/pystache/loader.py
+++ b/pystache/loader.py
@@ -42,9 +42,9 @@ class Loader(object):
Arguments:
- extension: the template file extension. Pass False for no
- extension (i.e. to use extensionless template files).
- Defaults to the package default.
+ extension: the template file extension, without the leading dot.
+ Pass False for no extension (e.g. to use extensionless template
+ files). Defaults to the package default.
file_encoding: the name of the encoding to use when converting file
contents to unicode. Defaults to the package default.
@@ -119,7 +119,6 @@ class Loader(object):
return self.unicode(b, encoding)
- # TODO: unit-test this method.
def load_file(self, file_name):
"""
Find and return the template with the given file name.
@@ -135,7 +134,6 @@ class Loader(object):
return self.read(path)
- # TODO: unit-test this method.
def load_name(self, name):
"""
Find and return the template with the given template name.
diff --git a/pystache/tests/test_loader.py b/pystache/tests/test_loader.py
index c47239c..f2c2187 100644
--- a/pystache/tests/test_loader.py
+++ b/pystache/tests/test_loader.py
@@ -14,6 +14,10 @@ from pystache import defaults
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):
def setUp(self):
@@ -178,7 +182,7 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
actual = loader.read(path, encoding='utf-8')
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.
@@ -192,3 +196,14 @@ class LoaderTests(unittest.TestCase, AssertStringMixin, SetupDefaults):
#actual = loader.read(path)
#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')
+