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
54eb4b50
Commit
54eb4b50
authored
Apr 29, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored spectesting.py: added _convert_children() function.
parent
21ab97cd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
8 deletions
+33
-8
pystache/tests/spectesting.py
+33
-8
No files found.
pystache/tests/spectesting.py
View file @
54eb4b50
...
...
@@ -115,6 +115,37 @@ def _read_spec_tests(path):
return
cases
# TODO: simplify the implementation of this function.
def
_convert_children
(
node
):
"""
Recursively convert to functions all "code strings" below the node.
This function is needed only for the json format.
"""
if
not
isinstance
(
node
,
(
list
,
dict
)):
# Then there is nothing to iterate over and recurse.
return
if
isinstance
(
node
,
list
):
for
child
in
node
:
_convert_children
(
child
)
return
# Otherwise, node is a dict, so attempt the conversion.
for
key
in
node
.
keys
():
val
=
node
[
key
]
if
not
isinstance
(
val
,
dict
)
or
val
.
get
(
'__tag__'
)
!=
'code'
:
_convert_children
(
val
)
continue
# Otherwise, we are at a "leaf" node.
val
=
eval
(
val
[
'python'
])
node
[
key
]
=
val
continue
def
_deserialize_spec_test
(
data
,
file_path
):
"""
Return a unittest.TestCase instance representing a spec test.
...
...
@@ -124,7 +155,7 @@ def _deserialize_spec_test(data, file_path):
data: the dictionary of attributes for a single test.
"""
unconverted_
context
=
data
[
'data'
]
context
=
data
[
'data'
]
description
=
data
[
'desc'
]
# PyYAML seems to leave ASCII strings as byte strings.
expected
=
unicode
(
data
[
'expected'
])
...
...
@@ -133,13 +164,7 @@ def _deserialize_spec_test(data, file_path):
template
=
data
[
'template'
]
test_name
=
data
[
'name'
]
# Convert code strings to functions.
# TODO: make this section of code easier to understand.
context
=
{}
for
key
,
val
in
unconverted_context
.
iteritems
():
if
isinstance
(
val
,
dict
)
and
val
.
get
(
'__tag__'
)
==
'code'
:
val
=
eval
(
val
[
'python'
])
context
[
key
]
=
val
_convert_children
(
context
)
test_case
=
_make_spec_test
(
expected
,
template
,
context
,
partials
,
description
,
test_name
,
file_path
)
...
...
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