[Zope3-checkins] CVS: Zope3/lib/python/Interface/Registry/tests - TestIAdapterRegistry.py:1.1 TestIImplementorRegistry.py:1.1 __init__.py:1.1 testAdapterRegistry.py:1.1 testImplementorRegistry.py:1.1 testTypeRegistry.py:1.1

Jim Fulton jim@zope.com
Thu, 1 Aug 2002 11:33:44 -0400


Update of /cvs-repository/Zope3/lib/python/Interface/Registry/tests
In directory cvs.zope.org:/tmp/cvs-serv4877/lib/python/Interface/Registry/tests

Added Files:
	TestIAdapterRegistry.py TestIImplementorRegistry.py 
	__init__.py testAdapterRegistry.py testImplementorRegistry.py 
	testTypeRegistry.py 
Log Message:
Refactored and moved Zope.ComponentArchitecture.IToIRegistry into
Interface.Registry. This is only the first step. The tests pass and
Zope 3 runs, but there are a bunch of wrong dependencies that still
need to get cleaned up, which is my next task.



=== Added File Zope3/lib/python/Interface/Registry/tests/TestIAdapterRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""

Revision information:
$Id: TestIAdapterRegistry.py,v 1.1 2002/08/01 15:33:43 jim Exp $
"""

from Interface import Interface

class R1(Interface): pass
class R12(Interface): pass
class R2(R1): pass
class R3(R2): pass
class R4(R3): pass

class P1(Interface): pass
class P2(P1): pass
class P3(P2): pass
class P4(P3): pass

class TestIAdapterRegistry:

    def testImplementsIAdapterRegistry(self):
        from Interface.Verify import verifyObject
        from Interface.Registry.IAdapterRegistry import IAdapterRegistry
        
        registry = self._TestIAdapterRegistry__new()

        verifyObject(IAdapterRegistry, registry)

    def __registery(self):        
        registry = self._TestIAdapterRegistry__new()

        registry.register(None, P3, 'default P3')
        registry.register(Interface, P3, 'any P3')
        registry.register(R2, P3, 'R2 P3')

        return registry
        

    def test_get(self):
        registry = self.__registery()

        for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
            for P in [P1, P2, P3]:
                self.assertEqual(registry.get((R, P)), 'R2 P3')

        for R in [None, R1, R2, R3, R4, (R12, R2), (R12, R4)]:
            self.assertEqual(registry.get((R, P4)), None)

        for P in [P1, P2, P3]:
            self.assertEqual(registry.get((R1, P)), 'any P3')

        for P in [P1, P2, P3]:
            self.assertEqual(registry.get((None, P)), 'default P3')

        
        
        



=== Added File Zope3/lib/python/Interface/Registry/tests/TestIImplementorRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""

Revision information:
$Id: TestIImplementorRegistry.py,v 1.1 2002/08/01 15:33:43 jim Exp $
"""

from Interface import Interface

class R1(Interface): pass
class R12(Interface): pass
class R2(R1): pass
class R3(R2): pass
class R4(R3): pass

class P1(Interface): pass
class P2(P1): pass
class P3(P2): pass
class P4(P3): pass

class TestIImplementorRegistry:

    def testImplementsIImplementorRegistry(self):
        from Interface.Verify import verifyObject
        from Interface.Registry.IImplementorRegistry \
             import IImplementorRegistry
        
        registry = self._TestIImplementorRegistry__new()

        verifyObject(IImplementorRegistry, registry)

    def __registery(self):        
        registry = self._TestIImplementorRegistry__new()

        registry.register(P3, 'C3')

        return registry
        

    def test_get(self):
        registry = self.__registery()

        for P in [P1, P2, P3]:
            self.assertEqual(registry.get(P), 'C3')

        self.assertEqual(registry.get(P4), None)

        registry.register(P1, 'C1')
        registry.register(P2, 'C3')
        
        
        



