[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture/tests - PlacelessSetup.py:1.2 testInterfaceService.py:1.2
Jim Fulton
jim@zope.com
Tue, 19 Nov 2002 18:15:15 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv10296/tests
Added Files:
PlacelessSetup.py testInterfaceService.py
Log Message:
Merged changes from Zope3-Bangalore-TTW-Branch (Deb and Raju)
Defined an interface service to keep track of and provide query of
known interfaces.
Provided a global interface service implementation.
=== Zope3/lib/python/Zope/App/ComponentArchitecture/tests/PlacelessSetup.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/tests/PlacelessSetup.py Tue Nov 19 18:15:14 2002
@@ -0,0 +1,38 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Unit test logic for setting up and tearing down basic infrastructure
+
+
+$Id$
+"""
+
+from Zope.ComponentArchitecture import getServiceManager
+from Zope.App.ComponentArchitecture.IInterfaceService import IInterfaceService
+from Zope.App.ComponentArchitecture.InterfaceService import interfaceService
+
+
+from Zope.Event.IEventService import IEventService
+from Zope.Event.GlobalEventService import eventService
+from Interface import Interface
+
+class PlacelessSetup:
+
+ def setUp(self):
+
+ sm=getServiceManager(None)
+ defineService=sm.defineService
+ provideService=sm.provideService
+
+ defineService("Interfaces", IInterfaceService)
+ provideService("Interfaces", interfaceService)
=== Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceService.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceService.py Tue Nov 19 18:15:14 2002
@@ -0,0 +1,82 @@
+from Interface import Interface
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.Testing.CleanUp import CleanUp
+from Zope.App.ComponentArchitecture.IGlobalInterfaceService \
+ import IGlobalInterfaceService
+from Zope.App.ComponentArchitecture.InterfaceService import InterfaceService
+from Zope.App.ComponentArchitecture.IInterfaceService import IInterfaceService
+from Interface.Verify import verifyObject
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+from Zope.ComponentArchitecture.GlobalServiceManager \
+ import serviceManager, defineService
+
+
+class I(Interface):
+ """bah blah
+ """
+
+class I2(Interface):
+ """eek
+ """
+
+class I3(Interface):
+ """
+ """
+ def one():
+ """method one"""
+
+ def two():
+ """method two"""
+
+class Test(CleanUp, TestCase):
+ """Test Interface for InterfaceService Instance.
+ """
+
+ 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])
+
+ 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])
+
+def test_suite():
+ return TestSuite((makeSuite(Test),))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
+ self.assertEqual(list(service.searchInterface('two')), [I3])
+
+
+def test_suite():
+ return TestSuite((makeSuite(Test),))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
+