[Checkins] SVN: Sandbox/faassen/iface/src/iface/ Set up some tests to explore compatibility with zope.interface,
Martijn Faassen
faassen at startifact.com
Sat Jan 9 11:40:23 EST 2010
Log message for revision 107942:
Set up some tests to explore compatibility with zope.interface,
in particular the AdapterRegistry.
Right now we don't test very much yet.
Changed:
A Sandbox/faassen/iface/src/iface/compatibility.py
A Sandbox/faassen/iface/src/iface/compatibility.txt
U Sandbox/faassen/iface/src/iface/tests.py
-=-
Added: Sandbox/faassen/iface/src/iface/compatibility.py
===================================================================
--- Sandbox/faassen/iface/src/iface/compatibility.py (rev 0)
+++ Sandbox/faassen/iface/src/iface/compatibility.py 2010-01-09 16:40:23 UTC (rev 107942)
@@ -0,0 +1,20 @@
+from iface import MapKey, MultiMap
+
+class ZopeInterfaceMapKey(MapKey):
+ def __init__(self, interface):
+ super(ZopeInterfaceMapKey, self).__init__(
+ interface, map(ZopeInterfaceMapKey, interface.__bases__))
+
+class CompatibilityAdapterRegistry(object):
+ def __init__(self):
+ self._map = MultiMap()
+
+ def register(self, required, provided, name, value):
+ required = map(ZopeInterfaceMapKey, required)
+ self._map[required] = value
+
+ def lookup(self, required, provided, name='', default=None):
+ required = map(ZopeInterfaceMapKey, required)
+ return self._map[required]
+
+
Added: Sandbox/faassen/iface/src/iface/compatibility.txt
===================================================================
--- Sandbox/faassen/iface/src/iface/compatibility.txt (rev 0)
+++ Sandbox/faassen/iface/src/iface/compatibility.txt 2010-01-09 16:40:23 UTC (rev 107942)
@@ -0,0 +1,26 @@
+Compatibility with zope.interface
+=================================
+
+The goal of iface to be behavior-compatible with zope.interface and
+zope.component. We also intend to eventually provide support for
+zope.interface. We test the backwards compatibility here. The idea is
+that this test is run twice, once with the AdapterRegistry from
+zope.interface, and once with the compatible
+CompatibilityAdapterRegistry provided by iface.
+
+ >>> from zope.interface import Interface
+ >>> class IA(Interface):
+ ... pass
+ >>> class IB(IA):
+ ... pass
+ >>> class IC(IA):
+ ... pass
+ >>> class ID(IB, IC):
+ ... pass
+ >>> class ILookup(Interface):
+ ... "A simple interface to look up"
+
+ >>> reg = AdapterRegistry()
+ >>> reg.register((IA,), ILookup, '', u'Value for A')
+ >>> reg.lookup((IA,), ILookup)
+ u'Value for A'
Modified: Sandbox/faassen/iface/src/iface/tests.py
===================================================================
--- Sandbox/faassen/iface/src/iface/tests.py 2010-01-09 16:15:54 UTC (rev 107941)
+++ Sandbox/faassen/iface/src/iface/tests.py 2010-01-09 16:40:23 UTC (rev 107942)
@@ -1,12 +1,26 @@
import unittest, doctest
+from zope.interface.adapter import AdapterRegistry
+from iface.compatibility import CompatibilityAdapterRegistry
+
def test_suite():
suite = unittest.TestSuite()
optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
suite.addTests([
- doctest.DocFileSuite('mapping.txt',
- optionflags=optionflags)])
+ doctest.DocFileSuite(
+ 'mapping.txt',
+ optionflags=optionflags),
+ doctest.DocFileSuite(
+ 'compatibility.txt',
+ optionflags=optionflags,
+ globs=dict(AdapterRegistry=AdapterRegistry)),
+ doctest.DocFileSuite(
+ 'compatibility.txt',
+ optionflags=optionflags,
+ globs=dict(AdapterRegistry=CompatibilityAdapterRegistry)),
+ ])
+
return suite
More information about the checkins
mailing list