[Zope3-checkins] CVS: Zope3/src/zope/interface/tests - test_surrogate.py:1.2 iadapter.py:1.5 test_declarations.py:1.10 test_interface.py:1.8

Jim Fulton cvs-admin at zope.org
Fri Nov 21 12:11:45 EST 2003


Update of /cvs-repository/Zope3/src/zope/interface/tests
In directory cvs.zope.org:/tmp/cvs-serv31759/src/zope/interface/tests

Modified Files:
	iadapter.py test_declarations.py test_interface.py 
Added Files:
	test_surrogate.py 
Log Message:
Refactored interfaces to use more efficient structures internally to
track relationships between interfaces.  Interfaces now maintain a
mapping with keys for all of the interfaces they extend. This allows
questions like "Does this interface extend another" to be anwered much
more quickly.

Unified interfaces and declarations into "specifications".  Like
interfaces, declarations also keep track of the specifications they
extend.

Class implementation declarations now have bases that include the
interfaces declared for them directly as well as declarations for base
classes.

Similarly, instance declarations now have, as one of their bases, the
declarations for their classes.


=== Zope3/src/zope/interface/tests/test_surrogate.py 1.1 => 1.2 ===
--- /dev/null	Fri Nov 21 12:11:45 2003
+++ Zope3/src/zope/interface/tests/test_surrogate.py	Fri Nov 21 12:11:44 2003
@@ -0,0 +1,268 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+from zope.interface.surrogate import SurrogateRegistry
+import zope.interface
+
+class IF0(zope.interface.Interface):
+    pass
+class IF1(IF0):
+    pass
+
+class F1:
+    zope.interface.implements(IF1)
+
+class IB0(zope.interface.Interface):
+    pass
+class IB1(IB0):
+    pass
+
+class IR0(zope.interface.Interface):
+    pass
+class IR1(IR0):
+    pass
+
+class R1:
+    zope.interface.implements(IR1)
+
+class Adapter:
+    def __init__(self, *args):
+        self.args = args
+
+class A1(Adapter):
+    pass
+
+class A2(Adapter):
+    pass
+
+def test_multi_adapter_w_default():
+    """
+    >>> c = F1()
+    >>> r = R1()
+
+    >>> registry = SurrogateRegistry()
+    
+    >>> registry.provideAdapter(None, IB1, [A1], name='bob', with=[IR0])
+
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__ is A1
+    True
+    >>> a.args == (c, r)
+    True
+    
+    >>> registry.queryMultiAdapter((c, r), IB0, 'bruce')
+
+    >>> registry.provideAdapter(None, IB1, [A2], name='bob', with=[IR1])
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__ is A2
+    True
+    >>> a.args == (c, r)
+    True
+    
+    """
+
+def test_multi_adapter_w_inherited_and_multiple_registrations():
+    """
+    >>> c = F1()
+    >>> r = R1()
+
+    >>> registry = SurrogateRegistry()
+
+    >>> class IX(zope.interface.Interface):
+    ...    pass
+
+    >>> class AX(Adapter):
+    ...     pass
+    
+    >>> registry.provideAdapter(IF0, IB1, [A1], name='bob', with=[IR0])
+    >>> registry.provideAdapter(IF1, IB1, [AX], name='bob', with=[IX])
+
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__ is A1
+    True
+    >>> a.args == (c, r)
+    True
+    """
+
+def test_named_adapter_with_default():
+    """Query a named simple adapter
+
+    >>> import zope.interface
+
+    >>> c = F1()
+
+    >>> registry = SurrogateRegistry()
+
+    If we ask for a named adapter, we won't get a result unless there
+    is a named adapter, even if the object implements the interface:
+
+    >>> registry.queryNamedAdapter(c, IF0, 'bob')
+
+    >>> registry.provideAdapter(None, IB1, [A1], name='bob')
+    >>> a = registry.queryNamedAdapter(c, IB0, 'bob')
+    >>> a.__class__ is A1
+    True
+    >>> a.args == (c, )
+    True
+
+    >>> registry.queryNamedAdapter(c, IB0, 'bruce')
+
+    >>> registry.provideAdapter(None, IB0, [A2], name='bob')
+    >>> a = registry.queryNamedAdapter(c, IB0, 'bob')
+    >>> a.__class__ is A2
+    True
+    >>> a.args == (c, )
+    True
+
+
+    """
+
+def test_multi_adapter_gets_closest_provided():
+    """
+    >>> c = F1()
+    >>> r = R1()
+
+    >>> registry = SurrogateRegistry()
+    >>> registry.provideAdapter(IF1, IB0, [A1], name='bob', with=[IR0])
+    >>> registry.provideAdapter(IF1, IB1, [A2], name='bob', with=[IR0])
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__ is A1
+    True
+
+    >>> registry = SurrogateRegistry()
+    >>> registry.provideAdapter(IF1, IB1, [A2], name='bob', with=[IR0])
+    >>> registry.provideAdapter(IF1, IB0, [A1], name='bob', with=[IR0])
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__ is A1
+    True
+
+    >>> registry = SurrogateRegistry()
+    >>> registry.provideAdapter(IF1, IB0, [A1], name='bob', with=[IR0])
+    >>> registry.provideAdapter(IF1, IB1, [A2], name='bob', with=[IR1])
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__ is A2
+    True
+
+    >>> registry = SurrogateRegistry()
+    >>> registry.provideAdapter(IF1, IB1, [A2], name='bob', with=[IR1])
+    >>> registry.provideAdapter(IF1, IB0, [A1], name='bob', with=[IR0])
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__ is A2
+    True
+
+    """
+
+def test_multi_adapter_check_non_default_dont_hide_default():
+    """
+    >>> c = F1()
+    >>> r = R1()
+
+    >>> registry = SurrogateRegistry()
+
+    >>> class IX(zope.interface.Interface):
+    ...     pass
+
+    
+    >>> registry.provideAdapter(None, IB0, [A1], name='bob', with=[IR0])
+    >>> registry.provideAdapter(IF1,  IB0, [A2], name='bob', with=[IX])
+    >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+    >>> a.__class__.__name__
+    'A1'
+
+    """
+
+
+def test_getRegisteredMatching_with_with():
+    """
+    >>> registry = SurrogateRegistry()
+    >>> registry.provideAdapter(None, IB0, '_0')
+    >>> registry.provideAdapter(IF0, IB0, '00')
+    >>> registry.provideAdapter(IF1, IB0, '10')
+    >>> registry.provideAdapter(IF1, IB1, '11')
+    >>> registry.provideAdapter(IF0, IB0, '000', with=(IR0,))
+    >>> registry.provideAdapter(IF1, IB0, '100', with=(IR0,))
+    >>> registry.provideAdapter(IF1, IB1, '110', with=(IR0,))
+    >>> registry.provideAdapter(IF0, IB0, '001', with=(IR1,))
+    >>> registry.provideAdapter(IF1, IB0, '101', with=(IR1,))
+    >>> registry.provideAdapter(IF1, IB1, '111', with=(IR1,))
+
+    >>> from pprint import PrettyPrinter
+    >>> pprint = PrettyPrinter(width=60).pprint
+    >>> def sorted(x):
+    ...    x = [(getattr(r, '__name__', None), p.__name__,
+    ...          [w.__name__ for w in rwith], n, f)
+    ...         for (r, p, rwith, n, f) in x]
+    ...    x.sort()
+    ...    pprint(x)
+
+    >>> sorted(registry.getRegisteredMatching())
+    [(None, 'IB0', [], u'', '_0'),
+     ('IF0', 'IB0', [], u'', '00'),
+     ('IF0', 'IB0', ['IR0'], u'', '000'),
+     ('IF0', 'IB0', ['IR1'], u'', '001'),
+     ('IF1', 'IB0', [], u'', '10'),
+     ('IF1', 'IB0', ['IR0'], u'', '100'),
+     ('IF1', 'IB0', ['IR1'], u'', '101'),
+     ('IF1', 'IB1', [], u'', '11'),
+     ('IF1', 'IB1', ['IR0'], u'', '110'),
+     ('IF1', 'IB1', ['IR1'], u'', '111')]
+    >>> sorted(registry.getRegisteredMatching(required=[IF0]))
+    [(None, 'IB0', [], u'', '_0'),
+     ('IF0', 'IB0', [], u'', '00'),
+     ('IF0', 'IB0', ['IR0'], u'', '000'),
+     ('IF0', 'IB0', ['IR1'], u'', '001')]
+    >>> sorted(registry.getRegisteredMatching(required=[IF1],
+    ...                                       provided=[IB0]))
+    [(None, 'IB0', [], u'', '_0'),
+     ('IF0', 'IB0', [], u'', '00'),
+     ('IF0', 'IB0', ['IR0'], u'', '000'),
+     ('IF0', 'IB0', ['IR1'], u'', '001'),
+     ('IF1', 'IB0', [], u'', '10'),
+     ('IF1', 'IB0', ['IR0'], u'', '100'),
+     ('IF1', 'IB0', ['IR1'], u'', '101'),
+     ('IF1', 'IB1', [], u'', '11'),
+     ('IF1', 'IB1', ['IR0'], u'', '110'),
+     ('IF1', 'IB1', ['IR1'], u'', '111')]
+    >>> sorted(registry.getRegisteredMatching(required=[IF1],
+    ...                                       provided=[IB0],
+    ...                                       with=[IR0]))
+    [('IF0', 'IB0', ['IR0'], u'', '000'),
+     ('IF1', 'IB0', ['IR0'], u'', '100'),
+     ('IF1', 'IB1', ['IR0'], u'', '110')]
+    >>> sorted(registry.getRegisteredMatching(required=[IF1],
+    ...                                       provided=[IB0],
+    ...                                       with=[IR1]))
+    [('IF0', 'IB0', ['IR0'], u'', '000'),
+     ('IF0', 'IB0', ['IR1'], u'', '001'),
+     ('IF1', 'IB0', ['IR0'], u'', '100'),
+     ('IF1', 'IB0', ['IR1'], u'', '101'),
+     ('IF1', 'IB1', ['IR0'], u'', '110'),
+     ('IF1', 'IB1', ['IR1'], u'', '111')]
+    """
+
+
+
+
+def test_suite():
+    return unittest.TestSuite((
+        DocTestSuite('zope.interface.surrogate'),
+        DocTestSuite(),
+        ))
+
+if __name__ == '__main__': unittest.main()


