[Checkins] SVN: Zope3/trunk/src/zope/component/ Added some emissing tests.

Jim Fulton jim at zope.com
Mon Jul 31 13:56:36 EDT 2006


Log message for revision 69322:
  Added some emissing tests.
  

Changed:
  U   Zope3/trunk/src/zope/component/registry.py
  U   Zope3/trunk/src/zope/component/registry.txt
  U   Zope3/trunk/src/zope/component/tests.py

-=-
Modified: Zope3/trunk/src/zope/component/registry.py
===================================================================
--- Zope3/trunk/src/zope/component/registry.py	2006-07-31 17:50:15 UTC (rev 69321)
+++ Zope3/trunk/src/zope/component/registry.py	2006-07-31 17:56:35 UTC (rev 69322)
@@ -137,12 +137,10 @@
             raise interfaces.ComponentLookupError(provided, name)
         return utility
 
-    #TODO needs tests
     def getUtilitiesFor(self, interface):
         for name, utility in self.utilities.lookupAll((), interface):
             yield name, utility
 
-    #TODO needs tests
     def getAllUtilitiesRegisteredFor(self, interface):
         return self.utilities.subscriptions((), interface)
 

Modified: Zope3/trunk/src/zope/component/registry.txt
===================================================================
--- Zope3/trunk/src/zope/component/registry.txt	2006-07-31 17:50:15 UTC (rev 69321)
+++ Zope3/trunk/src/zope/component/registry.txt	2006-07-31 17:56:35 UTC (rev 69322)
@@ -166,6 +166,30 @@
     True
     >>> components.queryUtility(tests.I1)
 
+You can get the name and utility for all of the utilities that provide
+an interface using getUtilitiesFor:
+
+    >>> sorted(components.getUtilitiesFor(tests.I2))
+    [(u'', U12(2)), (u'three', U12(3))]
+
+getAllUtilitiesRegisteredFor is similar to getUtilitiesFor except that
+it includes utilities that are overridden.  For example, we'll
+register a utility that for an extending interface of I2:
+
+    >>> components.registerUtility(tests.U('ext'), tests.I2e)
+    Registered event:
+    UtilityRegistration(<Components comps>, I2e, u'', ext, u'')
+
+We don't get the new utility for getUtilitiesFor:
+
+    >>> sorted(components.getUtilitiesFor(tests.I2))
+    [(u'', U12(2)), (u'three', U12(3))]
+
+but we do get it from getAllUtilitiesRegisteredFor:
+
+    >>> sorted(map(str, components.getAllUtilitiesRegisteredFor(tests.I2)))
+    ['U(ext)', 'U12(2)', 'U12(3)']
+
 Adapters
 --------
 

Modified: Zope3/trunk/src/zope/component/tests.py
===================================================================
--- Zope3/trunk/src/zope/component/tests.py	2006-07-31 17:50:15 UTC (rev 69321)
+++ Zope3/trunk/src/zope/component/tests.py	2006-07-31 17:56:35 UTC (rev 69322)
@@ -46,6 +46,8 @@
     pass
 class I2(interface.Interface):
     pass
+class I2e(I2):
+    pass
 class I3(interface.Interface):
     pass
 



More information about the Checkins mailing list