[Zodb-checkins] CVS: Zope3/src/zope/interface/tests - m1.py:1.1.2.1 m2.py:1.1.2.1 test_declarations.py:1.1.2.1 dummy.py:1.3.6.1 iadapter.py:1.2.18.1 test_interface.py:1.3.16.1

Jim Fulton jim at zope.com
Fri Apr 18 23:46:51 EDT 2003


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

Modified Files:
      Tag: interfacegeddon-branch
	dummy.py iadapter.py test_interface.py 
Added Files:
      Tag: interfacegeddon-branch
	m1.py m2.py test_declarations.py 
Log Message:
committing work in progress to interfacegeddon branch.



=== 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.2.1 2003/04/19 02:46:20 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.3 => 1.3.6.1 ===
--- Zope3/src/zope/interface/tests/dummy.py:1.3	Thu Mar 13 13:49:15 2003
+++ Zope3/src/zope/interface/tests/dummy.py	Fri Apr 18 22:46:20 2003
@@ -12,8 +12,9 @@
 #
 ##############################################################################
 from zope.interface.tests.ifoo import IFoo
+from zope.interface import moduleProvides
 
-__implements__ = IFoo
+moduleProvides(IFoo)
 
 def bar(baz):
     pass


=== Zope3/src/zope/interface/tests/iadapter.py 1.2 => 1.2.18.1 ===
--- Zope3/src/zope/interface/tests/iadapter.py:1.2	Wed Dec 25 09:15:12 2002
+++ Zope3/src/zope/interface/tests/iadapter.py	Fri Apr 18 22:46:20 2003
@@ -19,7 +19,7 @@
 
 import unittest
 
-from zope.interface import Interface
+from zope.interface import Interface, directlyProvides
 
 class R1(Interface): pass
 class R12(Interface): pass
@@ -87,15 +87,11 @@
         c = C()
 
         for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
-            c.__implements__ = R
+            directlyProvides(c, R)
             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)]:
-            c.__implements__ = R
-            self.assertEqual(registry.getForObject(c, None), None)
-
-        c.__implements__ = R1
+        directlyProvides(c, R1)
         for P in [P1, P2, P3]:
             self.assertEqual(registry.getForObject(c, P), 'any P3')
 
@@ -125,7 +121,7 @@
         c = C()
 
         for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
-            c.__implements__ = R
+            directlyProvides(c, R)
             for P in [P1, P2, P3]:
                 self.assertEqual(
                     registry.getForObject(c, P,


=== Zope3/src/zope/interface/tests/test_interface.py 1.3 => 1.3.16.1 ===
--- Zope3/src/zope/interface/tests/test_interface.py:1.3	Sat Jan 25 00:13:47 2003
+++ Zope3/src/zope/interface/tests/test_interface.py	Fri Apr 18 22:46:20 2003
@@ -16,8 +16,8 @@
 import zope.interface
 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
 
@@ -41,18 +41,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())
@@ -72,7 +75,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