=== Zope3/src/zope/interface/tests/iadapter.py 1.4 => 1.5 ===
--- Zope3/src/zope/interface/tests/iadapter.py:1.4	Sat May  3 12:37:26 2003
+++ Zope3/src/zope/interface/tests/iadapter.py	Fri Nov 21 12:11:44 2003
@@ -165,7 +165,7 @@
         registry = self.__registery()
 
         got = list(registry.getRegisteredMatching(
-            required_interfaces = (R1, )
+            required = (R1, )
             ))
         got.sort()
         expect = [
@@ -179,7 +179,7 @@
         registry = self.__registery()
 
         got = list(registry.getRegisteredMatching(
-            required_interfaces = (R12, R2)
+            required = (R12, R2)
             ))
         got.sort()
         expect = [
@@ -193,9 +193,7 @@
     def test_getRegisteredMatching_provided_P1(self):
         registry = self.__registery()
 
-        got = list(registry.getRegisteredMatching(
-            provided_interfaces = (P1, )
-            ))
+        got = list(registry.getRegisteredMatching(provided = (P1, )))
         got.sort()
         expect = [
             (None, P3, 'default P3'),
@@ -209,7 +207,7 @@
         registry = self.__registery()
 
         got = list(registry.getRegisteredMatching(
-            provided_interfaces = (P3, )
+            provided = (P3, )
             ))
         got.sort()
         expect = [
@@ -224,8 +222,8 @@
         registry = self.__registery()
 
         got = list(registry.getRegisteredMatching(
-            required_interfaces = (R4, R12),
-            provided_interfaces = (P1, ),
+            required = (R4, R12),
+            provided = (P1, ),
             ))
         got.sort()
         expect = [
@@ -240,8 +238,8 @@
         registry = self.__registery()
 
         got = list(registry.getRegisteredMatching(
-            required_interfaces = (R4, R12),
-            provided_interfaces = (P3, ),
+            required = (R4, R12),
+            provided = (P3, ),
             ))
         got.sort()
         expect = [
@@ -257,8 +255,8 @@
         registry = self.__registery()
 
         got = list(registry.getRegisteredMatching(
-            required_interfaces = (R2, ),
-            provided_interfaces = (P3, ),
+            required = (R2, ),
+            provided = (P3, ),
             ))
         got.sort()
         expect = [


=== Zope3/src/zope/interface/tests/test_declarations.py 1.9 => 1.10 ===
--- Zope3/src/zope/interface/tests/test_declarations.py:1.9	Tue Sep 23 15:12:36 2003
+++ Zope3/src/zope/interface/tests/test_declarations.py	Fri Nov 21 12:11:44 2003
@@ -44,47 +44,36 @@
 class D(COnly):
     implements(I5)
     
+def test_ObjectSpecification_Simple():
+    """
+    >>> c = C()
+    >>> directlyProvides(c, I4)
+    >>> [i.__name__ for i in providedBy(c)]
+    ['I4', 'I3', 'I1', 'I2']
+    """
+
+def test_ObjectSpecification_Simple_w_only():
+    """
+    >>> c = COnly()
+    >>> directlyProvides(c, I4)
+    >>> [i.__name__ for i in providedBy(c)]
+    ['I4', 'I3']
+    """
+
+def test_ObjectSpecification_Simple_old_style():
+    """
+    >>> c = COnly_old()
+    >>> directlyProvides(c, I4)
+    >>> [i.__name__ for i in providedBy(c)]
+    ['I4', 'I3']
+    """
+
 
 class Test(unittest.TestCase):
 
     # Note that most of the tests are in the doc strings of the
     # declarations module.
 
-    def test_ObjectSpecification_Simple(self):
-        c = C()
-        directlyProvides(c, I4)
-        spec = providedBy(c)
-        sig = spec.__signature__
-        expect = ('zope.interface.tests.test_declarations.I4\t'
-                  'zope.interface.Interface',
-                  'zope.interface.tests.test_declarations.I3\t'
-                  'zope.interface.tests.test_declarations.I1\t'
-                  'zope.interface.tests.test_declarations.I2\t'
-                  'zope.interface.Interface')
-        self.assertEqual(sig, expect)
-
-    def test_ObjectSpecification_Simple_w_only(self):
-        c = COnly()
-        directlyProvides(c, I4)
-        spec = providedBy(c)
-        sig = spec.__signature__
-        expect = ('zope.interface.tests.test_declarations.I4\t'
-                  'zope.interface.Interface',
-                  'zope.interface.tests.test_declarations.I3\t'
-                  'zope.interface.Interface')
-        self.assertEqual(sig, expect)
-
-    def test_ObjectSpecification_Simple_old_style(self):
-        c = COnly_old()
-        directlyProvides(c, I4)
-        spec = providedBy(c)
-        sig = spec.__signature__
-        expect = ('zope.interface.tests.test_declarations.I4\t'
-                  'zope.interface.Interface',
-                  'zope.interface.tests.test_declarations.I3\t'
-                  'zope.interface.Interface')
-        self.assertEqual(sig, expect)
-
     def test_backward_compat(self):
 
         class C1: __implements__ = I1
@@ -131,12 +120,10 @@
 
     def test_builtins(self):
         # Setup
-        from zope.interface.declarations import _implements_reg
-        oldint = _implements_reg.get(int)
-        if oldint:
-            del _implements_reg[int]
-        
-        
+
+        intspec = implementedBy(int)
+        olddeclared = intspec.declared
+                
         classImplements(int, I1)
         class myint(int):
             implements(I2)
@@ -151,15 +138,12 @@
                          ['I3', 'I2', 'I1'])
 
         # cleanup
-        del _implements_reg[int]
+        intspec.declared = olddeclared
+        classImplements(int)
 
         x = 42
         self.assertEqual([i.getName() for i in providedBy(x)],
                          [])
-
-        # cleanup
-        if oldint is not None:
-            _implements_reg[int] = oldint
         
 
 def test_signature_w_no_class_interfaces():
@@ -168,14 +152,13 @@
     >>> class C:
     ...     pass
     >>> c = C()
-    >>> providedBy(c).__signature__
-    ''
+    >>> list(providedBy(c))
+    []
     
     >>> class I(Interface):
     ...    pass
     >>> directlyProvides(c, I)
-    >>> int(providedBy(c).__signature__
-    ...     == directlyProvidedBy(c).__signature__)
+    >>> list(providedBy(c))  == list(directlyProvidedBy(c))
     1
     """
 
@@ -200,99 +183,102 @@
 
     """
 
-def test_computeSignature():
-    """Compute a specification signature
-
-    For example::
-
-      >>> from zope.interface import Interface
-      >>> class I1(Interface): pass
-      ...
-      >>> class I2(I1): pass
-      ...
-      >>> spec = InterfaceSpecification(I2)
-      >>> int(spec.__signature__ == "%s\\t%s\\t%s" % (
-      ...    I2.__identifier__, I1.__identifier__,
-      ...    Interface.__identifier__))
-      1
-
-    """
-
-def test_cant_pickle_plain_specs():
-    """
-    >>> from pickle import dumps
-    >>> dumps(InterfaceSpecification())
-    Traceback (most recent call last):
-    ...
-    TypeError: can't pickle InterfaceSpecification objects
-    >>> dumps(InterfaceSpecification(), 2)
-    Traceback (most recent call last):
-    ...
-    TypeError: can't pickle InterfaceSpecification objects
-    
-    """
-
 def test_pickle_provides_specs():
     """
     >>> from pickle import dumps, loads
     >>> a = A()
-    >>> int(I2.isImplementedBy(a))
+    >>> I2.isImplementedBy(a)
     0
     >>> directlyProvides(a, I2)
-    >>> int(I2.isImplementedBy(a))
+    >>> I2.isImplementedBy(a)
     1
     >>> a2 = loads(dumps(a))
-    >>> int(I2.isImplementedBy(a2))
+    >>> I2.isImplementedBy(a2)
     1
     
     """
 
-def test_pickle_implements_specs():
+def test_that_we_dont_inherit_class_provides():
     """
-    >>> from pickle import dumps, loads
-    >>> class A:
-    ...   implements(I1)
-    >>> class B(A):
-    ...   implements(I2)
-    >>> names =  [i.getName() for i in implementedBy(B)]
-    >>> names
-    ['I2', 'I1']
-    >>> old = B.__dict__['__implements__']
-    >>> new = loads(dumps(old))
-    >>> names =  [i.getName() for i in new]
-    >>> names
-    ['I2']
-    >>> classImplements(A, I3)
-    >>> B.__implements__ = new
-    >>> names =  [i.getName() for i in implementedBy(B)]
-    >>> names
-    ['I2', 'I1', 'I3']
+    >>> class X:
+    ...     classProvides(I1)
+    >>> class Y(X):
+    ...     pass
+    >>> [i.__name__ for i in X.__provides__]
+    ['I1']
+    >>> Y.__provides__
+    Traceback (most recent call last):
+    ...
+    AttributeError: __provides__
     
     """
 
-def test_pickle_only_specs():
+def test_that_we_dont_inherit_provides_optimizations():
     """
-    >>> from pickle import dumps, loads
+
+    When we make a declaration for a class, we install a __provides__
+    descriptors that provides a default for instances that don't have
+    instance-specific declarations:
+    
     >>> class A:
-    ...   implements(I1)
-    >>> class B(A):
-    ...   implementsOnly(I2)
-    >>> names =  [i.getName() for i in implementedBy(B)]
-    >>> names
-    ['I2']
-    >>> old = B.__dict__['__implements__']
-    >>> new = loads(dumps(old))
-    >>> names =  [i.getName() for i in new]
-    >>> names
-    ['I2']
-    >>> classImplements(A, I3)
-    >>> B.__implements__ = new
-    >>> names =  [i.getName() for i in implementedBy(B)]
-    >>> names
+    ...     implements(I1)
+
+    >>> class B:
+    ...     implements(I2)
+
+    >>> [i.__name__ for i in A().__provides__]
+    ['I1']
+    >>> [i.__name__ for i in B().__provides__]
     ['I2']
+
+    But it's important that we don't use this for subclasses without
+    declarations.  This would cause incorrect results:
+
+    >>> class X(A, B):
+    ...     pass
+
+    >>> X().__provides__
+    Traceback (most recent call last):
+    ...
+    AttributeError: __provides__
+
+    However, if we "induce" a declaration, by calling implementedBy
+    (even indirectly through providedBy):
+
+    >>> [i.__name__ for i in providedBy(X())]
+    ['I1', 'I2']
+
+
+    then the optimization will work:
+    
+    >>> [i.__name__ for i in X().__provides__]
+    ['I1', 'I2']
     
     """
 
+def test_classProvides_before_implements():
+    """Special descriptor for class __provides__
+
+    The descriptor caches the implementedBy info, so that
+    we can get declarations for objects without instance-specific
+    interfaces a bit quicker.
+
+        For example::
+
+          >>> from zope.interface import Interface
+          >>> class IFooFactory(Interface):
+          ...     pass
+          >>> class IFoo(Interface):
+          ...     pass
+          >>> class C:
+          ...     classProvides(IFooFactory)
+          ...     implements(IFoo)
+          >>> [i.getName() for i in C.__provides__]
+          ['IFooFactory']
+
+          >>> [i.getName() for i in C().__provides__]
+          ['IFoo']
+    """
 
 def test_suite():
     suite = unittest.TestSuite()


=== Zope3/src/zope/interface/tests/test_interface.py 1.7 => 1.8 ===
--- Zope3/src/zope/interface/tests/test_interface.py:1.7	Thu Jul  3 18:46:20 2003
+++ Zope3/src/zope/interface/tests/test_interface.py	Fri Nov 21 12:11:44 2003
@@ -13,6 +13,7 @@
 ##############################################################################
 
 import unittest
+from zope.testing.doctestunit import DocTestSuite
 from zope.interface.tests.unitfixtures import *  # hehehe
 from zope.interface.exceptions import BrokenImplementation
 from zope.interface import implementedBy
@@ -29,56 +30,54 @@
         pass
 
     def testClassImplements(self):
-        assert IC.isImplementedByInstancesOf(C)
+        self.assert_(IC.isImplementedByInstancesOf(C))
 
-        assert I1.isImplementedByInstancesOf(A)
-        assert I1.isImplementedByInstancesOf(B)
-        assert not I1.isImplementedByInstancesOf(C)
-        assert I1.isImplementedByInstancesOf(D)
-        assert I1.isImplementedByInstancesOf(E)
-
-        assert not I2.isImplementedByInstancesOf(A)
-        assert I2.isImplementedByInstancesOf(B)
-        assert not I2.isImplementedByInstancesOf(C)
+        self.assert_(I1.isImplementedByInstancesOf(A))
+        self.assert_(I1.isImplementedByInstancesOf(B))
+        self.assert_(not I1.isImplementedByInstancesOf(C))
+        self.assert_(I1.isImplementedByInstancesOf(D))
+        self.assert_(I1.isImplementedByInstancesOf(E))
+
+        self.assert_(not I2.isImplementedByInstancesOf(A))
+        self.assert_(I2.isImplementedByInstancesOf(B))
+        self.assert_(not I2.isImplementedByInstancesOf(C))
 
         # No longer after interfacegeddon
-        # assert not I2.isImplementedByInstancesOf(D)
+        # self.assert_(not I2.isImplementedByInstancesOf(D))
 
-        assert not I2.isImplementedByInstancesOf(E)
+        self.assert_(not I2.isImplementedByInstancesOf(E))
 
     def testUtil(self):
-        f = implementedBy
-        assert IC in f(C)
-        assert I1 in f(A)
-        assert not I1 in f(C)
-        assert I2 in f(B)
-        assert not I2 in f(C)
-
-        f = providedBy
-        assert IC in f(C())
-        assert I1 in f(A())
-        assert not I1 in f(C())
-        assert I2 in f(B())
-        assert not I2 in f(C())
+        self.assert_(IC in implementedBy(C))
+        self.assert_(I1 in implementedBy(A))
+        self.assert_(not I1 in implementedBy(C))
+        self.assert_(I2 in implementedBy(B))
+        self.assert_(not I2 in implementedBy(C))
+
+        self.assert_(IC in providedBy(C()))
+        self.assert_(I1 in providedBy(A()))
+        self.assert_(not I1 in providedBy(C()))
+        self.assert_(I2 in providedBy(B()))
+        self.assert_(not I2 in providedBy(C()))
 
 
     def testObjectImplements(self):
-        assert IC.isImplementedBy(C())
+        self.assert_(IC.isImplementedBy(C()))
 
-        assert I1.isImplementedBy(A())
-        assert I1.isImplementedBy(B())
-        assert not I1.isImplementedBy(C())
-        assert I1.isImplementedBy(D())
-        assert I1.isImplementedBy(E())
-
-        assert not I2.isImplementedBy(A())
-        assert I2.isImplementedBy(B())
-        assert not I2.isImplementedBy(C())
+        self.assert_(I1.isImplementedBy(A()))
+        self.assert_(I1.isImplementedBy(B()))
+        self.assert_(not I1.isImplementedBy(C()))
+        self.assert_(I1.isImplementedBy(D()))
+        self.assert_(I1.isImplementedBy(E()))
+
+        self.assert_(not I2.isImplementedBy(A()))
+        self.assert_(I2.isImplementedBy(B()))
+        self.assert_(not I2.isImplementedBy(C()))
 
         # Not after interface geddon
-        # assert not I2.isImplementedBy(D())
+        # self.assert_(not I2.isImplementedBy(D()))
 
-        assert not I2.isImplementedBy(E())
+        self.assert_(not I2.isImplementedBy(E()))
 
     def testDeferredClass(self):
         a = A()
@@ -86,18 +85,18 @@
 
 
     def testInterfaceExtendsInterface(self):
-        assert BazInterface.extends(BobInterface)
-        assert BazInterface.extends(BarInterface)
-        assert BazInterface.extends(FunInterface)
-        assert not BobInterface.extends(FunInterface)
-        assert not BobInterface.extends(BarInterface)
-        assert BarInterface.extends(FunInterface)
-        assert not BarInterface.extends(BazInterface)
+        self.assert_(BazInterface.extends(BobInterface))
+        self.assert_(BazInterface.extends(BarInterface))
+        self.assert_(BazInterface.extends(FunInterface))
+        self.assert_(not BobInterface.extends(FunInterface))
+        self.assert_(not BobInterface.extends(BarInterface))
+        self.assert_(BarInterface.extends(FunInterface))
+        self.assert_(not BarInterface.extends(BazInterface))
 
     def testVerifyImplementation(self):
         from zope.interface.verify import verifyClass
-        assert verifyClass(FooInterface, Foo)
-        assert Interface.isImplementedBy(I1)
+        self.assert_(verifyClass(FooInterface, Foo))
+        self.assert_(Interface.isImplementedBy(I1))
 
     def test_names(self):
         names = list(_I2.names()); names.sort()
@@ -181,7 +180,9 @@
 
 
 def test_suite():
-    return unittest.makeSuite(InterfaceTests)
+    suite = unittest.makeSuite(InterfaceTests)
+    suite.addTest(DocTestSuite("zope.interface.interface"))
+    return suite
 
 def main():
     unittest.TextTestRunner().run(test_suite())




More information about the Zope3-Checkins mailing list