Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
50d6a535
Commit
50d6a535
authored
Apr 08, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exposed an html_escape function in tests.common for consistent Python 2/3 testing.
parent
9b167cc1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletions
+26
-1
pystache/tests/common.py
+14
-0
pystache/tests/test_pystache.py
+12
-1
No files found.
pystache/tests/common.py
View file @
50d6a535
...
...
@@ -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
)
...
...
pystache/tests/test_pystache.py
View file @
50d6a535
# 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}}"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment