[Zope3-checkins] SVN: Zope3/branches/3.3/src/zope/component/ Added som emissing tests.

Jim Fulton jim at zope.com
Mon Jul 31 13:50:15 EDT 2006


Log message for revision 69321:
  Added som emissing tests.
  

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

-=-
Modified: Zope3/branches/3.3/src/zope/component/registry.py
===================================================================
--- Zope3/branches/3.3/src/zope/component/registry.py	2006-07-31 17:27:52 UTC (rev 69320)
+++ Zope3/branches/3.3/src/zope/component/registry.py	2006-07-31 17:50:15 UTC (rev 69321)
@@ -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/branches/3.3/src/zope/component/registry.txt
===================================================================
--- Zope3/branches/3.3/src/zope/component/registry.txt	2006-07-31 17:27:52 UTC (rev 69320)
+++ Zope3/branches/3.3/src/zope/component/registry.txt	2006-07-31 17:50:15 UTC (rev 69321)
@@ -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/branches/3.3/src/zope/component/tests.py
===================================================================
--- Zope3/branches/3.3/src/zope/component/tests.py	2006-07-31 17:27:52 UTC (rev 69320)
+++ Zope3/branches/3.3/src/zope/component/tests.py	2006-07-31 17:50:15 UTC (rev 69321)
@@ -46,6 +46,8 @@
     pass
 class I2(interface.Interface):
     pass
+class I2e(I2):
+    pass
 class I3(interface.Interface):
     pass
 



More information about the Zope3-Checkins mailing list