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
d13a4c43
Commit
d13a4c43
authored
Dec 23, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring: removed some of the cut-and-paste from test_pystache.py.
parent
f5e9950b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
28 deletions
+25
-28
tests/test_pystache.py
+25
-28
No files found.
tests/test_pystache.py
View file @
d13a4c43
...
...
@@ -29,38 +29,38 @@ class PystacheTests(object):
def
test_less_basic
(
self
):
template
=
"It's a nice day for {{beverage}}, right {{person}}?"
ret
=
pystache
.
render
(
template
,
{
'beverage'
:
'soda'
,
'person'
:
'Bob'
})
self
.
assertEquals
(
ret
,
"It's a nice day for soda, right Bob?"
)
context
=
{
'beverage'
:
'soda'
,
'person'
:
'Bob'
}
self
.
_assert_rendered
(
"It's a nice day for soda, right Bob?"
,
template
,
context
)
def
test_even_less_basic
(
self
):
template
=
"I think {{name}} wants a {{thing}}, right {{name}}?"
ret
=
pystache
.
render
(
template
,
{
'name'
:
'Jon'
,
'thing'
:
'racecar'
})
self
.
assertEquals
(
ret
,
"I think Jon wants a racecar, right Jon?"
)
context
=
{
'name'
:
'Jon'
,
'thing'
:
'racecar'
}
self
.
_assert_rendered
(
"I think Jon wants a racecar, right Jon?"
,
template
,
context
)
def
test_ignores_misses
(
self
):
template
=
"I think {{name}} wants a {{thing}}, right {{name}}?"
ret
=
pystache
.
render
(
template
,
{
'name'
:
'Jon'
})
self
.
assertEquals
(
ret
,
"I think Jon wants a , right Jon?"
)
context
=
{
'name'
:
'Jon'
}
self
.
_assert_rendered
(
"I think Jon wants a , right Jon?"
,
template
,
context
)
def
test_render_zero
(
self
):
template
=
'My value is {{value}}.'
ret
=
pystache
.
render
(
template
,
{
'value'
:
0
})
self
.
assertEquals
(
ret
,
'My value is 0.'
)
context
=
{
'value'
:
0
}
self
.
_assert_rendered
(
'My value is 0.'
,
template
,
context
)
def
test_comments
(
self
):
template
=
"What {{! the }} what?"
ret
=
pystache
.
render
(
template
)
self
.
assertEquals
(
ret
,
"What what?"
)
actual
=
pystache
.
render
(
template
)
self
.
assertEquals
(
"What what?"
,
actual
)
def
test_false_sections_are_hidden
(
self
):
template
=
"Ready {{#set}}set {{/set}}go!"
ret
=
pystache
.
render
(
template
,
{
'set'
:
False
})
self
.
assertEquals
(
ret
,
"Ready go!"
)
context
=
{
'set'
:
False
}
self
.
_assert_rendered
(
"Ready go!"
,
template
,
context
)
def
test_true_sections_are_shown
(
self
):
template
=
"Ready {{#set}}set{{/set}} go!"
ret
=
pystache
.
render
(
template
,
{
'set'
:
True
})
self
.
assertEquals
(
ret
,
"Ready set go!"
)
context
=
{
'set'
:
True
}
self
.
_assert_rendered
(
"Ready set go!"
,
template
,
context
)
non_strings_expected
=
"""(123 & ['something'])(chris & 0.9)"""
...
...
@@ -69,34 +69,32 @@ class PystacheTests(object):
stats
=
[]
stats
.
append
({
'key'
:
123
,
'value'
:
[
'something'
]})
stats
.
append
({
'key'
:
u"chris"
,
'value'
:
0.900
})
ret
=
pystache
.
render
(
template
,
{
'stats'
:
stats
})
self
.
assertEquals
(
ret
,
self
.
non_strings_expected
)
context
=
{
'stats'
:
stats
}
self
.
_assert_rendered
(
self
.
non_strings_expected
,
template
,
context
)
def
test_unicode
(
self
):
template
=
'Name: {{name}}; Age: {{age}}'
ret
=
pystache
.
render
(
template
,
{
'name'
:
u'Henri Poincaré'
,
'age'
:
156
})
self
.
assertEquals
(
ret
,
u'Name: Henri Poincaré; Age: 156'
)
context
=
{
'name'
:
u'Henri Poincaré'
,
'age'
:
156
}
self
.
_assert_rendered
(
u'Name: Henri Poincaré; Age: 156'
,
template
,
context
)
def
test_sections
(
self
):
template
=
"""<ul>{{#users}}<li>{{name}}</li>{{/users}}</ul>"""
context
=
{
'users'
:
[
{
'name'
:
'Chris'
},
{
'name'
:
'Tom'
},
{
'name'
:
'PJ'
}
]
}
ret
=
pystache
.
render
(
template
,
context
)
self
.
assertEquals
(
ret
,
"""<ul><li>Chris</li><li>Tom</li><li>PJ</li></ul>"""
)
expected
=
"""<ul><li>Chris</li><li>Tom</li><li>PJ</li></ul>"""
self
.
_assert_rendered
(
expected
,
template
,
context
)
def
test_implicit_iterator
(
self
):
template
=
"""<ul>{{#users}}<li>{{.}}</li>{{/users}}</ul>"""
context
=
{
'users'
:
[
'Chris'
,
'Tom'
,
'PJ'
]
}
ret
=
pystache
.
render
(
template
,
context
)
self
.
assertEquals
(
ret
,
"""<ul><li>Chris</li><li>Tom</li><li>PJ</li></ul>"""
)
expected
=
"""<ul><li>Chris</li><li>Tom</li><li>PJ</li></ul>"""
self
.
_assert_rendered
(
expected
,
template
,
context
)
# The spec says that sections should not alter surrounding whitespace.
def
test_surrounding_whitepace_not_altered
(
self
):
template
=
"first{{#spacing}} second {{/spacing}}third"
ret
=
pystache
.
render
(
template
,
{
"spacing"
:
True
})
self
.
assertEquals
(
ret
,
"first second third"
)
context
=
{
"spacing"
:
True
}
self
.
_assert_rendered
(
"first second third"
,
template
,
context
)
def
test__section__non_false_value
(
self
):
"""
...
...
@@ -123,8 +121,7 @@ class PystacheTests(object):
"""
template
=
"""{{#s1}}foo{{/s1}} {{#s2}}<{{/s2}}"""
context
=
{
's1'
:
True
,
's2'
:
[
True
]}
actual
=
pystache
.
render
(
template
,
context
)
self
.
assertEquals
(
actual
,
"""foo <"""
)
self
.
_assert_rendered
(
"foo <"
,
template
,
context
)
class
PystacheWithoutMarkupsafeTests
(
PystacheTests
,
unittest
.
TestCase
):
...
...
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