[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - absIInterfaceService.py:1.1 test_interfaceservice.py:1.7

Jeremy Hylton jeremy@zope.com
Sun, 22 Jun 2003 16:18:00 -0400


Update of /cvs-repository/Zope3/src/zope/app/component/tests
In directory cvs.zope.org:/tmp/cvs-serv17983/src/zope/app/component/tests

Modified Files:
	test_interfaceservice.py 
Added Files:
	absIInterfaceService.py 
Log Message:
Add items() to IInterfaceService.

Refactor the test suite so that it can be used by multiple implementations of IInterfaceService.
Implement other search methods in terms of items(), because it is the most generic.


=== Added File Zope3/src/zope/app/component/tests/absIInterfaceService.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.
#
##############################################################################
"""Abstract test class for IInterfaceService."""

from zope.component.exceptions import ComponentLookupError
from zope.app.interfaces.component import IInterfaceService
from zope.interface import Interface
from zope.interface.verify import verifyObject

class B(Interface):
    pass

class I(Interface):
    """bah blah
    """

class I2(B):
    """eek
    """

class I3(B):
    """
    """
    def one():
        """method one"""

    def two():
        """method two"""

class IInterfaceServiceTests:

    def getServices(self):
        # Return pair of services, one to query, one to update.
        raise NotImplementedError
    
    def testVerifyIInterfaceService(self):
        verifyObject(IInterfaceService, self.getServices()[0])

    def listEq(self, iterable, expectedlist):
        self.assertEqual(list(iterable), expectedlist)

    def testInterfaceService(self):
        rservice, wservice = self.getServices()

        self.assertRaises(ComponentLookupError,
                          rservice.getInterface, 'Foo.Bar')
        self.assertEqual(rservice.queryInterface('Foo.Bar'), None)
        self.assertEqual(rservice.queryInterface('Foo.Bar', 42), 42)
        self.failIf(rservice.searchInterface(''))

        wservice.provideInterface('Foo.Bar', I)

        self.assertEqual(rservice.getInterface('Foo.Bar'), I)
        self.assertEqual(rservice.queryInterface('Foo.Bar'), I)
        self.listEq(rservice.searchInterface(''), [I])
        self.listEq(rservice.searchInterface(base=B), [])

        wservice.provideInterface('Foo.Baz', I2)

        result = list(rservice.searchInterface(''))
        result.sort()
        self.assertEqual(result, [I, I2])

        self.listEq(rservice.searchInterface('I2'), [I2])
        self.listEq(rservice.searchInterface('eek'), [I2])

        self.listEq(rservice.searchInterfaceIds('I2'), ['Foo.Baz'])
        self.listEq(rservice.searchInterfaceIds('eek'), ['Foo.Baz'])

        self.listEq(rservice.items("I2"), [("Foo.Baz", I2)])
        self.listEq(rservice.items("eek"), [("Foo.Baz", I2)])

        wservice.provideInterface('Foo.Bus', I3)
        self.listEq(rservice.searchInterface('two'), [I3])
        self.listEq(rservice.searchInterface('two', base=B), [I3])
        self.listEq(rservice.items("two", base=B), [("Foo.Bus", I3)])

        r = list(rservice.searchInterface(base=B))
        r.sort()
        self.assertEqual(r, [I2, I3])


=== Zope3/src/zope/app/component/tests/test_interfaceservice.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/component/tests/test_interfaceservice.py:1.6	Sun Jun 22 14:58:50 2003
+++ Zope3/src/zope/app/component/tests/test_interfaceservice.py	Sun Jun 22 16:17:59 2003
@@ -11,80 +11,26 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+import unittest
+
 from zope.interface import Interface
-from unittest import TestCase, TestSuite, main, makeSuite
-from zope.testing.cleanup import CleanUp
+
 from zope.app.interfaces.component import IGlobalInterfaceService
 from zope.app.component.globalinterfaceservice import InterfaceService
+from zope.app.component.tests.absIInterfaceService \
+     import IInterfaceServiceTests
+
 from zope.interface.verify import verifyObject
-from zope.component.exceptions import ComponentLookupError
 
-class B(Interface):
-    pass
+class Test(IInterfaceServiceTests, unittest.TestCase):
+    """Test Interface for InterfaceService Instance."""
 
-class I(Interface):
-    """bah blah
-    """
-
-class I2(B):
-    """eek
-    """
-
-class I3(B):
-    """
-    """
-    def one():
-        """method one"""
-
-    def two():
-        """method two"""
-
-class Test(CleanUp, TestCase):
-    """Test Interface for InterfaceService Instance.
-    """
+    def getServices(self):
+        s = InterfaceService()
+        return s, s
 
     def testInterfaceVerification(self):
-
         verifyObject(IGlobalInterfaceService, InterfaceService())
 
-    def testInterfaceService(self):
-        service = InterfaceService()
-
-        self.assertRaises(ComponentLookupError,
-                          service.getInterface, 'Foo.Bar')
-        self.assertEqual(service.queryInterface('Foo.Bar'), None)
-        self.assertEqual(service.queryInterface('Foo.Bar', 42), 42)
-        self.failIf(service.searchInterface(''))
-
-        service.provideInterface('Foo.Bar', I)
-
-        self.assertEqual(service.getInterface('Foo.Bar'), I)
-        self.assertEqual(service.queryInterface('Foo.Bar'), I)
-        self.assertEqual(list(service.searchInterface('')), [I])
-        self.assertEqual(list(service.searchInterface(base=B)), [])
-
-        service.provideInterface('Foo.Baz', I2)
-
-        result = list(service.searchInterface(''))
-        result.sort()
-        self.assertEqual(result, [I, I2])
-
-        self.assertEqual(list(service.searchInterface('I2')), [I2])
-        self.assertEqual(list(service.searchInterface('eek')), [I2])
-
-        self.assertEqual(list(service.searchInterfaceIds('I2')), ['Foo.Baz'])
-        self.assertEqual(list(service.searchInterfaceIds('eek')), ['Foo.Baz'])
-
-        service.provideInterface('Foo.Bus', I3)
-        self.assertEqual(list(service.searchInterface('two')), [I3])
-        self.assertEqual(list(service.searchInterface('two', base=B)), [I3])
-
-        r = list(service.searchInterface(base=B))
-        r.sort()
-        self.assertEqual(r, [I2, I3])
-
 def test_suite():
-    return makeSuite(Test)
-
-if __name__=='__main__':
-    main(defaultTest='test_suite')
+    return unittest.makeSuite(Test)