Commit c414a5ca by Chris Jerdonek

Made 6 more tests pass in Python 3 (and simultaneously, Python 2)..

parent 50d6a535
...@@ -12,6 +12,7 @@ import pystache ...@@ -12,6 +12,7 @@ import pystache
from pystache import defaults from pystache import defaults
# Save a reference to the original function to avoid recursion.
_DEFAULT_TAG_ESCAPE = defaults.TAG_ESCAPE _DEFAULT_TAG_ESCAPE = defaults.TAG_ESCAPE
_TESTS_DIR = os.path.dirname(pystache.tests.__file__) _TESTS_DIR = os.path.dirname(pystache.tests.__file__)
...@@ -29,6 +30,10 @@ def html_escape(u): ...@@ -29,6 +30,10 @@ def html_escape(u):
This function is needed because single quotes are escaped in Python 3 This function is needed because single quotes are escaped in Python 3
(to '''), but not in Python 2. (to '''), but not in Python 2.
The global defaults.TAG_ESCAPE can be set to this function in the
setUp() and tearDown() of unittest test cases, for example, for
consistent test results.
""" """
u = _DEFAULT_TAG_ESCAPE(u) u = _DEFAULT_TAG_ESCAPE(u)
return u.replace("'", ''') return u.replace("'", ''')
......
...@@ -16,6 +16,19 @@ from pystache.loader import Loader ...@@ -16,6 +16,19 @@ from pystache.loader import Loader
class LoaderTests(unittest.TestCase, AssertStringMixin): class LoaderTests(unittest.TestCase, AssertStringMixin):
# Switching to standard encodings allows for consistent test
# results across Python 2/3.
def setUp(self):
self.original_string_encoding = defaults.STRING_ENCODING
self.original_file_encoding = defaults.FILE_ENCODING
defaults.STRING_ENCODING = 'ascii'
defaults.FILE_ENCODING = 'ascii'
def tearDown(self):
defaults.STRING_ENCODING = self.original_string_encoding
defaults.FILE_ENCODING = self.original_file_encoding
def test_init__extension(self): def test_init__extension(self):
loader = Loader(extension='foo') loader = Loader(extension='foo')
self.assertEqual(loader.extension, 'foo') self.assertEqual(loader.extension, 'foo')
......
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