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

Jeremy Hylton jeremy@zope.com
Fri, 20 Sep 2002 15:52:27 -0400


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

Modified Files:
	testModule.py 
Log Message:
Add support for relative imports from modules in packages.

XXX I'm not sure this is complete, but it's getting there.




=== Zope3/lib/python/Persistence/tests/testModule.py 1.20 => 1.21 ===
--- Zope3/lib/python/Persistence/tests/testModule.py:1.20	Fri Sep 20 14:28:07 2002
+++ Zope3/lib/python/Persistence/tests/testModule.py	Fri Sep 20 15:52:26 2002
@@ -63,7 +63,7 @@
         self._registry = registry
 
     def __import__(self, name, globals={}, locals={}, fromlist=[]):
-        mod = self._import(self._registry, name, globals.get('__name__'),
+        mod = self._import(self._registry, name, self._get_parent(globals),
                            fromlist)
         if mod is not None:
             return mod
@@ -260,7 +260,28 @@
         mgr = PersistentModuleManager(self.registry)
         self.assertRaises(ValueError,
                           mgr.new, "A.__init__.D", "x = 2")
-                          
+
+    def testPackageRelativeImport(self):
+        mgr = PersistentModuleManager(self.registry)
+        mgr.new("A.B.C", "def f(x): return x")
+        get_transaction().commit()
+
+        mgr = PersistentModuleManager(self.registry)
+        mgr.new("A.Q", "from B.C import f")
+        get_transaction().commit()
+
+        import A.Q
+        self.assertEqual(A.B.C.f, A.Q.f)
+
+        mgr.update("import B.C")
+        get_transaction().commit()
+
+        self.assertEqual(A.B.C.f, A.Q.B.C.f)
+
+        try:
+            import A.B.Q
+        except ImportError:
+            pass
 
 class TestModuleReload(unittest.TestCase):
     """Test reloading of modules"""