Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Attributes
CMFPlone.tests.testInterfaces.zope_interface_test Class Reference
Inheritance diagram for CMFPlone.tests.testInterfaces.zope_interface_test:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def interfaceImplementedBy
def interfaceProvidedBy
def getImplementedBy
def getProvidedBy
def doesImplementedBy
def doesProvidedBy

Static Public Attributes

 klass = None
 instance = None
tuple forcedImpl = ()

Private Member Functions

def _testStuff

Static Private Attributes

int _setup_fixture = 0

Detailed Description

general zope.interface testing class

klass - the class object to test
forcedImpl - a list of interface class objects that the class klass
    *must* implement to fullfil this test

This test class doesn't implement a test* method so you have to provide
a test method in your implementation. See above for two examples. One
example uses the special magic of setattr::

    setattr(MyClass, MyMethodName, lambda self: self._testStuff())

Definition at line 183 of file testInterfaces.py.


Member Function Documentation

test self.klass and self.instance 

Definition at line 274 of file testInterfaces.py.

00274 
00275     def _testStuff(self):
00276         """ test self.klass and self.instance """
00277         if self.klass:
00278             if self.forcedImpl:
00279                 self.doesImplementedBy(self.klass, self.forcedImpl)
00280             for iface in self.getImplementedBy(self.klass):
00281                 self.interfaceImplementedBy(self.klass, iface)
00282         if self.instance:
00283             if self.forcedImpl:
00284                 self.doesProvidedBy(self.instance, self.forcedImpl)
00285             for iface in self.getProvidedBy(self.instance):
00286                 self.interfaceProvidedBy(self.instance, iface)
00287 

Here is the call graph for this function:

def CMFPlone.tests.testInterfaces.zope_interface_test.doesImplementedBy (   self,
  klass,
  interfaces 
)
make sure that the klass implements at least these interfaces

Definition at line 256 of file testInterfaces.py.

00256 
00257     def doesImplementedBy(self, klass, interfaces):
00258         """ make sure that the klass implements at least these interfaces"""
00259         impl = self.getImplementedBy(klass)
00260         for interface in interfaces:
00261             self.failUnless(
00262                 interface in impl,
00263                 'The class %s does not implement %s' % (dottedName(klass),
00264                                                         dottedName(interface)))

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.tests.testInterfaces.zope_interface_test.doesProvidedBy (   self,
  instance,
  interfaces 
)
make sure that the klass implements at least these interfaces

Definition at line 265 of file testInterfaces.py.

00265 
00266     def doesProvidedBy(self, instance, interfaces):
00267         """ make sure that the klass implements at least these interfaces"""
00268         impl = self.getProvidedBy(instance)
00269         for interface in interfaces:
00270             self.failUnless(
00271                 interface in impl,
00272                 'The instance of %s does not provide %s' % (dottedName(instance),
00273                                                             dottedName(interface)))

Here is the call graph for this function:

Here is the caller graph for this function:

returns the interfaces implemented by the klass (flat)

Definition at line 246 of file testInterfaces.py.

00246 
00247     def getImplementedBy(self, klass):
00248         """ returns the interfaces implemented by the klass (flat)"""
00249         from zope.interface import implementedBy
00250         return implementedBy(klass)

Here is the caller graph for this function:

returns the interfaces implemented by the instance (flat)

Definition at line 251 of file testInterfaces.py.

00251 
00252     def getProvidedBy(self, instance):
00253         """ returns the interfaces implemented by the instance (flat)"""
00254         from zope.interface import providedBy
00255         return providedBy(instance)

Here is the caller graph for this function:

tests if the klass implements the interface in the right way 

Definition at line 204 of file testInterfaces.py.

00204 
00205     def interfaceImplementedBy(self, klass, interface):
00206         """ tests if the klass implements the interface in the right way """
00207 
00208         from zope.interface.verify import verifyClass
00209         from zope.interface.exceptions import BrokenImplementation, DoesNotImplement
00210         from zope.interface.exceptions import BrokenMethodImplementation
00211 
00212         # is the class really implemented by the given interface?
00213         self.failUnless(interface.implementedBy(klass),
00214             'The class %s does not implement %s' % (dottedName(klass),
00215                                                     dottedName(interface)))
00216         # verify if the implementation is correct
00217         try:
00218             verifyClass(interface, klass)
00219         except (BrokenImplementation, DoesNotImplement,
00220                 BrokenMethodImplementation), errmsg:
00221             self.fail('The class %s does not implement %s correctly: \n%s'
00222                       % (dottedName(klass), dottedName(interface), errmsg))
00223        except AttributeError, errmsg:
00224            self.fail('There was a problem while checking the implementation of '
00225                      'class %s and interface %s: \nAttributeError %s\n%s'
00226                     % (dottedName(klass), dottedName(interface), errmsg,
00227                          ''.join(traceback.format_tb(sys.exc_traceback))))

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.tests.testInterfaces.zope_interface_test.interfaceProvidedBy (   self,
  instance,
  interface 
)
tests if the instance implements the interface in the right way 

Definition at line 228 of file testInterfaces.py.

00228 
00229     def interfaceProvidedBy(self, instance, interface):
00230         """ tests if the instance implements the interface in the right way """
00231         from zope.interface.verify import verifyObject
00232         from zope.interface.exceptions import BrokenImplementation, DoesNotImplement
00233         from zope.interface.exceptions import BrokenMethodImplementation
00234 
00235         # is the class really implemented by the given interface?
00236         self.failUnless(interface.providedBy(instance),
00237             'The instance of %s does not provide %s' % (dottedName(instance),
00238                                                         dottedName(interface)))
00239         # verify if the implementation is correct
00240         try:
00241             verifyObject(interface, instance)
00242         except (BrokenImplementation, DoesNotImplement,
00243                 BrokenMethodImplementation), errmsg:
00244             self.fail('The instance of %s does not provide %s correctly: \n%s'
00245                       % (dottedName(instance), dottedName(interface), errmsg))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 198 of file testInterfaces.py.

Reimplemented in CMFPlone.tests.testInterfaces.InstanceInterfaceTest.

Definition at line 201 of file testInterfaces.py.

Reimplemented in CMFPlone.tests.testInterfaces.KlassInterfaceTest.

Definition at line 200 of file testInterfaces.py.


The documentation for this class was generated from the following file: