[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_adapter.py:1.12

Jim Fulton jim@zope.com
Wed, 21 May 2003 16:30:37 -0400


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv22750/src/zope/app/services/tests

Modified Files:
	test_adapter.py 
Log Message:
Changed the API for handling named adapters.  There is
now a separate cleaner api for getting named adapters.

Also added support for the PEP 246 __conform__ method.



=== Zope3/src/zope/app/services/tests/test_adapter.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/services/tests/test_adapter.py:1.11	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_adapter.py	Wed May 21 16:30:05 2003
@@ -87,6 +87,27 @@
     def createTestingConfiguration(self):
         return Configuration()
 
+    def test_conforms(self):
+        service = self._service
+        class Conforms:
+            def __conform__(self, i):
+                if i is I1:
+                    return A(self)
+
+        o = Conforms()
+        self.assertEqual(service.queryAdapter(o, I2), None)
+        self.assertRaises(ComponentLookupError, service.getAdapter, o, I2)
+        self.assertEqual(service.queryAdapter(Conforms, I2), None)
+        self.assertEqual(service.queryAdapter(Conforms, I1), None)
+
+        a = service.queryAdapter(o, I1)
+        self.assertEqual(a.__class__, A)
+        self.assertEqual(a.context, o)
+
+        a = service.getAdapter(o, I1)
+        self.assertEqual(a.__class__, A)
+        self.assertEqual(a.context, o)
+
     def test_queryAdapter_no_adapter(self):
         service = self._service
         class O:
@@ -173,11 +194,11 @@
                 o = O()
                 directlyProvides(o, r)
 
-                adapter = service.getAdapter(o, p, u"Yatta!")
+                adapter = service.getNamedAdapter(o, p, u"Yatta!")
                 self.assertEqual(adapter.__class__, A)
                 self.assertEqual(adapter.context, o)
 
-        self.assertRaises(ComponentLookupError, service.getAdapter,
+        self.assertRaises(ComponentLookupError, service.getNamedAdapter,
                           o, I1, u"Yatta!")
 
         for r in I1, I1E:
@@ -185,16 +206,16 @@
                 o = O()
                 directlyProvides(o, r)
 
-                adapter = service.queryAdapter(o, p, None, u"Yatta!")
+                adapter = service.queryNamedAdapter(o, p, u"Yatta!")
                 self.assertEqual(adapter.__class__, A)
                 self.assertEqual(adapter.context, o)
 
-        self.assertEqual(service.queryAdapter(o, I1, None, u"Yatta!"), None)
+        self.assertEqual(service.queryNamedAdapter(o, I1, u"Yatta!"), None)
 
-        self.assertRaises(ComponentLookupError, service.getAdapter,
+        self.assertRaises(ComponentLookupError, service.getNamedAdapter,
                           O(), I3, "Yatta!")
-        self.assertEqual(service.queryAdapter(o, I3, name=u"Yatta!"), None)
-        self.assertEqual(service.queryAdapter(o, I3, 42, u"Yatta!"), 42)
+        self.assertEqual(service.queryNamedAdapter(o, I3, u"Yatta!"), None)
+        self.assertEqual(service.queryNamedAdapter(o, I3, u"Yatta!", 42), 42)
 
     def test_queryAdapter_delegation(self):
         service = self._service