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
78bb39e3
Commit
78bb39e3
authored
Dec 17, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue #51: "Passing **kwargs to Template.__init__() modifies the context"
Also added a test case.
parent
a484f30f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
pystache/template.py
+10
-3
tests/test_template.py
+11
-0
No files found.
pystache/template.py
View file @
78bb39e3
...
...
@@ -62,15 +62,22 @@ class Template(object):
modifiers
=
Modifiers
()
def
__init__
(
self
,
template
=
None
,
context
=
None
,
**
kwargs
):
"""
The **kwargs arguments are only supported if the context is
a dictionary (i.e. not a View).
"""
from
.view
import
View
self
.
template
=
template
if
context
is
None
:
context
=
{}
if
kwargs
:
context
.
update
(
kwargs
)
elif
not
isinstance
(
context
,
View
):
# Views do not support copy() or update().
context
=
context
.
copy
()
if
kwargs
:
context
.
update
(
kwargs
)
self
.
view
=
context
if
isinstance
(
context
,
View
)
else
View
(
context
=
context
)
self
.
_compile_regexps
()
...
...
tests/test_template.py
View file @
78bb39e3
...
...
@@ -12,6 +12,8 @@ from pystache.template import Template
class
TemplateTestCase
(
unittest
.
TestCase
):
"""Test the Template class."""
def
test_init__kwargs_with_no_context
(
self
):
"""
Test passing **kwargs with no context.
...
...
@@ -20,3 +22,12 @@ class TemplateTestCase(unittest.TestCase):
# This test checks that the following line raises no exception.
template
=
Template
(
foo
=
"bar"
)
def
test_init__kwargs_does_not_modify_context
(
self
):
"""
Test that passing **kwargs does not modify the passed context.
"""
context
=
{}
template
=
Template
(
context
=
context
,
foo
=
"bar"
)
self
.
assertEquals
(
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