[Zope3-checkins] CVS: Zope3/src/zope/component/tests - placelesssetup.py:1.6.28.2 test_adapter.py:1.1.24.1 test_api.py:1.10.24.2 test_presentation.py:1.1.2.2 test_service.py:1.3.28.2

Jim Fulton cvs-admin at zope.org
Tue Nov 18 17:27:11 EST 2003


Update of /cvs-repository/Zope3/src/zope/component/tests
In directory cvs.zope.org:/tmp/cvs-serv19243/src/zope/component/tests

Modified Files:
      Tag: adaptergeddon-branch
	placelesssetup.py test_adapter.py test_api.py 
	test_presentation.py test_service.py 
Log Message:
Implemented local presentation services.


=== Zope3/src/zope/component/tests/placelesssetup.py 1.6.28.1 => 1.6.28.2 ===
--- Zope3/src/zope/component/tests/placelesssetup.py:1.6.28.1	Sun Nov  9 11:08:32 2003
+++ Zope3/src/zope/component/tests/placelesssetup.py	Tue Nov 18 17:26:40 2003
@@ -46,8 +46,8 @@
         # adapter service
         from zope.component.interfaces import IAdapterService
         defineService(Adapters, IAdapterService)
-        from zope.component.adapter import adapterService
-        provideService(Adapters, adapterService)
+        from zope.component.adapter import GlobalAdapterService
+        provideService(Adapters, GlobalAdapterService())
         
         # presentation service
         from zope.component.interfaces import IPresentationService


