[Zope3-checkins] CVS: Zope3/src/zope/component/tests -
test_service.py:1.4
Jim Fulton
cvs-admin at zope.org
Fri Nov 21 12:10:00 EST 2003
Update of /cvs-repository/Zope3/src/zope/component/tests
In directory cvs.zope.org:/tmp/cvs-serv29575/src/zope/component/tests
Modified Files:
test_service.py
Log Message:
Made global service managers picklable as global objects.
Added GlobalService base class for creating pickleable global
services. Global services are pickled by reducing them to (now
picklable) global service managers and service named.
=== Zope3/src/zope/component/tests/test_service.py 1.3 => 1.4 ===
--- Zope3/src/zope/component/tests/test_service.py:1.3 Fri Jun 6 15:29:08 2003
+++ Zope3/src/zope/component/tests/test_service.py Fri Nov 21 12:09:29 2003
@@ -17,17 +17,17 @@
"""
import unittest
+import pickle
from zope.interface import Interface, implements
+
from zope.exceptions import DuplicationError
from zope.testing.cleanup import CleanUp
-from zope.component \
- import getServiceDefinitions, getService, getServiceManager
-from zope.component.service \
- import UndefinedService, InvalidService
+from zope.component import getServiceDefinitions, getService, getServiceManager
+from zope.component.service import UndefinedService, InvalidService
+from zope.component.service import GlobalServiceManager, GlobalService
from zope.component.exceptions import ComponentLookupError
-
from zope.component import queryService
class IOne(Interface):
@@ -36,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):
@@ -108,6 +108,26 @@
defs.sort()
self.assertEqual(defs,
[('one', IOne), ('two', ITwo)])
+
+
+ def testPickling(self):
+ 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