[Zope3-checkins] CVS: Zope3/lib/python/Interface/Registry/tests - TestIAdapterRegistry.py:1.2.8.2
Jim Fulton
jim@zope.com
Wed, 16 Oct 2002 04:35:36 -0400
Update of /cvs-repository/Zope3/lib/python/Interface/Registry/tests
In directory cvs.zope.org:/tmp/cvs-serv11955/lib/python/Interface/Registry/tests
Modified Files:
Tag: Zope3-Bangalore-TTW-Branch
TestIAdapterRegistry.py
Log Message:
- Added a filter option to get and getForObject. This will be
needed for placeful adapter service implementations.
- Added tests for getForObject.
- Fixed a logic error in get.
=== Zope3/lib/python/Interface/Registry/tests/TestIAdapterRegistry.py 1.2.8.1 => 1.2.8.2 ===
--- Zope3/lib/python/Interface/Registry/tests/TestIAdapterRegistry.py:1.2.8.1 Tue Oct 15 10:41:30 2002
+++ Zope3/lib/python/Interface/Registry/tests/TestIAdapterRegistry.py Wed Oct 16 04:35:35 2002
@@ -74,6 +74,66 @@
for P in [P1, P2, P3]:
self.assertEqual(registry.get((None, P)), 'default P3')
+ def test_getForObject(self):
+ registry = self.__registery()
+
+ class C: pass
+ c = C()
+
+ for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
+ c.__implements__ = R
+ for P in [P1, P2, P3]:
+ self.assertEqual(registry.getForObject(c, P), 'R2 P3')
+
+ for R in [None, R1, R2, R3, R4, (R12, R2), (R12, R4)]:
+ c.__implements__ = R
+ self.assertEqual(registry.getForObject(c, None), None)
+
+ c.__implements__ = R1
+ for P in [P1, P2, P3]:
+ self.assertEqual(registry.getForObject(c, P), 'any P3')
+
+ c = C()
+ for P in [P1, P2, P3]:
+ self.assertEqual(registry.getForObject(c, P), 'default P3')
+
+ def test_get_w_filter(self):
+ registry = self.__registery()
+
+ for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
+ for P in [P1, P2, P3]:
+ self.assertEqual(
+ registry.get((R, P), filter=lambda o: o.startswith('a')),
+ 'any P3')
+ self.assertEqual(
+ registry.get((R, P), filter=lambda o: o.startswith('d')),
+ 'default P3')
+ self.assertEqual(
+ registry.get((R, P), filter=lambda o: o.startswith('z')),
+ None)
+
+ def test_getForObject_w_filter(self):
+ registry = self.__registery()
+
+ class C: pass
+ c = C()
+
+ for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
+ c.__implements__ = R
+ for P in [P1, P2, P3]:
+ self.assertEqual(
+ registry.getForObject(c, P,
+ filter=lambda o: o.startswith('a')),
+ 'any P3')
+ self.assertEqual(
+ registry.getForObject(c, P,
+ filter=lambda o: o.startswith('d')),
+ 'default P3')
+ self.assertEqual(
+ registry.getForObject(c, P,
+ filter=lambda o: o.startswith('z')),
+ None)
+
def test_getRegistered(self):
registry = self.__registery()