[Checkins] SVN: z3c.testing/trunk/src/z3c/testing/ Bugfix,
added custom verify module which does
Roger Ineichen
roger at projekt01.ch
Mon Jan 22 03:22:30 EST 2007
Log message for revision 72167:
Bugfix, added custom verify module which does
not raise exceptions on decorated methods
Changed:
U z3c.testing/trunk/src/z3c/testing/app.py
A z3c.testing/trunk/src/z3c/testing/verify.py
-=-
Modified: z3c.testing/trunk/src/z3c/testing/app.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/app.py 2007-01-22 07:20:07 UTC (rev 72166)
+++ z3c.testing/trunk/src/z3c/testing/app.py 2007-01-22 08:22:29 UTC (rev 72167)
@@ -66,8 +66,8 @@
# Public Base Tests
#
###############################################################################
-from zope.interface.verify import verifyClass
from zope.interface.verify import verifyObject
+from z3c.testing.verify import verifyClass
class InterfaceBaseTest(TestCase):
Added: z3c.testing/trunk/src/z3c/testing/verify.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/verify.py 2007-01-22 07:20:07 UTC (rev 72166)
+++ z3c.testing/trunk/src/z3c/testing/verify.py 2007-01-22 08:22:29 UTC (rev 72167)
@@ -0,0 +1,84 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Verify interface implementations
+
+$Id$
+"""
+from zope.interface.exceptions import BrokenImplementation, DoesNotImplement
+from zope.interface.exceptions import BrokenMethodImplementation
+from types import FunctionType, MethodType
+from zope.interface.interface import fromMethod, fromFunction, Method
+from zope.interface.verify import _incompat, MethodTypes
+
+
+def _verify(iface, candidate, tentative=0, vtype=None):
+ """Fix broken testing decorated methods.
+
+ You can find such a broken interfaces test in z3c.proxy where the
+ methods are decorated within ``@non_overridable``.
+ """
+
+ if vtype == 'c':
+ tester = iface.implementedBy
+ else:
+ tester = iface.providedBy
+
+ if not tentative and not tester(candidate):
+ raise DoesNotImplement(iface)
+
+ # Here the `desc` is either an `Attribute` or `Method` instance
+ for name, desc in iface.namesAndDescriptions(1):
+ if not hasattr(candidate, name):
+ if (not isinstance(desc, Method)) and vtype == 'c':
+ # We can't verify non-methods on classes, since the
+ # class may provide attrs in it's __init__.
+ continue
+
+ raise BrokenImplementation(iface, name)
+
+ attr = getattr(candidate, name)
+ if not isinstance(desc, Method):
+ # If it's not a method, there's nothing else we can test
+ continue
+
+ if isinstance(attr, FunctionType):
+ # should never get here, since classes should not provide functions
+ meth = fromFunction(attr, iface, name=name)
+ elif (isinstance(attr, MethodTypes)
+ and type(attr.im_func) is FunctionType):
+ meth = fromMethod(attr, iface, name)
+ elif isinstance(attr, property):
+ # We can't verify decorated methods on classes.
+ continue
+ else:
+ import pdb; pdb.set_trace()
+ if not callable(attr):
+ raise BrokenMethodImplementation(name, "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
+
+ # Make sure that the required and implemented method signatures are
+ # the same.
+ desc = desc.getSignatureInfo()
+ meth = meth.getSignatureInfo()
+
+ mess = _incompat(desc, meth)
+ if mess:
+ raise BrokenMethodImplementation(name, mess)
+
+ return True
+
+def verifyClass(iface, candidate, tentative=0):
+ return _verify(iface, candidate, tentative, vtype='c')
Property changes on: z3c.testing/trunk/src/z3c/testing/verify.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list