=== Zope3/src/zope/component/tests/test_adapter.py 1.1 => 1.1.24.1 ===
--- Zope3/src/zope/component/tests/test_adapter.py:1.1	Tue Jun 24 11:29:54 2003
+++ Zope3/src/zope/component/tests/test_adapter.py	Tue Nov 18 17:26:40 2003
@@ -49,9 +49,9 @@
         got = list(registry.getRegisteredMatching())
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
-            ('', R2, P3, [R2_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (R2, P3, (), u'', [R2_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
@@ -60,12 +60,12 @@
         registry = self.getRegistry()
 
         got = list(registry.getRegisteredMatching(
-            for_interfaces = (R1, )
+            required = (R1, )
             ))
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
@@ -74,13 +74,13 @@
         registry = self.getRegistry()
 
         got = list(registry.getRegisteredMatching(
-            for_interfaces = (R12, R2)
+            required = (R12, R2)
             ))
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
-            ('', R2, P3, [R2_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (R2, P3, (), u'', [R2_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
@@ -89,14 +89,14 @@
         registry = self.getRegistry()
 
         got = list(registry.getRegisteredMatching(
-            provided_interfaces = (P1, )
+            provided = (P1, )
             ))
 
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
-            ('', R2, P3, [R2_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (R2, P3, (), u'', [R2_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
@@ -105,13 +105,13 @@
         registry = self.getRegistry()
 
         got = list(registry.getRegisteredMatching(
-            provided_interfaces = (P3, )
+            provided = (P3, )
             ))
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
-            ('', R2, P3, [R2_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (R2, P3, (), u'', [R2_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
@@ -120,14 +120,14 @@
         registry = self.getRegistry()
 
         got = list(registry.getRegisteredMatching(
-            for_interfaces = (R4, R12),
-            provided_interfaces = (P1, ),
+            required = (R4, R12),
+            provided = (P1, ),
             ))
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
-            ('', R2, P3, [R2_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (R2, P3, (), u'', [R2_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
@@ -136,14 +136,14 @@
         registry = self.getRegistry()
 
         got = list(registry.getRegisteredMatching(
-            for_interfaces = (R4, R12),
-            provided_interfaces = (P3, ),
+            required = (R4, R12),
+            provided = (P3, ),
             ))
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
-            ('', R2, P3, [R2_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (R2, P3, (), u'', [R2_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
@@ -152,17 +152,30 @@
         registry = self.getRegistry()
 
         got = list(registry.getRegisteredMatching(
-            for_interfaces = (R2, ),
-            provided_interfaces = (P3, ),
+            required = (R2, ),
+            provided = (P3, ),
             ))
         got.sort()
         expect = [
-            ('', None, P3, [default_P3]),
-            ('', Interface, P3, [any_P3]),
-            ('', R2, P3, [R2_P3]),
+            (Interface, P3, (), u'', [any_P3]),
+            (R2, P3, (), u'', [R2_P3]),
+            (None, P3, (), u'', [default_P3]),
             ]
         expect.sort()
         self.assertEqual(got, expect)
+
+    def test_pickling(self):
+        from zope.component.tests.test_service import testServiceManager
+        from zope.component.interfaces import IAdapterService
+        testServiceManager.defineService('Adapters', IAdapterService)
+        adapters = GlobalAdapterService()
+        testServiceManager.provideService('Adapters', adapters)
+        import pickle
+
+        as = pickle.loads(pickle.dumps(adapters))
+        self.assert_(as is adapters)
+
+        testServiceManager._clear()
 
 def test_suite():
     return unittest.makeSuite(GlobalAdapterServiceTests)


=== Zope3/src/zope/component/tests/test_api.py 1.10.24.1 => 1.10.24.2 ===
--- Zope3/src/zope/component/tests/test_api.py:1.10.24.1	Sun Nov  9 11:08:32 2003
+++ Zope3/src/zope/component/tests/test_api.py	Tue Nov 18 17:26:40 2003
@@ -77,46 +77,7 @@
         # ...otherwise, you get the default
         self.assertEquals(queryAdapter(Conforming, I3, Test), Test)
 
-        getService(None, Adapters).provideAdapter(I1, I2, Comp)
-        c = getAdapter(ob, I2)
-        self.assertEquals(c.__class__, Comp)
-        self.assertEquals(c.context, ob)
-
-        c = getAdapter(ob, I3)
-        self.assertEquals(c.__class__, Comp)
-        self.assertEquals(c.context, ob)
-
-    def testAdapter_via_conform_in_globalAdapterServiceDirectly(self):
-
-        from zope.component.adapter import adapterService
-        provideAdapter = adapterService.provideAdapter
-        getAdapter = adapterService.getAdapter
-        queryAdapter = adapterService.queryAdapter
-
-        ob = Conforming()
-
-        # If an object implements the interface you want to adapt to,
-        # getAdapter should simply return the object.
-        self.assertEquals(getAdapter(ob, I1), ob)
-
-        # If an adapter isn't registered for the given object and interface,
-        # and you provide no default, raise ComponentLookupError...
-        self.assertRaises(ComponentLookupError, getAdapter, ob, I2)
-
-        # If an adapter isn't registered for the given object and interface,
-        # and you provide no default, raise ComponentLookupError...
-        self.assertRaises(ComponentLookupError, getAdapter, Conforming, I2)
-
-        # ...otherwise, you get the default
-        self.assertEquals(queryAdapter(ob, I2, Test), Test)
-
-        # ...otherwise, you get the default
-        self.assertEquals(queryAdapter(Conforming, I2, Test), Test)
-
-        # ...otherwise, you get the default
-        self.assertEquals(queryAdapter(Conforming, I3, Test), Test)
-
-        provideAdapter(I1, I2, Comp)
+        getService(None, Adapters).provideAdapter(I1, I2, [Comp])
         c = getAdapter(ob, I2)
         self.assertEquals(c.__class__, Comp)
         self.assertEquals(c.context, ob)
@@ -137,7 +98,7 @@
         # ...otherwise, you get the default
         self.assertEquals(queryAdapter(ob, I2, Test), Test)
 
-        getService(None, Adapters).provideAdapter(I1, I2, Comp)
+        getService(None, Adapters).provideAdapter(I1, I2, [Comp])
         c = getAdapter(ob, I2)
         self.assertEquals(c.__class__, Comp)
         self.assertEquals(c.context, ob)
@@ -158,7 +119,7 @@
         # ...otherwise, you get the default
         self.assertEquals(queryAdapter(ob, I2, Test, context=ob), Test)
 
-        getService(None, Adapters).provideAdapter(I1, I2, Comp)
+        getService(None, Adapters).provideAdapter(I1, I2, [Comp])
         c = getAdapter(ob, I2, context=ob)
         self.assertEquals(c.__class__, Comp)
         self.assertEquals(c.context, ob)
@@ -184,7 +145,7 @@
 
         class Comp2(Comp): pass
 
-        getService(None, Adapters).provideAdapter(I1, I2, Comp2, name='test')
+        getService(None, Adapters).provideAdapter(I1, I2, [Comp2], name='test')
         c = getNamedAdapter(ob, I2, 'test')
         self.assertEquals(c.__class__, Comp2)
         self.assertEquals(c.context, ob)
@@ -202,7 +163,7 @@
 
         # providing an adapter for None says that your adapter can
         # adapt anything to I2.
-        getService(None, Adapters).provideAdapter(None, I2, Comp)
+        getService(None, Adapters).provideAdapter(None, I2, [Comp])
         c = getAdapter(ob, I2)
         self.assertEquals(c.__class__, Comp)
         self.assertEquals(c.context, ob)


=== Zope3/src/zope/component/tests/test_presentation.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/component/tests/test_presentation.py:1.1.2.1	Mon Nov 10 10:00:43 2003
+++ Zope3/src/zope/component/tests/test_presentation.py	Tue Nov 18 17:26:40 2003
@@ -240,6 +240,26 @@
     True
     """
 
+def test_pickling():
+    """
+    >>> from zope.component.tests.test_service import testServiceManager
+    >>> from zope.component.interfaces import IPresentationService
+    >>> testServiceManager.defineService('Presentation', IPresentationService)
+    >>> presentation = GlobalPresentationService()
+    >>> testServiceManager.provideService('Presentation', presentation)
+    >>> import pickle
+
+    >>> s = pickle.loads(pickle.dumps(presentation))
+    >>> s is presentation
+    True
+    
+    >>> layer = pickle.loads(pickle.dumps(presentation.queryLayer('default')))
+    >>> (layer is presentation.queryLayer('default')) and (layer is not None)
+    True
+
+    >>> testServiceManager._clear()
+    """
+
 
 def test_suite():
     return unittest.TestSuite((


=== Zope3/src/zope/component/tests/test_service.py 1.3.28.1 => 1.3.28.2 ===
--- Zope3/src/zope/component/tests/test_service.py:1.3.28.1	Tue Nov 11 11:04:12 2003
+++ Zope3/src/zope/component/tests/test_service.py	Tue Nov 18 17:26:40 2003
@@ -26,9 +26,8 @@
 
 from zope.component import getServiceDefinitions, getService, getServiceManager
 from zope.component.service import UndefinedService, InvalidService
-from zope.component.service import GlobalServiceManager
+from zope.component.service import GlobalServiceManager, GlobalService
 from zope.component.exceptions import ComponentLookupError
-
 from zope.component import queryService
 
 class IOne(Interface):
@@ -37,10 +36,10 @@
 class ITwo(Interface):
     pass
 
-class ServiceOne:
+class ServiceOne(GlobalService):
     implements(IOne)
 
-class ServiceTwo:
+class ServiceTwo(GlobalService):
     implements(ITwo)
 
 class Test(CleanUp, unittest.TestCase):
@@ -115,10 +114,20 @@
         self.assertEqual(testServiceManager.__reduce__(), 'testServiceManager')
         sm = pickle.loads(pickle.dumps(testServiceManager))
         self.assert_(sm is testServiceManager)
+
+        s2 = ServiceTwo()
+        sm.defineService('2', ITwo)
+        sm.provideService('2', s2)
+
+        self.assert_(s2.__parent__ is sm)
+        self.assertEqual(s2.__name__, '2')
+
+        s = pickle.loads(pickle.dumps(s2))
+        self.assert_(s is s2)
+        testServiceManager._clear()
         
 
 testServiceManager = GlobalServiceManager('testServiceManager', __name__)
-
 
 
 def test_suite():




More information about the Zope3-Checkins mailing list