[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/adapters.txt Add a plain simple test for adapter registration.

Uli Fouquet uli at gnufix.de
Sat Jun 21 18:09:20 EDT 2008


Log message for revision 87641:
  Add a plain simple test for adapter registration.

Changed:
  A   zope.introspector/trunk/src/zope/introspector/adapters.txt

-=-
Added: zope.introspector/trunk/src/zope/introspector/adapters.txt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/adapters.txt	                        (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/adapters.txt	2008-06-21 22:09:19 UTC (rev 87641)
@@ -0,0 +1,45 @@
+zope.introspector.adapters
+**************************
+
+:Test-Layer: functional
+
+Adapters to find utilities, handlers and adapters.
+
+We provide some adapters, to adapt different types of registrations to
+our local IRegistrySearch type.
+
+We create a simple fake registration::
+
+  >>> class FakeRegistration(object):
+  ...   pass
+  >>> fake_reg = FakeRegistration()
+
+We let this `fake_reg` now provide ``IAdapterRegistration`` to let the
+framework think, it is a real adapter registration::
+
+  >>> from zope.interface import directlyProvides
+  >>> from zope.component.interfaces import IAdapterRegistration
+  >>> directlyProvides(fake_reg, IAdapterRegistration)
+
+When we ask for an adapter to our own IRegistrySearch, we get an
+``AdapterSearch``::
+
+  >>> from zope.introspector.interfaces import IRegistrySearch
+  >>> IRegistrySearch(fake_reg)
+  <zope.introspector.adapters.AdapterSearch object at 0x...>
+
+The same works with handler registrations. We attach the interface
+using ``directlyProvides`` to remove any other interfaces from the
+fake registry::
+
+  >>> from zope.component.interfaces import IHandlerRegistration
+  >>> directlyProvides(fake_reg, IHandlerRegistration)
+  >>> IRegistrySearch(fake_reg)
+  <zope.introspector.adapters.HandlerSearch object at 0x...>
+
+Finally we have also an adapter for utility registrations::
+
+  >>> from zope.component.interfaces import IUtilityRegistration
+  >>> directlyProvides(fake_reg, IUtilityRegistration)
+  >>> IRegistrySearch(fake_reg)
+  <zope.introspector.adapters.UtilitySearch object at 0x...>



More information about the Checkins mailing list