Commit d9554ae2 by Chris Jerdonek

Fixed part of issue #110: accessing from context a property raising an exception.

parent 3c839348
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)
------------------
......
......@@ -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):
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment