Commit 50d6a535 by Chris Jerdonek

Exposed an html_escape function in tests.common for consistent Python 2/3 testing.

parent 9b167cc1
......@@ -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)
......
# 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}}"
......
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