[Zodb-checkins] CVS: Zope3/src/zope/interface/tests - m1.py:1.1.4.1 m2.py:1.1.4.1 test_declarations.py:1.1.4.1 dummy.py:1.4.6.1 iadapter.py:1.3.6.1 test_interface.py:1.4.4.1

Jim Fulton jim at zope.com
Fri May 2 16:43:25 EDT 2003


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

Modified Files:
      Tag: interfacegeddon2-branch
	dummy.py iadapter.py test_interface.py 
Added Files:
      Tag: interfacegeddon2-branch
	m1.py m2.py test_declarations.py 
Log Message:
Merged interfacegeddon changes into second interfacegeddon branch in
preparation for the final merge.


=== Added File Zope3/src/zope/interface/tests/m1.py ===
"""Test module that declares an interface
"""

from zope.interface import Interface, moduleProvides

class I1(Interface): pass
class I2(Interface): pass

moduleProvides(I1, I2)


=== Added File Zope3/src/zope/interface/tests/m2.py ===
"""Test module that doesn't declare an interface
"""


=== Added File Zope3/src/zope/interface/tests/test_declarations.py ===
##############################################################################
#
# 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.
#
##############################################################################
"""Test the new API for making and checking interface declarations


$Id: test_declarations.py,v 1.1.4.1 2003/05/02 19:42:54 jim Exp $
"""

import unittest
from zope.interface import *
from zope.testing.doc import doctest
from zope.interface import Interface

class I1(Interface): pass
class I2(Interface): pass
class I3(Interface): pass
class I4(Interface): pass
class I5(Interface): pass

class A:
    implements(I1)
class B:
    implements(I2)
class C(A, B):
    implements(I3)

class COnly(A, B):
    implementsOnly(I3)
    
class D(COnly):
    implements(I5)
    

class Test(unittest.TestCase):

    # Note that most of the tests are in the doc strings of the
    # declarations module.

    def test_doctest(self):
        doctest(self, declarations)

    def test_ObjectSpecification_Simple(self):
        c = C()
        directlyProvides(c, I4)
        spec = providedBy(c)
        sig = spec.__signature__
        expect = (c.__provides__.__signature__,
                  C.__dict__['__implements__'].__signature__,
                  A.__dict__['__implements__'].__signature__,
                  B.__dict__['__implements__'].__signature__,
                  )

    def test_ObjectSpecification_Simple_w_only(self):
        c = C()
        directlyProvides(c, I4)
        spec = providedBy(c)
        sig = spec.__signature__
        expect = (c.__provides__.__signature__,
                  C.__dict__['__implements__'].__signature__,
                  A.__dict__['__implements__'].__signature__,
                  B.__dict__['__implements__'].__signature__,
                  )



        c = COnly()
        directlyProvides(c, I4)
        spec = providedBy(c)
        sig = spec.__signature__
        expect = (c.__provides__.__signature__,
                  COnly.__dict__['__implements__'].__signature__,
                  A.__dict__['__implements__'].__signature__,
                  B.__dict__['__implements__'].__signature__,
                  )

    def test_backward_compat(self):

        class C1: __implements__ = I1
        class C2(C1): __implements__ = I2, I5
        class C3(C2): __implements__ = I3, C2.__implements__

        self.assert_(C3.__implements__.__class__ is tuple)

        self.assertEqual(
            [i.__name__ for i in providedBy(C3())],
            ['I3', 'I2', 'I5'],
            )

        class C4(C3):
            implements(I4)

        self.assertEqual(
            [i.__name__ for i in providedBy(C4())],
            ['I4', 'I3', 'I2', 'I5'],
            )

        self.assertEqual(
            [i.__name__ for i in C4.__implements__],
            ['I4', 'I3', 'I2', 'I5'],
            )

        # Note that C3.__implements__ should now be a sequence of interfaces
        self.assertEqual(
            [i.__name__ for i in C3.__implements__],
            ['I3', 'I2', 'I5'],
            )
        self.failIf(C3.__implements__.__class__ is tuple)

    def test_module(self):
        import zope.interface.tests.m1
        import zope.interface.tests.m2
        directlyProvides(zope.interface.tests.m2,
                         zope.interface.tests.m1.I1,
                         zope.interface.tests.m1.I2,
                         )
        self.assertEqual(list(providedBy(zope.interface.tests.m1)),
                         list(providedBy(zope.interface.tests.m2)),
                         )

    def test_builtins(self):
        classImplements(int, I1)
        class myint(int):
            implements(I2)

        x = 42
        self.assertEqual([i.__name__ for i in providedBy(x)],
                         ['I1'])

        x = myint(42)
        directlyProvides(x, I3)
        self.assertEqual([i.__name__ for i in providedBy(x)],
                         ['I3', 'I2', 'I1'])

        # cleanup
        from zope.interface.declarations import _implements_reg
        _implements_reg.clear()

        x = 42
        self.assertEqual([i.__name__ for i in providedBy(x)],
                         [])
        


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(Test))
    return suite


