[Zope3-checkins] CVS: Zope3/src/zope/component/tests - test_utilityservice.py:1.10

Jim Fulton jim at zope.com
Sun Apr 11 14:16:44 EDT 2004


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

Modified Files:
	test_utilityservice.py 
Log Message:
Reimplemented the global utility service using adapter registries.

Added a registrations method.


=== Zope3/src/zope/component/tests/test_utilityservice.py 1.9 => 1.10 ===
--- Zope3/src/zope/component/tests/test_utilityservice.py:1.9	Thu Jan 29 12:36:50 2004
+++ Zope3/src/zope/component/tests/test_utilityservice.py	Sun Apr 11 14:16:43 2004
@@ -18,7 +18,8 @@
 
 from unittest import TestCase, main, makeSuite
 from zope.component import \
-     getUtility, getUtilitiesFor, getService, queryUtility, getServiceManager
+     getUtility, getUtilitiesFor, getService, queryUtility, \
+     getServiceManager, getUtilitiesFor
 from zope.component.exceptions import ComponentLookupError
 from zope.component.servicenames import Utilities
 from zope.interface import Interface, implements
@@ -29,10 +30,12 @@
     pass
 
 class DummyUtility:
+    __name__ = 'DummyUtility'
     implements(IDummyUtility)
 
 class DummyUtility2:
     implements(IDummyUtility)
+    __name__ = 'DummyUtility2'
 
     def __len__(self):
         return 0
@@ -41,6 +44,7 @@
 dummyUtility2 = DummyUtility2()
 
 class Test(TestCase, CleanUp):
+
     def setUp(self):
         CleanUp.setUp(self)
         sm=getServiceManager(None)
@@ -48,8 +52,8 @@
         provideService=sm.provideService
         from zope.component.interfaces import IUtilityService
         defineService('Utilities',IUtilityService)
-        from zope.component.utility import utilityService
-        provideService('Utilities', utilityService)
+        from zope.component.utility import GlobalUtilityService
+        provideService('Utilities', GlobalUtilityService())
 
     def testGetUtility(self):
         us = getService(None, Utilities)
@@ -68,9 +72,17 @@
     def testgetUtilitiesFor(self):
         us = getService(None, Utilities)
         us.provideUtility(IDummyUtility, dummyUtility)
-        conns = getUtilitiesFor(None, IDummyUtility)
-        self.assertEqual(getUtilitiesFor(None, IDummyUtility),
+        self.assertEqual(list(getUtilitiesFor(None, IDummyUtility)),
+                         [('',dummyUtility)])
+        self.assertEqual(list(us.getUtilitiesFor(IDummyUtility)),
                          [('',dummyUtility)])
+
+    def testregistrations(self):
+        us = getService(None, Utilities)
+        us.provideUtility(IDummyUtility, dummyUtility)
+        self.assertEqual(
+            map(str, us.registrations()),
+            ["UtilityRegistration('IDummyUtility', '', 'DummyUtility', '')"])
         
     def testRegisteredMatching(self):
         us = getService(None, Utilities)




More information about the Zope3-Checkins mailing list