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
d9554ae2
Commit
d9554ae2
authored
May 03, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed part of issue #110: accessing from context a property raising an exception.
parent
3c839348
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletions
+34
-1
HISTORY.rst
+6
-0
pystache/context.py
+8
-1
pystache/tests/test_context.py
+20
-0
No files found.
HISTORY.rst
View file @
d9554ae2
History
=======
0.5.3 (TBD)
-----------
* Bugfix: exceptions no longer swallowed when accessing from context a
property that raises an exception (issue #110).
0.5.2 (2012-05-03)
------------------
...
...
pystache/context.py
View file @
d9554ae2
...
...
@@ -55,8 +55,15 @@ def _get_value(context, key):
# types like integers and strings as objects (cf. issue #81).
# Instances of user-defined classes on the other hand, for example,
# are considered objects by the test above.
if
hasattr
(
context
,
key
)
:
try
:
attr
=
getattr
(
context
,
key
)
except
AttributeError
:
# TODO: distinguish the case of the attribute not existing from
# an AttributeError being raised by the call to the attribute.
# See the following issue for implementation ideas:
# http://bugs.python.org/issue7559
pass
else
:
# TODO: consider using EAFP here instead.
# http://docs.python.org/glossary.html#term-eafp
if
callable
(
attr
):
...
...
pystache/tests/test_context.py
View file @
d9554ae2
...
...
@@ -147,6 +147,26 @@ class GetValueTests(unittest.TestCase, AssertIsMixin):
self
.
assertEqual
(
item
[
"foo"
],
"bar"
)
self
.
assertNotFound
(
item
,
"foo"
)
def
test_object__property__raising_exception
(
self
):
"""
Test getting a property that raises an exception.
"""
class
Foo
(
object
):
@property
def
bar
(
self
):
return
1
@property
def
baz
(
self
):
raise
ValueError
(
"test"
)
foo
=
Foo
()
self
.
assertEqual
(
_get_value
(
foo
,
'bar'
),
1
)
self
.
assertNotFound
(
foo
,
'missing'
)
self
.
assertRaises
(
ValueError
,
_get_value
,
foo
,
'baz'
)
### Case: the item is an instance of a built-in type.
def
test_built_in_type__integer
(
self
):
...
...
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