Back to index

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

List of all members.

Public Member Functions

def interfaceImplementedByInstanceOf
def interfaceImplementedBy
def getImplementsOfInstanceOf
def getImplementsOf
def doesImplementByInstanceOf
def doesImplementBy

Static Public Attributes

 klass = None
 instance = None
tuple forcedImpl = ()

Private Member Functions

def _testStuff

Static Private Attributes

int _setup_fixture = 0

Detailed Description

general 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 65 of file testInterfaces.py.


Member Function Documentation

test self.klass and self.instance 

Definition at line 169 of file testInterfaces.py.

00169 
00170     def _testStuff(self):
00171         """ test self.klass and self.instance """
00172         if self.klass:
00173             if self.forcedImpl:
00174                 self.doesImplementByInstanceOf(self.klass, self.forcedImpl)
00175             for iface in self.getImplementsOfInstanceOf(self.klass):
00176                 self.interfaceImplementedByInstanceOf(self.klass, iface)
00177         if self.instance:
00178             if self.forcedImpl:
00179                 self.doesImplementBy(self.instance, self.forcedImpl)
00180             for iface in self.getImplementsOf(self.instance):
00181                 self.interfaceImplementedBy(self.instance, iface)
00182 

Here is the call graph for this function:

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

Definition at line 158 of file testInterfaces.py.

00158 
00159     def doesImplementBy(self, instance, interfaces):
00160         """ make sure that the klass implements at least these interfaces"""
00161         if type(interfaces) is not TupleType:
00162             interfaces = (interfaces)
00163         impl = self.getImplementsOf(instance)
00164         for interface in interfaces:
00165             self.failUnless(
00166                 interface in impl,
00167                 'The instance of %s does not implement %s' % (dottedName(instance),
00168                                                               dottedName(interface)))

Here is the call graph for this function:

Here is the caller graph for this function:

make sure that the klass implements at least these interfaces

Definition at line 147 of file testInterfaces.py.

00147 
00148     def doesImplementByInstanceOf(self, klass, interfaces):
00149         """ make sure that the klass implements at least these interfaces"""
00150         if type(interfaces) is not TupleType:
00151             interfaces = (interfaces)
00152         impl = self.getImplementsOfInstanceOf(klass)
00153         for interface in interfaces:
00154             self.failUnless(
00155                 interface in impl,
00156                 'The class %s does not implement %s' % (dottedName(klass),
00157                                                         dottedName(interface)))

Here is the call graph for this function:

Here is the caller graph for this function:

returns the interfaces implemented by the instance (flat)

Definition at line 137 of file testInterfaces.py.

00137 
00138     def getImplementsOf(self, instance):
00139         """ returns the interfaces implemented by the instance (flat)"""
00140         from Interface.Implements import getImplements, flattenInterfaces
00141 
00142         impl = getImplements(instance)
00143         if type(impl) is not TupleType:
00144             impl = (impl,)
00145         if impl:
00146             return flattenInterfaces(impl)

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 127 of file testInterfaces.py.

00127 
00128     def getImplementsOfInstanceOf(self, klass):
00129         """ returns the interfaces implemented by the klass (flat)"""
00130         from Interface.Implements import getImplementsOfInstances, flattenInterfaces
00131 
00132         impl = getImplementsOfInstances(klass)
00133         if type(impl) is not TupleType:
00134             impl = (impl,)
00135         if impl:
00136             return flattenInterfaces(impl)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 109 of file testInterfaces.py.

00109 
00110     def interfaceImplementedBy(self, instance, interface):
00111         """ tests if the instance implements the interface in the right way """
00112         from Interface.Verify import verifyObject
00113         from Interface.Exceptions import BrokenImplementation, DoesNotImplement
00114         from Interface.Exceptions import BrokenMethodImplementation
00115 
00116         # is the class really implemented by the given interface?
00117         self.failUnless(interface.isImplementedBy(instance),
00118             'The instance of %s does not implement %s' % (dottedName(instance),
00119                                                           dottedName(interface)))
00120         # verify if the implementation is correct
00121         try:
00122             verifyObject(interface, instance)
00123         except (BrokenImplementation, DoesNotImplement,
00124           BrokenMethodImplementation), errmsg:
00125             self.fail('The instance of %s does not implement %s correctly: \n%s'
00126                 % (dottedName(instance), dottedName(interface), errmsg))

Here is the call graph for this function:

Here is the caller graph for this function:

tests if the klass implements the interface in the right way 

Definition at line 86 of file testInterfaces.py.

00086 
00087     def interfaceImplementedByInstanceOf(self, klass, interface):
00088         """ tests if the klass implements the interface in the right way """
00089         from Interface.Verify import verifyClass
00090         from Interface.Exceptions import BrokenImplementation, DoesNotImplement
00091         from Interface.Exceptions import BrokenMethodImplementation
00092 
00093         # is the class really implemented by the given interface?
00094         self.failUnless(interface.isImplementedByInstancesOf(klass),
00095             'The class %s does not implement %s' % (dottedName(klass),
00096                                                     dottedName(interface)))
00097         # verify if the implementation is correct
00098         try:
00099             verifyClass(interface, klass)
00100         except (BrokenImplementation, DoesNotImplement,
00101                 BrokenMethodImplementation), errmsg:
00102             self.fail('The class %s does not implement %s correctly: \n%s'
00103                       % (dottedName(klass), dottedName(interface), errmsg))
00104        except AttributeError, errmsg:
00105            self.fail('There was a problem while checking the implementation of '
00106                      'class %s and interface %s: \nAttributeError %s\n%s'
00107                     % (dottedName(klass), dottedName(interface), errmsg,
00108                          ''.join(traceback.format_tb(sys.exc_traceback))))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 80 of file testInterfaces.py.

Reimplemented in CMFPlone.tests.testInterfaces.InstanceInterfaceTest.

Definition at line 83 of file testInterfaces.py.

Reimplemented in CMFPlone.tests.testInterfaces.KlassInterfaceTest.

Definition at line 82 of file testInterfaces.py.


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