[Zope3-checkins] SVN: Zope3/trunk/src/zope/interface/ verifyClass
now accepts methods as implementations for attributes
Jim Fulton
jim at zope.com
Mon Aug 2 16:57:00 EDT 2004
Log message for revision 26866:
verifyClass now accepts methods as implementations for attributes
and complains when non-methods are provides as implementations for
methods.
Fixed: http://collector.zope.org/Zope3-dev/254
Changed:
U Zope3/trunk/src/zope/interface/tests/test_verify.py
U Zope3/trunk/src/zope/interface/verify.py
-=-
Modified: Zope3/trunk/src/zope/interface/tests/test_verify.py
===================================================================
--- Zope3/trunk/src/zope/interface/tests/test_verify.py 2004-08-02 20:29:13 UTC (rev 26865)
+++ Zope3/trunk/src/zope/interface/tests/test_verify.py 2004-08-02 20:57:00 UTC (rev 26866)
@@ -15,7 +15,7 @@
$Id$
"""
-from zope.interface import Interface, implements, classImplements
+from zope.interface import Interface, implements, classImplements, Attribute
from zope.interface.verify import verifyClass, verifyObject
from zope.interface.exceptions import DoesNotImplement, BrokenImplementation
from zope.interface.exceptions import BrokenMethodImplementation
@@ -160,8 +160,34 @@
verifyObject(IFoo, dummy)
+ def testMethodForAttr(self):
+
+ class IFoo(Interface):
+ foo = Attribute("The foo Attribute")
+ class Foo:
+ implements(IFoo)
+
+ def foo(self):
+ pass
+
+ verifyClass(IFoo, Foo)
+
+ def testNonMethodForMethod(self):
+
+ class IBar(Interface):
+ def foo():
+ pass
+
+ class Bar:
+ implements(IBar)
+
+ foo = 1
+
+ self.assertRaises(BrokenMethodImplementation, verifyClass, IBar, Bar)
+
+
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
Modified: Zope3/trunk/src/zope/interface/verify.py
===================================================================
--- Zope3/trunk/src/zope/interface/verify.py 2004-08-02 20:29:13 UTC (rev 26865)
+++ Zope3/trunk/src/zope/interface/verify.py 2004-08-02 20:57:00 UTC (rev 26866)
@@ -60,6 +60,10 @@
raise BrokenImplementation(iface, n)
attr = getattr(candidate, n)
+ if not isinstance(d, Method):
+ # If it's not a method, there's nothing else we can test
+ continue
+
if type(attr) is FunctionType:
# should never get here
meth = fromFunction(attr, n)
@@ -67,7 +71,11 @@
and type(attr.im_func) is FunctionType):
meth = fromMethod(attr, n)
else:
- continue # must be an attribute...
+ if not callable(attr):
+ raise BrokenMethodImplementation(n, "Not a method")
+ # sigh, it's callable,but we don't know how to intrspect it, so
+ # we have to give it a pass.
+ continue
d=d.getSignatureInfo()
meth = meth.getSignatureInfo()
More information about the Zope3-Checkins
mailing list