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
abea8bad
Commit
abea8bad
authored
Jan 07, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganized (renamed and reordered) some rendering test cases.
parent
804c8712
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
78 deletions
+80
-78
tests/test_renderengine.py
+80
-78
No files found.
tests/test_renderengine.py
View file @
abea8bad
...
...
@@ -159,7 +159,25 @@ class RenderTests(unittest.TestCase):
self
.
_assert_render
(
'FOO 100 100'
,
template
,
context
,
engine
=
engine
)
def
test__implicit_iterator__literal
(
self
):
def
test_tag__output_not_interpolated
(
self
):
"""
Context values should not be treated as templates (issue #44).
"""
template
=
'{{test}}'
context
=
{
'test'
:
'{{hello}}'
}
self
.
_assert_render
(
'{{hello}}'
,
template
,
context
)
def
test_tag__output_not_interpolated__section
(
self
):
"""
Context values should not be treated as templates (issue #44).
"""
template
=
'{{test}}'
context
=
{
'test'
:
'{{#hello}}'
}
self
.
_assert_render
(
'{{#hello}}'
,
template
,
context
)
def
test_implicit_iterator__literal
(
self
):
"""
Test an implicit iterator in a literal tag.
...
...
@@ -169,7 +187,7 @@ class RenderTests(unittest.TestCase):
self
.
_assert_render
(
'<>'
,
template
,
context
)
def
test_
_
implicit_iterator__escaped
(
self
):
def
test_implicit_iterator__escaped
(
self
):
"""
Test an implicit iterator in a normal tag.
...
...
@@ -179,7 +197,7 @@ class RenderTests(unittest.TestCase):
self
.
_assert_render
(
'<>'
,
template
,
context
)
def
test_
_
literal__in_section
(
self
):
def
test_literal__in_section
(
self
):
"""
Check that literals work in sections.
...
...
@@ -189,7 +207,7 @@ class RenderTests(unittest.TestCase):
self
.
_assert_render
(
'1 < 2'
,
template
,
context
)
def
test_
_
literal__in_partial
(
self
):
def
test_literal__in_partial
(
self
):
"""
Check that literals work in partials.
...
...
@@ -200,11 +218,26 @@ class RenderTests(unittest.TestCase):
self
.
_assert_render
(
'1 < 2'
,
template
,
context
,
partials
=
partials
)
def
test_
render_with_
partial
(
self
):
def
test_partial
(
self
):
partials
=
{
'partial'
:
"{{person}}"
}
self
.
_assert_render
(
'Hi Mom'
,
'Hi {{>partial}}'
,
{
'person'
:
'Mom'
},
partials
=
partials
)
def
test_render__section_context_values
(
self
):
def
test_partial__context_values
(
self
):
"""
Test that escape and literal work on context values in partials.
"""
engine
=
self
.
_engine
()
template
=
'{{>partial}}'
partials
=
{
'partial'
:
'unescaped: {{{foo}}} escaped: {{foo}}'
}
context
=
{
'foo'
:
'<'
}
self
.
_assert_render
(
'unescaped: < escaped: <'
,
template
,
context
,
engine
=
engine
,
partials
=
partials
)
## Test cases related specifically to sections.
def
test_section__context_values
(
self
):
"""
Test that escape and literal work on context values in sections.
...
...
@@ -216,18 +249,14 @@ class RenderTests(unittest.TestCase):
self
.
_assert_render
(
'unescaped: < escaped: <'
,
template
,
context
,
engine
=
engine
)
def
test_
render__partial_context_values
(
self
):
def
test_
section__context_precedence
(
self
):
"""
Test that escape and literal work on context values in partials
.
Check that items higher in the context stack take precedence
.
"""
engine
=
self
.
_engine
()
template
=
'{{>partial}}'
partials
=
{
'partial'
:
'unescaped: {{{foo}}} escaped: {{foo}}'
}
context
=
{
'foo'
:
'<'
}
self
.
_assert_render
(
'unescaped: < escaped: <'
,
template
,
context
,
engine
=
engine
,
partials
=
partials
)
template
=
'{{entree}} : {{#vegetarian}}{{entree}}{{/vegetarian}}'
context
=
{
'entree'
:
'chicken'
,
'vegetarian'
:
{
'entree'
:
'beans and rice'
}}
self
.
_assert_render
(
u'chicken : beans and rice'
,
template
,
context
)
def
test_section__list_referencing_outer_context
(
self
):
"""
...
...
@@ -243,34 +272,55 @@ class RenderTests(unittest.TestCase):
"list"
:
[{
"name"
:
"Al"
},
{
"name"
:
"Bob"
}],
}
template
=
"{{#list}}{{greeting}}
, {{name}};
{{/list}}"
template
=
"{{#list}}{{greeting}}
{{name}},
{{/list}}"
self
.
_assert_render
(
"Hi
, Al; Hi, Bob;
"
,
template
,
context
)
self
.
_assert_render
(
"Hi
Al, Hi Bob,
"
,
template
,
context
)
def
test_
render__tag_in_value
(
self
):
def
test_
section__output_not_interpolated
(
self
):
"""
C
ontext values should not be treated as templates (issue #44)
.
C
heck that rendered section output is not interpolated
.
"""
template
=
'{{
tes
t}}'
context
=
{
'
test'
:
'{{hello}}
'
}
self
.
_assert_render
(
'{{hello}}
'
,
template
,
context
)
template
=
'{{
#section}}{{template}}{{/section}}: {{plane
t}}'
context
=
{
'
section'
:
True
,
'template'
:
'{{planet}}'
,
'planet'
:
'Earth
'
}
self
.
_assert_render
(
u'{{planet}}: Earth
'
,
template
,
context
)
def
test_
render__section_in_value
(
self
):
def
test_
section__nested_truthy
(
self
):
"""
Context values should not be treated as templates (issue #44).
Check that "nested truthy" sections get rendered.
Test case for issue #24: https://github.com/defunkt/pystache/issues/24
This test is copied from the spec. We explicitly include it to
prevent regressions for those who don't pull down the spec tests.
"""
template
=
'{{test}}'
context
=
{
'test'
:
'{{#hello}}'
}
self
.
_assert_render
(
'{{#hello}}'
,
template
,
context
)
template
=
'| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |'
context
=
{
'bool'
:
True
}
self
.
_assert_render
(
u'| A B C D E |'
,
template
,
context
)
def
test_section__nested_with_same_keys
(
self
):
"""
Check a doubly-nested section with the same context key.
Test case for issue #36: https://github.com/defunkt/pystache/issues/36
"""
# Start with an easier, working case.
template
=
'{{#x}}{{#z}}{{y}}{{/z}}{{/x}}'
context
=
{
'x'
:
{
'z'
:
{
'y'
:
1
}}}
self
.
_assert_render
(
u'1'
,
template
,
context
)
template
=
'{{#x}}{{#x}}{{y}}{{/x}}{{/x}}'
context
=
{
'x'
:
{
'x'
:
{
'y'
:
1
}}}
self
.
_assert_render
(
u'1'
,
template
,
context
)
def
test_
render__
section__lambda
(
self
):
def
test_section__lambda
(
self
):
template
=
'{{#test}}Mom{{/test}}'
context
=
{
'test'
:
(
lambda
text
:
'Hi
%
s'
%
text
)}
self
.
_assert_render
(
'Hi Mom'
,
template
,
context
)
def
test_
render__
section__lambda__tag_in_output
(
self
):
def
test_section__lambda__tag_in_output
(
self
):
"""
Check that callable output is treated as a template string (issue #46).
...
...
@@ -287,7 +337,7 @@ class RenderTests(unittest.TestCase):
context
=
{
'person'
:
'Mom'
,
'test'
:
(
lambda
text
:
text
+
" :)"
)}
self
.
_assert_render
(
'Hi Mom :)'
,
template
,
context
)
def
test_
render__section__
comment__multiline
(
self
):
def
test_comment__multiline
(
self
):
"""
Check that multiline comments are permitted.
...
...
@@ -316,51 +366,3 @@ class RenderTests(unittest.TestCase):
expected
=
u' {{foo}} '
self
.
_assert_render
(
expected
,
'{{=$ $=}} {{foo}} '
)
self
.
_assert_render
(
expected
,
'{{=$ $=}} {{foo}} $={{ }}=$'
)
# was yielding u' '.
def
test_section__output_not_interpolated
(
self
):
"""
Check that rendered section output is not interpolated.
"""
template
=
'{{#section}}{{template}}{{/section}}: {{planet}}'
context
=
{
'section'
:
True
,
'template'
:
'{{planet}}'
,
'planet'
:
'Earth'
}
self
.
_assert_render
(
u'{{planet}}: Earth'
,
template
,
context
)
def
test_section__context_precedence
(
self
):
"""
Check that items higher in the context stack take precedence.
"""
template
=
'{{entree}} : {{#vegetarian}}{{entree}}{{/vegetarian}}'
context
=
{
'entree'
:
'chicken'
,
'vegetarian'
:
{
'entree'
:
'beans and rice'
}}
self
.
_assert_render
(
u'chicken : beans and rice'
,
template
,
context
)
def
test_sections__nested_truthy
(
self
):
"""
Check that "nested truthy" sections get rendered.
Test case for issue #24: https://github.com/defunkt/pystache/issues/24
This test is copied from the spec. We explicitly include it to
prevent regressions for those who don't pull down the spec tests.
"""
template
=
'| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |'
context
=
{
'bool'
:
True
}
self
.
_assert_render
(
u'| A B C D E |'
,
template
,
context
)
def
test_sections__nested_with_same_keys
(
self
):
"""
Check a doubly-nested section with the same context key.
Test case for issue #36: https://github.com/defunkt/pystache/issues/36
"""
# Start with an easier, working case.
template
=
'{{#x}}{{#z}}{{y}}{{/z}}{{/x}}'
context
=
{
'x'
:
{
'z'
:
{
'y'
:
1
}}}
self
.
_assert_render
(
u'1'
,
template
,
context
)
template
=
'{{#x}}{{#x}}{{y}}{{/x}}{{/x}}'
context
=
{
'x'
:
{
'x'
:
{
'y'
:
1
}}}
self
.
_assert_render
(
u'1'
,
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