Commits

Christoph Reiter committed 38111c7

Move tests back to python

Comments (0)

Files changed (2)

pypy/module/cpyext/test/test_import.py

         assert stat
         assert space.getattr(stat, space.wrap("S_IMODE"))
 
-    def test_import_ext(self, space, api):
+    def test_import_module_ext(self, space, api):
         with rffi.scoped_str2charp("os.path") as modname:
             w_ospath = api.PyImport_ImportModuleEx(
                 modname, None, None, space.wrap(["foo"]))
         import os.path as ospath
         assert space.unwrap(space.getattr(w_ospath, space.wrap('__name__'))) == ospath.__name__
 
+        with rffi.scoped_str2charp("os.path") as modname:
+            w_ospath = api.PyImport_ImportModuleEx(
+                modname, None, None, None)
+        assert w_ospath
+        assert space.unwrap(space.getattr(w_ospath, space.wrap('__name__'))) == "os"
+
+        with rffi.scoped_str2charp("os.path") as modname:
+            w_ospath = api.PyImport_ImportModuleEx(
+                modname, space.newdict(), space.newdict(), space.newlist([]))
+        assert w_ospath
+        assert space.unwrap(space.getattr(w_ospath, space.wrap('__name__'))) == "os"
+
     def test_import_module_level(self, space, api):
         with rffi.scoped_str2charp("stat") as modname:
             w_stat = api.PyImport_ImportModuleLevel(
-                modname, None, None, space.newdict(), 0)
+                modname, space.newdict(), space.newdict(), space.newlist([]), 0)
         assert w_stat
         assert w_stat is space.getitem(space.sys.get("modules"), space.wrap("stat"))
 
+        with rffi.scoped_str2charp("stat") as modname:
+            w_stat = api.PyImport_ImportModuleLevel(
+                modname, None, None, None, -1)
+        assert w_stat
+
     def test_addmodule(self, space, api):
         with rffi.scoped_str2charp("sys") as modname:
             w_sys = api.PyImport_AddModule(modname)
         sys.path.append(path)
         import test_import_module
         assert test_import_module.TEST is None
-
-    def test_import_module_ex(self):
-        path = self.import_module(name='test_import_c', load_it=False)
-        import sys
-        sys.path.append(path)
-        import test_import_c
-        assert test_import_c.TEST == "OK"

pypy/module/cpyext/test/test_import_c.c

-#include "Python.h"
-
-void inittest_import_c(void)
-{
-     PyObject *from_list, *globals, *locals, *dict;
-     PyObject *module, *mod_name;
-
-     // PyImport_Import
-
-     mod_name = PyString_FromString ("os");
-     if(!mod_name)
-          return;
-     module = PyImport_Import (mod_name);
-     if (!module)
-          return;
-
-     Py_DECREF (module);
-     Py_DECREF (mod_name);
-
-     // PyImport_ImportModuleEx
-
-     from_list = Py_BuildValue ("(s)", "foobar");
-     globals = PyDict_New ();
-     locals = PyDict_New ();
-
-     if (!from_list || !globals || !locals)
-          return;
-
-     module = PyImport_ImportModuleEx ("os.path", NULL, NULL, NULL);
-     if (!module)
-          return;
-     Py_DECREF (module);
-
-     module = PyImport_ImportModuleEx ("os.path", globals, locals, from_list);
-     if (!module)
-          return;
-     Py_DECREF (module);
-
-     // PyImport_ImportModuleLevel
-
-     module = PyImport_ImportModuleLevel ("os.path", NULL, NULL, NULL, -1);
-     if (!module)
-          return;
-     Py_DECREF (module);
-
-     module = PyImport_ImportModuleLevel ("os.path", globals, locals,
-                                          from_list, 0);
-     if (!module)
-          return;
-     Py_DECREF (module);
-
-     Py_DECREF (from_list);
-     Py_DECREF (locals);
-     Py_DECREF (globals);
-
-     // signal the tests that everything passed
-     module = Py_InitModule("test_import", NULL);
-     if (!module)
-          return;
-     PyModule_AddStringConstant (module, "TEST", "OK");
-}