diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-08 18:10:55 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-08 18:10:55 -0700 |
commit | 50d6a535687ae29e9dcf4707bd03dad4f885f933 (patch) | |
tree | f6b2acc0a0a31c3b99680cc8385069cc6cfb4798 /pystache | |
parent | 9b167cc11b4f86346cdcd142a8fdcae8fb51146f (diff) | |
download | pystache-50d6a535687ae29e9dcf4707bd03dad4f885f933.tar.gz |
Exposed an html_escape function in tests.common for consistent Python 2/3 testing.
Diffstat (limited to 'pystache')
-rw-r--r-- | pystache/tests/common.py | 14 | ||||
-rw-r--r-- | pystache/tests/test_pystache.py | 13 |
2 files changed, 26 insertions, 1 deletions
diff --git a/pystache/tests/common.py b/pystache/tests/common.py index 538784b..3bbe1e4 100644 --- a/pystache/tests/common.py +++ b/pystache/tests/common.py @@ -9,8 +9,10 @@ import os import examples import pystache +from pystache import defaults +_DEFAULT_TAG_ESCAPE = defaults.TAG_ESCAPE _TESTS_DIR = os.path.dirname(pystache.tests.__file__) DATA_DIR = os.path.join(_TESTS_DIR, 'data') # i.e. 'pystache/tests/data'. @@ -20,6 +22,18 @@ PROJECT_DIR = os.path.join(SOURCE_DIR, '..') SPEC_TEST_DIR = os.path.join(PROJECT_DIR, 'ext', 'spec', 'specs') +def html_escape(u): + """ + An html escape function that behaves the same in both Python 2 and 3. + + This function is needed because single quotes are escaped in Python 3 + (to '''), but not in Python 2. + + """ + u = _DEFAULT_TAG_ESCAPE(u) + return u.replace("'", ''') + + def get_data_path(file_name): return os.path.join(DATA_DIR, file_name) diff --git a/pystache/tests/test_pystache.py b/pystache/tests/test_pystache.py index e241842..5447f8d 100644 --- a/pystache/tests/test_pystache.py +++ b/pystache/tests/test_pystache.py @@ -1,12 +1,23 @@ # encoding: utf-8 import unittest + import pystache +from pystache import defaults from pystache import renderer +from pystache.tests.common import html_escape class PystacheTests(unittest.TestCase): + + def setUp(self): + self.original_escape = defaults.TAG_ESCAPE + defaults.TAG_ESCAPE = html_escape + + def tearDown(self): + defaults.TAG_ESCAPE = self.original_escape + def _assert_rendered(self, expected, template, context): actual = pystache.render(template, context) self.assertEqual(actual, expected) @@ -54,7 +65,7 @@ class PystacheTests(unittest.TestCase): context = { 'set': True } self._assert_rendered("Ready set go!", template, context) - non_strings_expected = """(123 & ['something'])(chris & 0.9)""" + non_strings_expected = """(123 & ['something'])(chris & 0.9)""" def test_non_strings(self): template = "{{#stats}}({{key}} & {{value}}){{/stats}}" |