[Zope3-checkins] CVS: Zope3/lib/python/Persistence/tests - testModule.py:1.27

Jeremy Hylton jeremy@zope.com
Mon, 7 Oct 2002 19:30:36 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv7760/Persistence/tests

Modified Files:
	testModule.py 
Log Message:
Re-enable the reload() tests but without calling reload() :-).

reload() only accepts real modules, so it can't be used for a
persistent module.

Must uninstall() one importer before loading another, and must
guarantee that the registry is not a ghost.


=== Zope3/lib/python/Persistence/tests/testModule.py 1.26 => 1.27 ===
--- Zope3/lib/python/Persistence/tests/testModule.py:1.26	Mon Oct  7 14:41:11 2002
+++ Zope3/lib/python/Persistence/tests/testModule.py	Mon Oct  7 19:30:35 2002
@@ -61,6 +61,7 @@
 
     def __init__(self, registry):
         self._registry = registry
+        self._registry._p_activate()
 
     def __import__(self, name, globals={}, locals={}, fromlist=[]):
         mod = self._import(self._registry, name, self._get_parent(globals),
@@ -68,7 +69,6 @@
         if mod is not None:
             return mod
         return self._saved_import(name, globals, locals, fromlist)
-    
 
 class TestModule(unittest.TestCase):
 
@@ -317,16 +317,6 @@
 class TestModuleReload(unittest.TestCase):
     """Test reloading of modules"""
 
-    """XXX reload isn't working right now
-
-    ======================================================================
-    ERROR: testClassReload (Persistence.tests.testModule.TestModuleReload)
-    ----------------------------------------------------------------------
-    Traceback (most recent call last):
-        File "/usr/home/jeremy/src/Zope3/lib/python/Persistence/tests/testModule.py", line 272, in testClassReload
-        reload(foo)
-    """
-
     def setUp(self):
         self.storage = MappingStorage()
         self.open()
@@ -337,10 +327,11 @@
         # open a new db and importer from the storage
         self.db = ZODB.DB.DB(self.storage)
         self.root = self.db.open().root()
-        self.registry = PersistentModuleRegistry()
+        self.registry = self.root.get("registry")
+        if self.registry is None:
+            self.root["registry"] = self.registry = PersistentModuleRegistry()
         self.importer = TestPersistentModuleImporter(self.registry)
         self.importer.install()
-        self.root["registry"] = self.registry
         get_transaction().commit()
 
     def close(self):
@@ -357,8 +348,10 @@
         pmtest.f(4)
         self.close()
         pmtest._p_deactivate()
+        self.importer.uninstall()
         self.open()
-        reload(pmtest)
+        del pmtest
+        import pmtest
 
     def testClassReload(self):
         mgr = PersistentModuleManager(self.registry)
@@ -372,12 +365,14 @@
         get_transaction().commit()
         self.close()
         foo._p_deactivate()
+        self.importer.uninstall()
         self.open()
-        reload(foo)
+        del foo
+        import foo
 
 def test_suite():
     s = unittest.TestSuite()
-    for klass in TestModule,: # TestModuleReload:
+    for klass in TestModule, TestModuleReload:
         s.addTest(unittest.makeSuite(klass))
     return s