[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_module.py:1.9.6.1 test_servicemanager.py:1.13.6.1

Fred L. Drake, Jr. fred@zope.com
Sat, 28 Jun 2003 10:44:06 -0400


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

Modified Files:
      Tag: fdrake-local-modules-branch
	test_module.py test_servicemanager.py 
Log Message:
Checkpoint: changes to local modules started with Jim on Thursday.
These are not yet ready to land on the trunk.


=== Zope3/src/zope/app/services/tests/test_module.py 1.9 => 1.9.6.1 ===
--- Zope3/src/zope/app/services/tests/test_module.py:1.9	Sat Jun  7 01:32:01 2003
+++ Zope3/src/zope/app/services/tests/test_module.py	Sat Jun 28 10:44:05 2003
@@ -17,7 +17,8 @@
 $Id$
 """
 
-from unittest import TestCase, TestLoader, TextTestRunner
+import unittest
+
 from zope.interface import Interface, implements
 from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.traversing import traverse
@@ -34,50 +35,69 @@
 
     implements(ITestService)
 
-class ServiceManagerTests(PlacefulSetup, TestCase):
+
+NAME = 'zope.app.services.tests.sample1'
+
+called = 0
+
+SOURCE = """\
+class C:
+    def __init__(self, v):
+        self.ini = v
+
+x = 1
+from zope.app.services.tests import test_module
+
+test_module.called += 1
+"""
+
+class LocalModuleTests(PlacefulSetup, unittest.TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self, site=True)
+        self.sm = traverse(self.rootFolder, "++etc++site")
+        default = traverse(self.sm, "default")
+        old_called = called
+        default.setObject(NAME, Manager(NAME, SOURCE))
+        self.manager = traverse(default, NAME)
+        self.assertEqual(called, old_called)
+        self.manager.execute()
+        self.assertEqual(called, old_called + 1)
 
-    def test_resolve(self):
-        sm = traverse(self.rootFolder, "++etc++site")
-        default = traverse(sm, "default")
-        default.setObject('m1', Manager())
-        manager = traverse(default, "m1")
-        manager.new('zope.app.services.tests.sample1',
-                    "class C:\n"
-                    "    def __init__(self, v):\n"
-                    "        self.ini = v\n"
-                    "\n"
-                    "x=1\n"
-                    )
-
+    def test_module_persistence(self):
         db = DB(MappingStorage())
         conn = db.open()
         root = conn.root()
         root['Application'] = self.rootFolder
         get_transaction().commit()
+        default = traverse(self.rootFolder, "++etc++site/default")
+        m = default.findModule(NAME)
 
-        C = sm.resolve("zope.app.services.tests.sample1.C")
-        c = C(42)
+        c = m.C(42)
         self.assertEqual(c.ini, 42)
-        x = sm.resolve("zope.app.services.tests.sample1.x")
-        self.assertEqual(x, 1)
-        
+        self.assertEqual(m.x, 1)
+
+        # This tests that the module can be seen from a different
+        # connection; an earlier version had a bug that requires this
+        # regression check.
         conn2 = db.open()
         rootFolder2 = conn2.root()['Application']
-        sm2 = traverse(rootFolder2, "++etc++site")
+        default = traverse(rootFolder2, "++etc++site/default")
+        m = default.findModule(NAME)
 
-        C = sm2.resolve("zope.app.services.tests.sample1.C")
-        c = C(42)
+        c = m.C(42)
         self.assertEqual(c.ini, 42)
-        x = sm2.resolve("zope.app.services.tests.sample1.x")
-        self.assertEqual(x, 1)
+        self.assertEqual(m.x, 1)
+
+    def test_recompile(self):
+        old_called = called
+        self.manager.source += "\n"
+        self.assertEqual(called, old_called)
+        
 
 
 def test_suite():
-    loader=TestLoader()
-    return loader.loadTestsFromTestCase(ServiceManagerTests)
+    return unittest.makeSuite(LocalModuleTests)
 
 if __name__=='__main__':
-    TextTestRunner().run(test_suite())
+    unittest.main(defaultTest="test_suite")


=== Zope3/src/zope/app/services/tests/test_servicemanager.py 1.13 => 1.13.6.1 ===
--- Zope3/src/zope/app/services/tests/test_servicemanager.py:1.13	Sat Jun 21 17:22:13 2003
+++ Zope3/src/zope/app/services/tests/test_servicemanager.py	Sat Jun 28 10:44:05 2003
@@ -159,7 +159,10 @@
         service = getService(self.folder1, 'test_service')
         self.assertEqual(service, ts)
 
-    def test_resolve(self):
+    def donttest_resolve(self):
+        # XXX This test expects that the local module implementation
+        # (the Manager class) to register itself.  This is no longer
+        # intentional behavior; the right tests need to be determined.
         from zope.app.context import ContextWrapper as cw
         from zope.app.services.module import Manager
         import zope.app.services.tests.sample1
@@ -168,21 +171,22 @@
         sm = self.makeSite()
 
         default = cw(sm['default'], self.rootFolder, name='default')
-        default.setObject('m1', Manager())
+        default.setObject('m1', Manager('zope.app.services.tests.sample1',
+                                        'x = "root m1"\n'))
         manager = cw(default['m1'], default, name='m1')
-        manager.new('zope.app.services.tests.sample1',
-                    'x = "root m1"\n')
-        default.setObject('m2', Manager())
+        manager.execute()
+        default.setObject('m2', Manager('XXX.ZZZ',
+                                        'x = "root m2"\nZZZ = 42\n'))
         manager = cw(default['m2'], default, name='m2')
-        manager.new('XXX.ZZZ', 'x = "root m2"\nZZZ = 42\n')
+        manager.execute()
 
         self.folder1.setServiceManager(ServiceManager())
         sm2=getServiceManager(self.folder1)
         default = cw(sm2['default'], self.folder1, name='default')
-        default.setObject('m1', Manager())
+        default.setObject('m1', Manager('zope.app.services.tests.sample1',
+                                        'x = "folder1 m1 1"'))
         manager = cw(default['m1'], default, name='m1')
-        manager.new('zope.app.services.tests.sample1',
-                    'x = "folder1 m1 1"')
+        manager.execute()
 
         self.assertEqual(
           sm2.resolve("zope.app.services.tests.sample1.x"),