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
166f7c60
Commit
166f7c60
authored
Apr 08, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up test_mustachespec.py somewhat.
parent
17919ab6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
36 deletions
+12
-36
pystache/tests/test_mustachespec.py
+12
-36
No files found.
pystache/tests/test_mustachespec.py
View file @
166f7c60
...
@@ -9,6 +9,7 @@ Creates a unittest.TestCase for the tests defined in the mustache spec.
...
@@ -9,6 +9,7 @@ Creates a unittest.TestCase for the tests defined in the mustache spec.
FILE_ENCODING
=
'utf-8'
# the encoding of the spec test files.
FILE_ENCODING
=
'utf-8'
# the encoding of the spec test files.
yaml
=
None
try
:
try
:
# We try yaml first since it is more convenient when adding and modifying
# We try yaml first since it is more convenient when adding and modifying
...
@@ -37,23 +38,22 @@ import os.path
...
@@ -37,23 +38,22 @@ import os.path
import
unittest
import
unittest
import
pystache
import
pystache
from
pystache
import
common
from
pystache.renderer
import
Renderer
from
pystache.renderer
import
Renderer
from
pystache.tests.common
import
AssertStringMixin
,
SPEC_TEST_DIR
from
pystache.tests.common
import
AssertStringMixin
,
SPEC_TEST_DIR
spec_paths
=
glob
.
glob
(
os
.
path
.
join
(
SPEC_TEST_DIR
,
'*.
%
s'
%
file_extension
))
def
parse
(
u
):
def
parse
(
u
,
file_extension
):
"""
"""
Parse
Arguments:
Arguments:
u: a unicode string.
u: a unicode string.
"""
"""
# TODO: find a cleaner mechanism for choosing between the two.
# TODO: find a cleaner mechanism for choosing between the two.
if
file_extension
[
0
]
==
'j'
:
if
yaml
is
None
:
# Then json.
# Then
use
json.
# The only way to get the simplejson module to return unicode strings
# The only way to get the simplejson module to return unicode strings
# is to pass it unicode. See, for example--
# is to pass it unicode. See, for example--
...
@@ -157,38 +157,14 @@ def buildTest(testData, spec_filename, parser):
...
@@ -157,38 +157,14 @@ def buildTest(testData, spec_filename, parser):
return
test
return
test
for
spec_path
in
spec_paths
:
spec_paths
=
glob
.
glob
(
os
.
path
.
join
(
SPEC_TEST_DIR
,
'*.
%
s'
%
file_extension
))
for
path
in
spec_paths
:
file_name
=
os
.
path
.
basename
(
spec_
path
)
file_name
=
os
.
path
.
basename
(
path
)
# We use codecs.open() for pre Python 2.6 support and because it ports
b
=
common
.
read
(
path
)
# correctly to Python 3:
u
=
unicode
(
b
,
encoding
=
FILE_ENCODING
)
#
spec_data
=
parse
(
u
)
# "If pre-2.6 compatibility is needed, then you should use codecs.open()
# instead. This will make sure that you get back unicode strings in Python 2."
#
# (from http://docs.python.org/py3k/howto/pyporting.html#text-files )
#
# TODO: share code here with pystache's open() code.
f
=
codecs
.
open
(
spec_path
,
'r'
,
encoding
=
FILE_ENCODING
)
try
:
u
=
f
.
read
()
finally
:
f
.
close
()
# The only way to get the simplejson module to return unicode strings
# is to pass it unicode. See, for example--
#
# http://code.google.com/p/simplejson/issues/detail?id=40
#
# and the documentation of simplejson.loads():
#
# "If s is a str then decoded JSON strings that contain only ASCII
# characters may be parsed as str for performance and memory reasons.
# If your code expects only unicode the appropriate solution is
# decode s to unicode prior to calling loads."
#
spec_data
=
parse
(
u
,
file_extension
)
tests
=
spec_data
[
'tests'
]
tests
=
spec_data
[
'tests'
]
...
...
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