[Checkins]
SVN: zope.introspector/trunk/src/zope/introspector/adapters.txt
Added more tests for search adapters
Martin Lundwall
martin at webworks.se
Sun Jun 22 17:54:03 EDT 2008
Log message for revision 87659:
Added more tests for search adapters
Changed:
U zope.introspector/trunk/src/zope/introspector/adapters.txt
-=-
Modified: zope.introspector/trunk/src/zope/introspector/adapters.txt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/adapters.txt 2008-06-22 21:05:01 UTC (rev 87658)
+++ zope.introspector/trunk/src/zope/introspector/adapters.txt 2008-06-22 21:54:01 UTC (rev 87659)
@@ -3,17 +3,30 @@
:Test-Layer: functional
-Adapters to find utilities, handlers and adapters.
+Adapters to search 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::
+We create a simple fake registration, for this registration to behave normally we also need some
+fake interfaces a FakeProvided, FakeRequired and a FakeFactory::
+ >>> class FakeProvided:
+ ... pass
+ >>> class FakeRequired:
+ ... pass
+ >>> class FakeFactory:
+ ... pass
>>> class FakeRegistration(object):
- ... pass
+ ... provided = FakeProvided
+ ... name = "FakeName"
+ ... factory = FakeFactory
+ ... required = [FakeRequired]
>>> fake_reg = FakeRegistration()
+In the Component Registry there are four different types of registrations, ``IAdapterRegistration``,
+ ``IHandlerRegistration`` and ``IUtilityRegistration``. The fourth``ISubscriptionAdapterRegistration``
+ is just a sub-class of ``IAdapterRegistration`` and does not add anything to ``IAdapterRegistration``.
We let this `fake_reg` now provide ``IAdapterRegistration`` to let the
framework think, it is a real adapter registration::
@@ -21,25 +34,70 @@
>>> from zope.component.interfaces import IAdapterRegistration
>>> directlyProvides(fake_reg, IAdapterRegistration)
-When we ask for an adapter to our own IRegistrySearch, we get an
-``AdapterSearch``::
+We can now get an ``AdapterSearch`` from the IRegistrySearch, that we can use to search the registration
+and see if this registration has anything with that name.
+::
>>> from zope.introspector.interfaces import IRegistrySearch
- >>> IRegistrySearch(fake_reg)
- <zope.introspector.adapters.AdapterSearch object at 0x...>
+ >>> adapterSearch = IRegistrySearch(fake_reg)
+ >>> adapterSearch.searchRegistration("FakeName")
+ True
+
+ >>> adapterSearch.searchRegistration("FakeProvided")
+ True
+
+ >>> adapterSearch.searchRegistration("FakeFactory")
+ True
+We can also get the full paths of the involved interfaces::
+
+ >>> adapterSearch.getInterfaces()
+ ['__builtin__.FakeRequired', '__builtin__.FakeProvided']
+
+And if we want get the registration itself::
+
+ >>> adapterSearch.getObject()
+ <FakeRegistration 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...>
-
+ >>> handlerSearch = IRegistrySearch(fake_reg)
+ >>> handlerSearch.searchRegistration("FakeName")
+ True
+
+ >>> handlerSearch.searchRegistration("FakeFactory")
+ True
+
+ >>> handlerSearch.searchRegistration("FakeRequired")
+ True
+
+ >>> handlerSearch.getInterfaces()
+ ['__builtin__.FakeRequired', '__builtin__.FakeFactory']
+
+ >>> handlerSearch.getObject()
+ <FakeRegistration 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...>
+ >>> utilitySearch = IRegistrySearch(fake_reg)
+ >>> utilitySearch.searchRegistration("FakeName")
+ True
+
+ >>> utilitySearch.searchRegistration("FakeProvided")
+ True
+
+ >>> utilitySearch.getInterfaces()
+ ['__builtin__.FakeProvided']
+
+ >>> utilitySearch.getObject()
+ <FakeRegistration object at 0x...>
+
+
+
\ No newline at end of file
More information about the Checkins
mailing list