[pypy-svn] r70475 - in pypy/trunk/pypy/module/imp: . test

benjamin at codespeak.net benjamin at codespeak.net
Sun Jan 10 00:50:32 CET 2010


Author: benjamin
Date: Sun Jan 10 00:50:30 2010
New Revision: 70475

Modified:
   pypy/trunk/pypy/module/imp/importing.py
   pypy/trunk/pypy/module/imp/test/test_import.py
Log:
reload loaded modules from sys.modules during import like cpython does

Modified: pypy/trunk/pypy/module/imp/importing.py
==============================================================================
--- pypy/trunk/pypy/module/imp/importing.py	(original)
+++ pypy/trunk/pypy/module/imp/importing.py	Sun Jan 10 00:50:30 2010
@@ -389,6 +389,7 @@
         try:
             if find_info:
                 w_mod = load_module(space, w_modulename, find_info)
+                w_mod = space.getitem(space.sys.get("modules"), w_modulename)
                 if w_parent is not None:
                     space.setattr(w_parent, space.wrap(partname), w_mod)
                 return w_mod

Modified: pypy/trunk/pypy/module/imp/test/test_import.py
==============================================================================
--- pypy/trunk/pypy/module/imp/test/test_import.py	(original)
+++ pypy/trunk/pypy/module/imp/test/test_import.py	Sun Jan 10 00:50:30 2010
@@ -69,6 +69,11 @@
                         "print 'TOTO', __name__\n"
                         "sys.modules[__name__] = pkg_substituted")
     setuppkg("pkg_substituted", mod='')
+    setuppkg("evil_pkg",
+             evil = "import sys\n"
+                      "from evil_pkg import good\n"
+                      "sys.modules['evil_pkg.evil'] = good",
+             good = "a = 42")
     p = setuppkg("readonly", x='')
     p = setuppkg("pkg_univnewlines")
     p.join('__init__.py').write(
@@ -134,6 +139,10 @@
     def teardown_class(cls): # interpreter-level
         _teardown(cls.space, cls.saved_modules)
 
+    def test_set_sys_modules_during_import(self):
+        from evil_pkg import evil
+        assert evil.a == 42
+
     def test_import_bare_dir_fails(self):
         def imp():
             import notapackage
@@ -823,6 +832,7 @@
         class Importer(object):
             def find_module(self, fullname, path=None):
                 if fullname == "a":
+                    sys.modules["a"] = self
                     return self
 
             def load_module(self, name):



More information about the Pypy-commit mailing list