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
ad539070
Commit
ad539070
authored
Apr 08, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up test_renderengine unit tests related to built-in types.
parent
478d740c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
14 deletions
+41
-14
pystache/tests/test_renderengine.py
+41
-14
No files found.
pystache/tests/test_renderengine.py
View file @
ad539070
...
...
@@ -186,35 +186,62 @@ class RenderTests(unittest.TestCase, AssertStringMixin):
context
=
{
'test'
:
'{{#hello}}'
}
self
.
_assert_render
(
u'{{#hello}}'
,
template
,
context
)
# Built-in types:
#
# Confirm that we not treat instances of built-in types as objects,
# for example by calling a method on a built-in type instance when it
# has a method whose name matches the current key.
#
# Each test case puts an instance of a built-in type on top of the
# context stack before interpolating a tag whose key matches an
# attribute (method or property) of the instance.
#
def
_assert_builtin_attr
(
self
,
item
,
attr_name
,
expected_attr
):
self
.
assertTrue
(
hasattr
(
item
,
attr_name
))
actual
=
getattr
(
item
,
attr_name
)
if
callable
(
actual
):
actual
=
actual
()
self
.
assertEqual
(
actual
,
expected_attr
)
def
_assert_builtin_type
(
self
,
item
,
attr_name
,
expected_attr
,
expected_template
):
self
.
_assert_builtin_attr
(
item
,
attr_name
,
expected_attr
)
template
=
'{{#section}}{{
%
s}}{{/section}}'
%
attr_name
context
=
{
'section'
:
item
,
attr_name
:
expected_template
}
self
.
_assert_render
(
expected_template
,
template
,
context
)
def
test_interpolation__built_in_type__string
(
self
):
"""
Check tag interpolation with a
string on the top of the context stack
.
Check tag interpolation with a
built-in type: string
.
"""
item
=
'abc'
# item.upper() == 'ABC'
template
=
'{{#section}}{{upper}}{{/section}}'
context
=
{
'section'
:
item
,
'upper'
:
'XYZ'
}
self
.
_assert_render
(
u'XYZ'
,
template
,
context
)
self
.
_assert_builtin_type
(
'abc'
,
'upper'
,
'ABC'
,
u'xyz'
)
def
test_interpolation__built_in_type__integer
(
self
):
"""
Check tag interpolation with a
n integer on the top of the context stack
.
Check tag interpolation with a
built-in type: integer
.
"""
item
=
10
# item.real == 10
template
=
'{{#section}}{{real}}{{/section}}'
context
=
{
'section'
:
item
,
'real'
:
1000
}
self
.
_assert_render
(
u'1000'
,
template
,
context
)
# Since public attributes weren't added to integers until Python 2.6
# (for example the "real" attribute of the numeric type hierarchy)--
#
# http://docs.python.org/library/numbers.html
#
# we need to resort to built-in attributes (double-underscored) on
# the integer type.
self
.
_assert_builtin_type
(
15
,
'__hex__'
,
'0xf'
,
u'999'
)
def
test_interpolation__built_in_type__list
(
self
):
"""
Check tag interpolation with a
list on the top of the context stack
.
Check tag interpolation with a
built-in type: list
.
"""
item
=
[[
1
,
2
,
3
]]
# item[0].pop() == 3
attr_name
=
'pop'
# Make a copy to prevent changes to item[0].
self
.
_assert_builtin_attr
(
list
(
item
[
0
]),
attr_name
,
3
)
template
=
'{{#section}}{{pop}}{{/section}}'
context
=
{
'section'
:
item
,
'pop'
:
7
}
self
.
_assert_render
(
u'7'
,
template
,
context
)
...
...
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