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
111cf436
Commit
111cf436
authored
Dec 21, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Template._make_render_engine() and tests for it.
parent
28233892
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
4 deletions
+54
-4
pystache/template.py
+11
-4
tests/test_template.py
+43
-0
No files found.
pystache/template.py
View file @
111cf436
...
@@ -136,6 +136,16 @@ class Template(object):
...
@@ -136,6 +136,16 @@ class Template(object):
return
context
return
context
def
_make_render_engine
(
self
):
"""
Return a RenderEngine instance for rendering.
"""
engine
=
RenderEngine
(
load_template
=
self
.
load_template
,
literal
=
self
.
literal
,
escape
=
self
.
_unicode_and_escape
)
return
engine
def
render
(
self
,
context
=
None
,
**
kwargs
):
def
render
(
self
,
context
=
None
,
**
kwargs
):
"""
"""
Return the template rendered using the given context.
Return the template rendered using the given context.
...
@@ -156,16 +166,13 @@ class Template(object):
...
@@ -156,16 +166,13 @@ class Template(object):
These values take precedence over the context on any key conflicts.
These values take precedence over the context on any key conflicts.
"""
"""
engine
=
self
.
_make_render_engine
()
context
=
self
.
_make_context
(
context
,
**
kwargs
)
context
=
self
.
_make_context
(
context
,
**
kwargs
)
template
=
self
.
template
template
=
self
.
template
if
not
isinstance
(
template
,
unicode
):
if
not
isinstance
(
template
,
unicode
):
template
=
self
.
unicode
(
template
)
template
=
self
.
unicode
(
template
)
engine
=
RenderEngine
(
load_template
=
self
.
load_template
,
literal
=
self
.
literal
,
escape
=
self
.
_unicode_and_escape
)
result
=
engine
.
render
(
template
,
context
)
result
=
engine
.
render
(
template
,
context
)
if
self
.
output_encoding
is
not
None
:
if
self
.
output_encoding
is
not
None
:
...
...
tests/test_template.py
View file @
111cf436
...
@@ -355,3 +355,46 @@ class TemplateTestCase(unittest.TestCase):
...
@@ -355,3 +355,46 @@ class TemplateTestCase(unittest.TestCase):
template
.
default_encoding
=
'utf_8'
template
.
default_encoding
=
'utf_8'
self
.
assertEquals
(
template
.
render
(),
"déf"
)
self
.
assertEquals
(
template
.
render
(),
"déf"
)
# By testing that Template.render() constructs the RenderEngine instance
# correctly, we no longer need to test the rendering code paths through
# the Template. We can test rendering paths through only the RenderEngine
# for the same amount of code coverage.
def
test_make_render_engine__load_template
(
self
):
"""
Test that _make_render_engine() passes the right load_template.
"""
template
=
Template
()
template
.
load_template
=
"foo"
# in real life, this would be a function.
engine
=
template
.
_make_render_engine
()
self
.
assertEquals
(
engine
.
load_template
,
"foo"
)
def
test_make_render_engine__literal
(
self
):
"""
Test that _make_render_engine() passes the right literal.
"""
template
=
Template
()
template
.
literal
=
"foo"
# in real life, this would be a function.
engine
=
template
.
_make_render_engine
()
self
.
assertEquals
(
engine
.
literal
,
"foo"
)
def
test_make_render_engine__escape
(
self
):
"""
Test that _make_render_engine() passes the right escape.
"""
template
=
Template
()
template
.
unicode
=
lambda
s
:
s
.
upper
()
# a test version.
template
.
escape
=
lambda
s
:
"**"
+
s
# a test version.
engine
=
template
.
_make_render_engine
()
escape
=
engine
.
escape
self
.
assertEquals
(
escape
(
u"foo"
),
"**foo"
)
# Test that escape converts str strings to unicode first.
self
.
assertEquals
(
escape
(
"foo"
),
"**FOO"
)
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