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

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Jan 29 12:36:50 EST 2004


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

Modified Files:
	test_utilityservice.py 
Log Message:
Fixed a bug and added a test for UtilityService.getRegisteredMatching().

Reimplemented getRegisteredMatching() for the PresentationService. It is 
not part of the API yet, but we should do that!

As far as I can tell, the zope.component package is in a bad shape due to 
some refactorings. There are missing documentation strings everywhere and 
there are many legacy methods hanging around.


=== Zope3/src/zope/component/tests/test_utilityservice.py 1.8 => 1.9 ===
--- Zope3/src/zope/component/tests/test_utilityservice.py:1.8	Fri Dec 19 11:53:21 2003
+++ Zope3/src/zope/component/tests/test_utilityservice.py	Thu Jan 29 12:36:50 2004
@@ -11,9 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""test utility service
-
-XXX longer description goes here.
+"""Utility service tests
 
 $Id$
 """
@@ -27,13 +25,20 @@
 
 from zope.testing.cleanup import CleanUp # Base class w registry cleanup
 
-class IDummyService(Interface):
+class IDummyUtility(Interface):
     pass
 
-class DummyService:
-    implements(IDummyService)
+class DummyUtility:
+    implements(IDummyUtility)
+
+class DummyUtility2:
+    implements(IDummyUtility)
+
+    def __len__(self):
+        return 0
 
-dummyService = DummyService()
+dummyUtility = DummyUtility()
+dummyUtility2 = DummyUtility2()
 
 class Test(TestCase, CleanUp):
     def setUp(self):
@@ -49,40 +54,48 @@
     def testGetUtility(self):
         us = getService(None, Utilities)
         self.assertRaises(
-            ComponentLookupError, getUtility, None, IDummyService)
-        us.provideUtility(IDummyService, dummyService)
-        self.assertEqual(getUtility(None, IDummyService), dummyService)
+            ComponentLookupError, getUtility, None, IDummyUtility)
+        us.provideUtility(IDummyUtility, dummyUtility)
+        self.assertEqual(getUtility(None, IDummyUtility), dummyUtility)
 
     def testQueryUtility(self):
         us = getService(None, Utilities)
-        self.assertEqual(queryUtility(None, IDummyService), None)
-        self.assertEqual(queryUtility(None, IDummyService, self), self)
-        us.provideUtility(IDummyService, dummyService)
-        self.assertEqual(queryUtility(None, IDummyService), dummyService)
+        self.assertEqual(queryUtility(None, IDummyUtility), None)
+        self.assertEqual(queryUtility(None, IDummyUtility, self), self)
+        us.provideUtility(IDummyUtility, dummyUtility)
+        self.assertEqual(queryUtility(None, IDummyUtility), dummyUtility)
 
     def testgetUtilitiesFor(self):
         us = getService(None, Utilities)
-        us.provideUtility(IDummyService, dummyService)
-        conns = getUtilitiesFor(None, IDummyService)
-        self.assertEqual(getUtilitiesFor(None, IDummyService),
-                         [('',dummyService)])
+        us.provideUtility(IDummyUtility, dummyUtility)
+        conns = getUtilitiesFor(None, IDummyUtility)
+        self.assertEqual(getUtilitiesFor(None, IDummyUtility),
+                         [('',dummyUtility)])
         
     def testRegisteredMatching(self):
         us = getService(None, Utilities)
-        self.assertEqual(queryUtility(None, IDummyService), None)
-        self.assertEqual(queryUtility(None, IDummyService, self), self)
-        us.provideUtility(IDummyService, dummyService)
-        self.assertEqual(us.getRegisteredMatching(IDummyService),
-                         [(IDummyService, '', dummyService)])
+        self.assertEqual(queryUtility(None, IDummyUtility), None)
+        self.assertEqual(queryUtility(None, IDummyUtility, self), self)
+        us.provideUtility(IDummyUtility, dummyUtility)
+        self.assertEqual(us.getRegisteredMatching(IDummyUtility),
+                         [(IDummyUtility, '', dummyUtility)])
 
     def testRegisteredMatchingWithName(self):
         us = getService(None, Utilities)
-        self.assertEqual(queryUtility(None, IDummyService), None)
-        self.assertEqual(queryUtility(None, IDummyService, self), self)
-        us.provideUtility(IDummyService, dummyService, 'a dummy service')
-        self.assertEqual(us.getRegisteredMatching(IDummyService, 'dummy'),
-                         [(IDummyService, 'a dummy service', dummyService)])
-        self.assertEqual(us.getRegisteredMatching(IDummyService, 'stupid'),
+        self.assertEqual(queryUtility(None, IDummyUtility), None)
+        self.assertEqual(queryUtility(None, IDummyUtility, self), self)
+        us.provideUtility(IDummyUtility, dummyUtility, 'dummy')
+        us.provideUtility(IDummyUtility, dummyUtility2, 'another')
+        self.assertEqual(us.getRegisteredMatching(IDummyUtility, 'dummy'),
+                         [(IDummyUtility, 'dummy', dummyUtility)])
+        self.assertEqual(us.getRegisteredMatching(IDummyUtility, 'another'),
+                         [(IDummyUtility, 'another', dummyUtility2)])
+        res = us.getRegisteredMatching(IDummyUtility)
+        res.sort()
+        self.assertEqual(res,
+                         [(IDummyUtility, 'another', dummyUtility2),
+                          (IDummyUtility, 'dummy',   dummyUtility )])
+        self.assertEqual(us.getRegisteredMatching(IDummyUtility, 'stupid'),
                          [])
 
 def test_suite():




More information about the Zope3-Checkins mailing list