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

Jeremy Hylton jeremy@zope.com
Fri, 20 Sep 2002 11:21:06 -0400


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

Modified Files:
	testModule.py 
Log Message:
Add support for package __init__ modules.

Also extend _import signature to handle __name__.  This will be used
to support package-local imports.



=== Zope3/lib/python/Persistence/tests/testModule.py 1.18 => 1.19 ===
--- Zope3/lib/python/Persistence/tests/testModule.py:1.18	Thu Sep 19 18:07:02 2002
+++ Zope3/lib/python/Persistence/tests/testModule.py	Fri Sep 20 11:21:05 2002
@@ -63,7 +63,8 @@
         self._registry = registry
 
     def __import__(self, name, globals={}, locals={}, fromlist=[]):
-        mod = self._import(self._registry, name, fromlist)
+        mod = self._import(self._registry, name, globals.get('__name__'),
+                           fromlist)
         if mod is not None:
             return mod
         return self._saved_import(name, globals, locals, fromlist)
@@ -234,6 +235,29 @@
         self.assertRaises(ValueError,
                           mgr.new, "A.B", "def f(x): return x + 1")
 
+        mgr = PersistentModuleManager(self.registry)
+        mgr.new("A.B.D", "def f(x): return x")
+        get_transaction().commit()
+
+    def testPackageInit(self):
+        mgr = PersistentModuleManager(self.registry)
+        mgr.new("A.B.C", "def f(x): return x")
+        get_transaction().commit()
+
+        import A.B.C
+
+        mgr = PersistentModuleManager(self.registry)
+        mgr.new("A.B.__init__", "x = 2")
+        get_transaction().commit()
+
+        import A.B
+        self.assert_(hasattr(A.B, "C"))
+        self.assertEqual(A.B.x, 2)
+
+        mgr = PersistentModuleManager(self.registry)
+        self.assertRaises(ValueError,
+                          mgr.new, "A.__init__.D", "x = 2")
+                          
 
 class TestModuleReload(unittest.TestCase):
     """Test reloading of modules"""