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

fijal at codespeak.net fijal at codespeak.net
Sat Mar 13 19:16:52 CET 2010


Author: fijal
Date: Sat Mar 13 19:16:50 2010
New Revision: 72206

Modified:
   pypy/trunk/pypy/module/imp/importing.py
   pypy/trunk/pypy/module/imp/interp_imp.py
   pypy/trunk/pypy/module/imp/test/test_app.py
Log:
A test (and a fix?). I think the only other guy who might be confused now
is reload() but we have no tests that break (at the very least)


Modified: pypy/trunk/pypy/module/imp/importing.py
==============================================================================
--- pypy/trunk/pypy/module/imp/importing.py	(original)
+++ pypy/trunk/pypy/module/imp/importing.py	Sat Mar 13 19:16:50 2010
@@ -356,9 +356,14 @@
         return space.getbuiltinmodule(find_info.filename, force_init=True)
 
     if find_info.modtype in (PY_SOURCE, PY_COMPILED, PKG_DIRECTORY):
+        w_mod = None
         if reuse:
-            w_mod = space.getitem(space.sys.get('modules'), w_modulename)
-        else:
+            try:
+                w_mod = space.getitem(space.sys.get('modules'), w_modulename)
+            except OperationError, oe:
+                if not oe.match(space, space.w_KeyError):
+                    raise
+        if w_mod is None:
             w_mod = space.wrap(Module(space, w_modulename))
         if find_info.modtype == PKG_DIRECTORY:
             pkgdir = find_info.filename

Modified: pypy/trunk/pypy/module/imp/interp_imp.py
==============================================================================
--- pypy/trunk/pypy/module/imp/interp_imp.py	(original)
+++ pypy/trunk/pypy/module/imp/interp_imp.py	Sat Mar 13 19:16:50 2010
@@ -76,7 +76,7 @@
         space.str_w(w_suffix),
         filemode)
     return importing.load_module(
-        space, w_name, find_info)
+        space, w_name, find_info, reuse=True)
 
 def load_source(space, w_modulename, w_filename, w_file=None):
     filename = space.str_w(w_filename)

Modified: pypy/trunk/pypy/module/imp/test/test_app.py
==============================================================================
--- pypy/trunk/pypy/module/imp/test/test_app.py	(original)
+++ pypy/trunk/pypy/module/imp/test/test_app.py	Sat Mar 13 19:16:50 2010
@@ -110,3 +110,14 @@
             pass
         else:
             raise Exception("expected an ImportError")
+
+    def test_load_module_in_sys_modules(self):
+        fn = self._py_file()
+        f = open(fn, 'rb')
+        descr = ('.py', 'U', self.imp.PY_SOURCE)
+        mod = self.imp.load_module('test_imp_extra_AUTO6', f, fn, descr)
+        f.close()
+        f = open(fn, 'rb')
+        mod2 = self.imp.load_module('test_imp_extra_AUTO6', f, fn, descr)
+        f.close()
+        assert mod2 is mod



More information about the Pypy-commit mailing list