[Zodb-checkins] CVS: Zope3/src/zope/interface/tests - test_declarations.py:1.9.6.1

Jim Fulton jim at zope.com
Sat Oct 11 10:19:35 EDT 2003


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

Modified Files:
      Tag: adaptergeddon-branch
	test_declarations.py 
Log Message:
Refactored declaration framework to unify declarations and interfaces.


=== Zope3/src/zope/interface/tests/test_declarations.py 1.9 => 1.9.6.1 ===
--- 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	Sat Oct 11 10:19:04 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,20 @@
 
     """
 
-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():
-    """
-    >>> 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']
-    
-    """
-
-def test_pickle_only_specs():
-    """
-    >>> from pickle import dumps, loads
-    >>> 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
-    ['I2']
-    
-    """
-
 
 def test_suite():
     suite = unittest.TestSuite()




More information about the Zodb-checkins mailing list