summaryrefslogtreecommitdiff
path: root/src/zope/interface/tests
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2021-04-13 16:44:48 -0500
committerJason Madden <jamadden@gmail.com>2021-04-13 16:47:53 -0500
commit8a0a8f1dea4a042ac31d48ae60111d2179f73d59 (patch)
tree67a4a5808e27f44276c06e846492a12e0a345574 /src/zope/interface/tests
parent4a686fc8d87d398045dc44c1b6a97a2940121800 (diff)
downloadzope-interface-issue239.tar.gz
Make C's __providedBy__ stop ignoring all errors and catch only AttributeError.issue239
Fixes #239 There was a similar bug in the Python side where it would ignore a __provides__ of None, unlike the C implementation. I documented this in the code but not the CHANGES.rst because I can't imagine anyone relying on that.
Diffstat (limited to 'src/zope/interface/tests')
-rw-r--r--src/zope/interface/tests/test_declarations.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/zope/interface/tests/test_declarations.py b/src/zope/interface/tests/test_declarations.py
index 8efe2d8..eb8b2a7 100644
--- a/src/zope/interface/tests/test_declarations.py
+++ b/src/zope/interface/tests/test_declarations.py
@@ -2531,6 +2531,56 @@ class ObjectSpecificationDescriptorFallbackTests(unittest.TestCase):
directlyProvides(foo, IBaz)
self.assertEqual(list(foo.__providedBy__), [IBaz, IFoo])
+ def test_arbitrary_exception_accessing_provides_not_caught(self):
+
+ class MyException(Exception):
+ pass
+
+ class Foo(object):
+ __providedBy__ = self._makeOne()
+
+ @property
+ def __provides__(self):
+ raise MyException
+
+ foo = Foo()
+ with self.assertRaises(MyException):
+ getattr(foo, '__providedBy__')
+
+ def test_AttributeError_accessing_provides_caught(self):
+
+ class MyException(Exception):
+ pass
+
+ class Foo(object):
+ __providedBy__ = self._makeOne()
+
+ @property
+ def __provides__(self):
+ raise AttributeError
+
+ foo = Foo()
+ provided = getattr(foo, '__providedBy__')
+ self.assertIsNotNone(provided)
+
+ def test_None_in__provides__overrides(self):
+ from zope.interface import Interface
+ from zope.interface import implementer
+
+ class IFoo(Interface):
+ pass
+
+ @implementer(IFoo)
+ class Foo(object):
+
+ @property
+ def __provides__(self):
+ return None
+
+ Foo.__providedBy__ = self._makeOne()
+
+ provided = getattr(Foo(), '__providedBy__')
+ self.assertIsNone(provided)
class ObjectSpecificationDescriptorTests(
ObjectSpecificationDescriptorFallbackTests,