Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions
Archetypes.tests.test_interfaces.InterfaceTest Class Reference
Inheritance diagram for Archetypes.tests.test_interfaces.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

 layer = ZCMLLayer
 klass = None
 instance = None
tuple forcedImpl = ()

Private Member Functions

def _testStuff

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 75 of file test_interfaces.py.


Member Function Documentation

test self.klass and self.instance 

Definition at line 152 of file test_interfaces.py.

00152 
00153     def _testStuff(self):
00154         """ test self.klass and self.instance """
00155         if self.klass:
00156             if self.forcedImpl:
00157                 self.doesImplementByInstanceOf(self.klass, self.forcedImpl)
00158             for iface in self.getImplementsOfInstanceOf(self.klass):
00159                 self.interfaceImplementedByInstanceOf(self.klass, iface)
00160         if self.instance:
00161             if self.forcedImpl:
00162                 self.doesImplementBy(self.instance, self.forcedImpl)
00163             for iface in self.getImplementsOf(self.instance):
00164                 self.interfaceImplementedBy(self.instance, iface)

Here is the call graph for this function:

def Archetypes.tests.test_interfaces.InterfaceTest.doesImplementBy (   self,
  instance,
  interfaces 
)
make shure that the klass implements at least these interfaces

Definition at line 144 of file test_interfaces.py.

00144 
00145     def doesImplementBy(self, instance, interfaces):
00146         """ make shure that the klass implements at least these interfaces"""
00147         if not isinstance(interfaces, tuple):
00148             interfaces = (interfaces)
00149         impl = self.getImplementsOf(instance)
00150         for interface in interfaces:
00151             self.failUnless(interface in impl, 'The instance of %s does not implement %s' % (className(instance), className(interface)))

Here is the call graph for this function:

Here is the caller graph for this function:

make shure that the klass implements at least these interfaces

Definition at line 136 of file test_interfaces.py.

00136 
00137     def doesImplementByInstanceOf(self, klass, interfaces):
00138         """ make shure that the klass implements at least these interfaces"""
00139         if not isinstance(interfaces, tuple):
00140             interfaces = (interfaces)
00141         impl = self.getImplementsOfInstanceOf(klass)
00142         for interface in interfaces:
00143             self.failUnless(interface in impl, 'The class %s does not implement %s' % (className(klass), className(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 128 of file test_interfaces.py.

00128 
00129     def getImplementsOf(self, instance):
00130         """ returns the interfaces implemented by the instance (flat)"""
00131         impl = getImplements(instance)
00132         if not isinstance(impl, tuple):
00133             impl = (impl,)
00134         if impl:
00135             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 120 of file test_interfaces.py.

00120 
00121     def getImplementsOfInstanceOf(self, klass):
00122         """ returns the interfaces implemented by the klass (flat)"""
00123         impl = getImplementsOfInstances(klass)
00124         if not isinstance(impl, tuple):
00125             impl = (impl,)
00126         if impl:
00127             return flattenInterfaces(impl)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 107 of file test_interfaces.py.

00107 
00108     def interfaceImplementedBy(self, instance, interface):        
00109         """ tests if the instance implements the interface in the right way """
00110         # is the class really implemented by the given interface?
00111         self.failUnless(interface.isImplementedBy(instance),
00112             'The instance of %s does not implement %s' % (className(instance), className(interface)))
00113         # verify if the implementation is correct
00114         try:
00115             verifyObject(interface, instance)
00116         except (BrokenImplementation, DoesNotImplement,
00117           BrokenMethodImplementation), errmsg:
00118             self.fail('The instance of %s does not implement %s correctly: \n%s'
00119                 % (className(instance), className(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 94 of file test_interfaces.py.

00094 
00095     def interfaceImplementedByInstanceOf(self, klass, interface):
00096         """ tests if the klass implements the interface in the right way """
00097         # is the class really implemented by the given interface?
00098         self.failUnless(interface.isImplementedByInstancesOf(klass),
00099             'The class %s does not implement %s' % (className(klass), className(interface)))
00100         # verify if the implementation is correct
00101         try:
00102             verifyClass(interface, klass)
00103         except (BrokenImplementation, DoesNotImplement,
00104           BrokenMethodImplementation), errmsg:
00105             self.fail('The class %s does not implement %s correctly: \n%s'
00106                 % (className(klass), className(interface), errmsg))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented in Archetypes.tests.test_interfaces.InstanceInterfaceTest.

Definition at line 91 of file test_interfaces.py.


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