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
4eaa43b5
Commit
4eaa43b5
authored
Dec 25, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved display format of spec tests and fixed partials typo.
parent
17ce2986
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
8 deletions
+35
-8
tests/test_spec.py
+35
-8
No files found.
tests/test_spec.py
View file @
4eaa43b5
# coding: utf-8
"""
Tests the mustache spec test cases.
"""
import
glob
import
os.path
import
pystache
import
unittest
import
yaml
from
pystache.renderer
import
Renderer
def
code_constructor
(
loader
,
node
):
value
=
loader
.
construct_mapping
(
node
)
return
eval
(
value
[
'python'
],
{})
...
...
@@ -16,23 +25,41 @@ specs = glob.glob(os.path.join(specs, '*.yml'))
class
MustacheSpec
(
unittest
.
TestCase
):
pass
def
buildTest
(
testData
,
spec
):
def
buildTest
(
testData
,
spec_filename
):
name
=
testData
[
'name'
]
description
=
testData
[
'desc'
]
test_name
=
"
%
s (
%
s)"
%
(
name
,
spec_filename
)
def
test
(
self
):
template
=
testData
[
'template'
]
partials
=
testData
.
has_key
(
'partials'
)
and
test
[
'partials'
]
or
{}
partials
=
testData
.
has_key
(
'partials'
)
and
test
Data
[
'partials'
]
or
{}
expected
=
testData
[
'expected'
]
data
=
testData
[
'data'
]
self
.
assertEquals
(
pystache
.
render
(
template
,
data
),
expected
)
test
.
__doc__
=
testData
[
'desc'
]
test
.
__name__
=
'test
%
s (
%
s)'
%
(
testData
[
'name'
],
spec
)
renderer
=
Renderer
(
loader
=
partials
)
actual
=
renderer
.
render
(
template
,
data
)
.
encode
(
'utf-8'
)
message
=
"""
%
s
Template:
\"
""
%
s
\"
""
Expected:
%
s
Actual:
%
s"""
%
(
description
,
template
,
repr
(
expected
),
repr
(
actual
))
self
.
assertEquals
(
actual
,
expected
,
message
)
# The name must begin with "test" for nosetests test discovery to work.
test
.
__name__
=
'test: "
%
s"'
%
test_name
return
test
for
spec
in
specs
:
name
=
os
.
path
.
basename
(
spec
)
.
replace
(
'.yml'
,
''
)
file_name
=
os
.
path
.
basename
(
spec
)
for
test
in
yaml
.
load
(
open
(
spec
))[
'tests'
]:
test
=
buildTest
(
test
,
name
)
test
=
buildTest
(
test
,
file_
name
)
setattr
(
MustacheSpec
,
test
.
__name__
,
test
)
if
__name__
==
'__main__'
:
...
...
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