Commits

Amaury Forgeot d'Arc committed a53f63e

Fix some cpyext tests.

Comments (0)

Files changed (4)

pypy/module/_frozen_importlib/__init__.py

             source = fp.read()
         pathname = "<frozen importlib._bootstrap>"
         code_w = ec.compiler.compile(source, pathname, 'exec', 0)
-        w_dict = space.newdict()
-        space.setitem(w_dict, space.wrap('__name__'), self.w_name)
+        space.setitem(self.w_dict, space.wrap('__name__'), self.w_name)
+        space.setitem(self.w_dict, space.wrap('__builtins__'),
+                      space.wrap(space.builtin))
         code_w.exec_code(space, self.w_dict, self.w_dict)
 
     def startup(self, space):

pypy/module/cpyext/test/date.c

     PyObject *module, *othermodule;
     module = PyModule_Create(&moduledef);
     othermodule = PyImport_ImportModule("apple.banana");
+    if (!othermodule)
+        return NULL;
     Py_DECREF(othermodule);
     return module;
 }

pypy/module/cpyext/test/test_cpyext.py

 class AppTestCpythonExtensionBase(LeakCheckingTest):
 
     def setup_class(cls):
-        cls.space.getbuiltinmodule("cpyext")
-        from pypy.module.imp.importing import importhook
-        importhook(cls.space, "os") # warm up reference counts
-        state = cls.space.fromcache(RefcountState)
+        space = cls.space
+        space.getbuiltinmodule("cpyext")
+        # 'import os' to warm up reference counts
+        w_import = space.builtin.getdictvalue(space, '__import__')
+        space.call_function(w_import, space.wrap("os"))
+        state = space.fromcache(RefcountState)
         state.non_heaptypes_w[:] = []
 
     def setup_method(self, func):

pypy/module/imp/importing.py

         source = fp.read()
     pathname = "<frozen %s>" % modulename
     code_w = ec.compiler.compile(source, pathname, 'exec', 0)
-    w_dict = space.newdict()
     w_mod = add_module(space, space.wrap(modulename))
     space.setitem(space.sys.get('modules'), w_mod.w_name, w_mod)
-    space.setitem(w_dict, space.wrap('__name__'), w_mod.w_name)
+    space.setitem(w_mod.w_dict, space.wrap('__name__'), w_mod.w_name)
     code_w.exec_code(space, w_mod.w_dict, w_mod.w_dict)
     assert check_sys_modules_w(space, modulename)
     return w_mod