=== Added File Zope3/lib/python/Interface/Registry/tests/__init__.py ===
##############################################################################
#
# Copyright (c) 2002 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.
# 
##############################################################################



=== Added File Zope3/lib/python/Interface/Registry/tests/testAdapterRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""

Revision information:
$Id: testAdapterRegistry.py,v 1.1 2002/08/01 15:33:43 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from TestIAdapterRegistry import TestIAdapterRegistry

class Test(TestIAdapterRegistry, TestCase):

    def _TestIAdapterRegistry__new(self):
        from Interface.Registry.AdapterRegistry \
             import AdapterRegistry as Registry
        return Registry()

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/lib/python/Interface/Registry/tests/testImplementorRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""

Revision information:
$Id: testImplementorRegistry.py,v 1.1 2002/08/01 15:33:43 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from TestIImplementorRegistry import TestIImplementorRegistry

class Test(TestIImplementorRegistry, TestCase):

    def _TestIImplementorRegistry__new(self):
        from Interface.Registry.ImplementorRegistry \
             import ImplementorRegistry as Registry
        return Registry()

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/lib/python/Interface/Registry/tests/testTypeRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
# 
##############################################################################
"""

Revision information:
$Id: testTypeRegistry.py,v 1.1 2002/08/01 15:33:43 jim Exp $
"""

import unittest, sys
from Interface.Registry.TypeRegistry import TypeRegistry
from Interface import Interface

def getAllForObject(reg, ob):
    all = list(reg.getAllForObject(ob))
    all.sort()
    return all

class Test(unittest.TestCase):

    def test(self):
        class I1(Interface): pass
        class I2(I1): pass
        class I3(I2): pass

        reg = TypeRegistry()
        reg.register(I2, 2)

        class C1: __implements__ = I1
        class C2: __implements__ = I2
        class C3: __implements__ = I3
        class C: pass

        self.assertEqual(getAllForObject(reg, C1()), [])
        self.assertEqual(getAllForObject(reg, C2()), [2])
        self.assertEqual(getAllForObject(reg, C3()), [2])
        self.assertEqual(getAllForObject(reg,  C()), [])

        self.assertEqual(reg.get(I1), None)
        self.assertEqual(reg.get(I2), 2)
        self.assertEqual(reg.get(I3), None)

        reg.register(I1, 1)

        self.assertEqual(getAllForObject(reg, C1()), [1])
        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
        self.assertEqual(getAllForObject(reg, C3()), [1, 2])
        self.assertEqual(getAllForObject(reg,  C()), [])

        self.assertEqual(reg.get(I1), 1)
        self.assertEqual(reg.get(I2), 2)
        self.assertEqual(reg.get(I3), None)

        reg.register(I3, 3)

        self.assertEqual(getAllForObject(reg, C1()), [1])
        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
        self.assertEqual(getAllForObject(reg, C3()), [1, 2, 3])
        self.assertEqual(getAllForObject(reg,  C()), [])

        self.assertEqual(reg.get(I1), 1)
        self.assertEqual(reg.get(I2), 2)
        self.assertEqual(reg.get(I3), 3)

    def testDup(self):
        class I1(Interface): pass
        class I2(I1): pass
        class I3(I1): pass
        class I4(I2, I3): pass
        class C1: __implements__ = I1
        class C2: __implements__ = I2
        class C3: __implements__ = I3
        class C4: __implements__ = I4
        class C5: __implements__ = I1, I2, I3, I4
        class C: pass

        reg = TypeRegistry()
        reg.register(I1, 1)
        reg.register(I2, 2)
        reg.register(I3, 3)

        self.assertEqual(getAllForObject(reg, C1()), [1])
        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
        self.assertEqual(getAllForObject(reg, C3()), [1, 3])
        self.assertEqual(getAllForObject(reg, C4()), [1, 2, 3])
        self.assertEqual(getAllForObject(reg, C5()), [1, 2, 3])
        self.assertEqual(getAllForObject(reg,  C()), [])

def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())