if __name__ == '__main__':
    unittest.main()


=== Zope3/src/zope/interface/tests/dummy.py 1.4 => 1.4.6.1 ===
--- Zope3/src/zope/interface/tests/dummy.py:1.4	Fri Apr 18 18:12:32 2003
+++ Zope3/src/zope/interface/tests/dummy.py	Fri May  2 15:42:54 2003
@@ -13,6 +13,7 @@
 ##############################################################################
 from zope.interface import moduleProvides
 from zope.interface.tests.ifoo import IFoo
+from zope.interface import moduleProvides
 
 moduleProvides(IFoo)
 


=== Zope3/src/zope/interface/tests/iadapter.py 1.3 => 1.3.6.1 ===
--- Zope3/src/zope/interface/tests/iadapter.py:1.3	Fri Apr 18 18:12:32 2003
+++ Zope3/src/zope/interface/tests/iadapter.py	Fri May  2 15:42:54 2003
@@ -91,10 +91,6 @@
             for P in [P1, P2, P3]:
                 self.assertEqual(registry.getForObject(c, P), 'R2 P3')
 
-        for R in [None, R1, R2, R3, R4, (R12, R2), (R12, R4)]:
-            directlyProvides(c, R)
-            self.assertEqual(registry.getForObject(c, None), None)
-
         directlyProvides(c, R1)
         for P in [P1, P2, P3]:
             self.assertEqual(registry.getForObject(c, P), 'any P3')


=== Zope3/src/zope/interface/tests/test_interface.py 1.4 => 1.4.4.1 ===
--- Zope3/src/zope/interface/tests/test_interface.py:1.4	Thu May  1 15:35:44 2003
+++ Zope3/src/zope/interface/tests/test_interface.py	Fri May  2 15:42:54 2003
@@ -15,8 +15,8 @@
 import unittest
 from zope.interface.tests.unitfixtures import *  # hehehe
 from zope.interface.exceptions import BrokenImplementation
-from zope.interface.implements import instancesOfObjectImplements
-from zope.interface.implements import objectImplements
+from zope.interface import implementedBy
+from zope.interface import providedBy
 from zope.interface import Interface
 from zope.interface.interface import Attribute
 
@@ -40,18 +40,21 @@
         assert not I2.isImplementedByInstancesOf(A)
         assert I2.isImplementedByInstancesOf(B)
         assert not I2.isImplementedByInstancesOf(C)
-        assert not I2.isImplementedByInstancesOf(D)
+
+        # No longer after interfacegeddon
+        # assert not I2.isImplementedByInstancesOf(D)
+
         assert not I2.isImplementedByInstancesOf(E)
 
     def testUtil(self):
-        f = instancesOfObjectImplements
+        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 = objectImplements
+        f = providedBy
         assert IC in f(C())
         assert I1 in f(A())
         assert not I1 in f(C())
@@ -71,7 +74,10 @@
         assert not I2.isImplementedBy(A())
         assert I2.isImplementedBy(B())
         assert not I2.isImplementedBy(C())
-        assert not I2.isImplementedBy(D())
+
+        # Not after interface geddon
+        # assert not I2.isImplementedBy(D())
+
         assert not I2.isImplementedBy(E())
 
     def testDeferredClass(self):




More information about the Zodb-checkins mailing list