===================================
Verifying interface implementations
===================================
The ``zope.interface.verify`` module provides functions that test whether a
given interface is implemented by a class or provided by an object, resp.
Verifying classes
=================
This is covered by unit tests defined in ``zope.interface.tests.test_verify``.
Verifying objects
=================
An object provides an interface if
- either its class declares that it implements the interfaces, or the object
declares that it directly provides the interface
- the object defines all the methods required by the interface
- all the methods have the correct signature
- the object defines all non-method attributes required by the interface
This doctest currently covers only the latter item.
Testing for attributes
----------------------
Attributes of the object, be they defined by its class or added by its
``__init__`` method, will be recognized:
>>> from zope.interface import Interface, Attribute, implements
>>> class IFoo(Interface):
... x = Attribute("The X attribute")
... y = Attribute("The Y attribute")
>>> class Foo(object):
... implements(IFoo)
... x = 1
... def __init__(self):
... self.y = 2
>>> from zope.interface.verify import verifyObject
>>> verifyObject(IFoo, Foo())
True
If either attribute is missing, verification will fail:
>>> class Foo(object):
... implements(IFoo)
... x = 1
>>> verifyObject(IFoo, Foo())
Traceback (most recent call last):
BrokenImplementation: An object has failed to implement interface