[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/registry.txt Update tests to check for finding of local utilities.

Uli Fouquet uli at gnufix.de
Thu Jul 10 06:57:53 EDT 2008


Log message for revision 88164:
  Update tests to check for finding of local utilities.

Changed:
  U   zope.introspector/trunk/src/zope/introspector/registry.txt

-=-
Modified: zope.introspector/trunk/src/zope/introspector/registry.txt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/registry.txt	2008-07-10 10:55:39 UTC (rev 88163)
+++ zope.introspector/trunk/src/zope/introspector/registry.txt	2008-07-10 10:57:53 UTC (rev 88164)
@@ -3,42 +3,46 @@
 
 :Test-Layer: functional
 
-zope.interface provides the ``RegistryInfoUtility`` to search for and list all registered Utilities, 
-Adapters, Handlers and SubscriptionAdapters. To list all registered Utilities::
+zope.interface provides the ``RegistryInfoUtility`` to search for and
+list all registered Utilities, Adapters, Handlers and
+SubscriptionAdapters. To list all registered Utilities::
 
   >>> from zope.introspector.interfaces import IRegistryInfo
   >>> from zope.component import getUtility
-  >>> registryUtil = getUtility(IRegistryInfo)
-  >>> registryUtil.getAllUtilities()
+  >>> registry_util = getUtility(IRegistryInfo)
+  >>> registry_util.getAllUtilities()
   [UtilityRegistration...]
   
 The same thing can be done for Adapters::
 
-  >>> registryUtil.getAllAdapters()
+  >>> registry_util.getAllAdapters()
   [AdapterRegistration...]
   
-  >>> registryUtil.getAllAdapters(registry='test')
+  >>> registry_util.getAllAdapters(registry='test')
   []
 
 For Handlers::
 
-  >>> registryUtil.getAllHandlers()
+  >>> registry_util.getAllHandlers()
   [HandlerRegistration...]
   
 And for SubscriptionAdapters::
 
-  >>> registryUtil.getAllSubscriptionAdapters()
+  >>> registry_util.getAllSubscriptionAdapters()
   [...]
 
 So far this has been empty.
 Or you can get all registrations::
 
-  >>> registryUtil.getAllRegistrations()
+  >>> registry_util.getAllRegistrations()
   [AdapterRegistration...]
 
-However if you are looking for something special you can do a search in the registry to see if it registered.
-So first we will create a Dummy utility so we have something to find when we search::
+However if you are looking for something special you can do a search
+in the registry to see if it registered.
 
+So first we will create a dummy utility so we have something to find
+when we search::
+
   >>> from zope.interface import Interface, implements
   >>> from zope.component import provideUtility
   >>> class IDummy(Interface):
@@ -52,18 +56,68 @@
 
 And use the RegistryInfoUtility to search for it::
 
-  >>> registryUtil.getRegistrationsForInterface("Dummy")
-  [UtilityRegistration(<BaseGlobalComponents base>, IDummy, u'', Dummy, u'')...]
-  
-Depending on what type of Registration that is searched different things are examined.    
-Utilites you can search for either name of utility or provided interface.
-Adapters you can search for name, provided interfaces, factory or required interfaces.
-Handlers you can search for name, factory, or required interfaces.
+  >>> registry_util.getRegistrationsForInterface("Dummy")
+  [UtilityRegistration(<BaseGlobalComponents base>, 
+  ...IDummy, u'', Dummy, u'')...]
 
-There is also a way to get all registrations in a dictionary ordered by package name. 
+Also local utilities can be found. We create a site, where we can
+register local components::
 
-  >>> registryUtil.getAllInterfaces()
+  >>> from zope.app.folder import folder
+  >>> local_site1 = folder.rootFolder()
+  >>> getRootFolder()['local_site'] = local_site1
+
+  >>> from zope.app.component import site
+  >>> sm = site.LocalSiteManager(local_site1)
+  >>> local_site1.setSiteManager(sm)
+
+We register a utility in this site, this time a named one::
+
+  >>> local_utility1 = Dummy()
+  >>> sm.registerUtility(Dummy, IDummy, 'local_u1')
+
+As a last step, we create a placeful object, that we put into this
+site::
+
+  >>> class Mammoth(object):
+  ...   pass
+
+  >>> fred = Mammoth()
+  >>> local_site1['fred'] = fred
+  >>> fred.__parent__ = local_site1
+
+The utility is available, if we ask the local site manager directly::
+
+  >>> sm.queryUtility(IDummy, 'local_u1')
+  <class 'Dummy'>
+
+If we now ask for utilities, that are available to `fred`, we get also
+the local utilitiy::
+
+  >>> from pprint import pprint
+  >>> pprint(sorted([(x.registry, x.name, x.component, x.provided)
+  ...         for x in registry_util.getAllUtilities(context=fred)
+  ...         if 'Dummy' in str(x.component)]))
+  [(<BaseGlobalComponents base>,
+    u'',
+    <class 'Dummy'>,
+    <InterfaceClass __builtin__.IDummy>),
+   (<LocalSiteManager ++etc++site>,
+    'local_u1',
+    <class 'Dummy'>,
+    <InterfaceClass __builtin__.IDummy>)]
+
+Depending on what type of registration that is searched different
+things are examined.  Utilites you can search for either name of
+utility or provided interface.  Adapters you can search for name,
+provided interfaces, factory or required interfaces.  Handlers you can
+search for name, factory, or required interfaces.
+
+There is also a way to get all registrations in a dictionary ordered
+by package name.
+
+  >>> registry_util.getAllInterfaces()
   {...: {...: {...: {...: [...Registration...]}...}...}...}
 
-This is mainly useful for browsing the complete component registry if you are not 
-really sure what you are looking for.  
\ No newline at end of file
+This is mainly useful for browsing the complete component registry if
+you are not really sure what you are looking for.



More information about the Checkins mailing list