[Checkins] SVN: Sandbox/faassen/iface/src/iface/compatibility. Expand the tests to cover quite a few tests, including multiadaptation.

Martijn Faassen faassen at startifact.com
Sat Jan 9 11:54:56 EST 2010


Log message for revision 107943:
  Expand the tests to cover quite a few tests, including multiadaptation.
  

Changed:
  U   Sandbox/faassen/iface/src/iface/compatibility.py
  U   Sandbox/faassen/iface/src/iface/compatibility.txt

-=-
Modified: Sandbox/faassen/iface/src/iface/compatibility.py
===================================================================
--- Sandbox/faassen/iface/src/iface/compatibility.py	2010-01-09 16:40:23 UTC (rev 107942)
+++ Sandbox/faassen/iface/src/iface/compatibility.py	2010-01-09 16:54:56 UTC (rev 107943)
@@ -15,6 +15,8 @@
 
     def lookup(self, required, provided, name='', default=None):
         required = map(ZopeInterfaceMapKey, required)
-        return self._map[required]
+        try:
+            return self._map[required]
+        except KeyError:
+            return None
     
-    

Modified: Sandbox/faassen/iface/src/iface/compatibility.txt
===================================================================
--- Sandbox/faassen/iface/src/iface/compatibility.txt	2010-01-09 16:40:23 UTC (rev 107942)
+++ Sandbox/faassen/iface/src/iface/compatibility.txt	2010-01-09 16:54:56 UTC (rev 107943)
@@ -9,6 +9,10 @@
 CompatibilityAdapterRegistry provided by iface.
 
   >>> from zope.interface import Interface
+
+Single adaptation
+-----------------
+
   >>> class IA(Interface):
   ...     pass
   >>> class IB(IA):
@@ -24,3 +28,68 @@
   >>> reg.register((IA,), ILookup, '', u'Value for A')
   >>> reg.lookup((IA,), ILookup)
   u'Value for A'
+
+  >>> reg = AdapterRegistry()
+  >>> reg.register((IB,), ILookup, '', u'Value for B')
+  >>> reg.lookup((IB,), ILookup)
+  u'Value for B'
+
+  >>> print reg.lookup((IC,), ILookup)
+  None
+
+  >>> print reg.lookup((IA,), ILookup)
+  None
+
+  >>> reg.lookup((ID,), ILookup)
+  u'Value for B'
+
+  >>> reg.register((IC,), ILookup, '', u'Value for C')
+  >>> reg.lookup((ID,), ILookup)
+  u'Value for B'
+
+Multi adaptation
+----------------
+
+  >>> class IAlpha(Interface):
+  ...    pass
+  >>> class IBeta(IAlpha):
+  ...    pass
+  >>> class IGamma(IBeta):
+  ...    pass
+
+  >>> class IOne(Interface):
+  ...    pass
+  >>> class ITwo(IOne):
+  ...    pass
+  >>> class IThree(ITwo):
+  ...    pass
+
+  >>> reg = AdapterRegistry()
+  >>> reg.register((IAlpha, IThree), ILookup, '', u'Value for alpha, three')
+  >>> reg.register((IBeta, ITwo), ILookup, '', u'Value for beta, two')
+  >>> reg.lookup((IAlpha, IThree), ILookup)
+  u'Value for alpha, three'
+  >>> reg.lookup((IBeta, ITwo), ILookup)
+  u'Value for beta, two'
+  >>> reg.lookup((IGamma, ITwo), ILookup)
+  u'Value for beta, two'
+  >>> reg.lookup((IBeta, IThree), ILookup)
+  u'Value for beta, two'
+  >>> reg.lookup((IGamma, IThree), ILookup)
+  u'Value for beta, two'
+  >>> print reg.lookup((IAlpha, IOne), ILookup)
+  None
+  >>> print reg.lookup((IAlpha, ITwo), ILookup)
+  None
+  >>> print reg.lookup((IBeta, IOne), ILookup)
+  None
+  
+  >>> reg.register((IAlpha, IOne), ILookup, '', u'Value for alpha, one')
+  >>> reg.lookup((IAlpha, IOne), ILookup)
+  u'Value for alpha, one'
+  >>> reg.lookup((IAlpha, ITwo), ILookup)
+  u'Value for alpha, one'
+  >>> reg.lookup((IBeta, IOne), ILookup)
+  u'Value for alpha, one'
+
+



More information about the checkins mailing list