[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/interface/ Merged from trunk:

Jim Fulton jim at zope.com
Mon Aug 2 17:06:08 EDT 2004


Log message for revision 26867:
  Merged from trunk:
  
    r26866 | jim | 2004-08-02 16:57:00 -0400 (Mon, 02 Aug 2004) | 7 lines
  
  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/branches/ZopeX3-3.0/src/zope/interface/tests/test_verify.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/verify.py


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_verify.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_verify.py	2004-08-02 20:57:00 UTC (rev 26866)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/tests/test_verify.py	2004-08-02 21:06:08 UTC (rev 26867)
@@ -17,8 +17,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
@@ -168,8 +167,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/branches/ZopeX3-3.0/src/zope/interface/verify.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/verify.py	2004-08-02 20:57:00 UTC (rev 26866)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/verify.py	2004-08-02 21:06:08 UTC (rev 26867)
@@ -57,6 +57,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)
@@ -64,7 +68,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