[Checkins] SVN: z3c.componentdebug/trunk/src/z3c/componentdebug/
Add tests for the site manager iteration
Ross Patterson
me at rpatterson.net
Wed May 30 22:40:46 EDT 2007
Log message for revision 76031:
Add tests for the site manager iteration
Changed:
U z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
U z3c.componentdebug/trunk/src/z3c/componentdebug/component.py
A z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt
U z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py
-=-
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt 2007-05-31 02:25:37 UTC (rev 76030)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt 2007-05-31 02:40:43 UTC (rev 76031)
@@ -23,26 +23,23 @@
Component Inspection
--------------------
-A set of interfaces are needed to demonstrate the inspection
-functions::
-
- >>> from zope.interface import Interface
- >>> class IFoo(Interface): pass
- >>> class IBar(Interface): pass
- >>> class IBaz(Interface): pass
-
z3c.componentdebug.inspect provides inspection of registrations that
-provide a specific interface. Unlike
-zope.app.apidoc.getRequiredAdapters, however, it takes a list of
-objects to adapt and for each object reports which registrations
+provide a specific interface. Unlike zope.app.apidoc, it takes a list
+of objects to adapt and for each object reports which registrations
require an interface provided by that object for the correct position
-in the list of objects.
+in the list of objects. Also unlike zope.app.apidoc, it examines the
+contents of all site managers in the resolution order.
Registrations are sorted first by the number of objects that match and
then by the specificity of the required interfaces.
Start with some objects that provide some interfaces::
+ >>> from zope.interface import Interface
+ >>> class IFoo(Interface): pass
+ >>> class IBar(Interface): pass
+ >>> class IBaz(Interface): pass
+
>>> from zope.interface import alsoProvides
>>> class Foo(object): pass
>>> foo = Foo()
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/component.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/component.py 2007-05-31 02:25:37 UTC (rev 76030)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/component.py 2007-05-31 02:40:43 UTC (rev 76031)
@@ -17,7 +17,7 @@
yield sm
sm = queryNextSiteManager(sm, _marker)
-def getRegistrations(methods, context=None):
+def getRegistrations(methods=all_methods, context=None):
for sm in getSiteManagers(context):
for method in methods:
for reg in getattr(sm, method)():
Added: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt (rev 0)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/site.txt 2007-05-31 02:40:43 UTC (rev 76031)
@@ -0,0 +1,28 @@
+;-*-Doctest-*-
+=============
+Site Managers
+=============
+
+z3c.componentdebug examines the registrations of all site managers in
+the resolution order::
+
+ >>> from zope.component import getSiteManager
+ >>> from zope.component.persistentregistry import (
+ ... PersistentComponents,)
+ >>> gsm = getSiteManager()
+ >>> sm = PersistentComponents(bases=(gsm,))
+
+ >>> from pprint import pprint
+ >>> from z3c.componentdebug.component import getSiteManagers
+ >>> pprint([i for i in getSiteManagers(sm)])
+ [<PersistentComponents >, <BaseGlobalComponents base>]
+
+ >>> from zope.interface import Interface
+ >>> from z3c.componentdebug.component import getRegistrations
+ >>> gsm.registerUtility(object, Interface)
+ >>> sm.registerUtility(object, Interface)
+ >>> pprint([i for i in getRegistrations(context=sm)])
+ [UtilityRegistration(<PersistentComponents >, Interface, u'',
+ object, u''),
+ UtilityRegistration(<BaseGlobalComponents base>, Interface, u'',
+ object, u'')]
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py 2007-05-31 02:25:37 UTC (rev 76030)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/tests.py 2007-05-31 02:40:43 UTC (rev 76031)
@@ -3,6 +3,7 @@
def test_suite():
suite = doctest.DocFileSuite(
+ 'site.txt',
'../README.txt',
'component.txt',
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
More information about the Checkins
mailing list