Author: Ronan Lamy <[email protected]>
Branch: py3k-update
Changeset: r84031:3a1f7e742d24
Date: 2016-04-29 16:33 +0100
http://bitbucket.org/pypy/pypy/changeset/3a1f7e742d24/

Log:    Fix some tests

diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -387,9 +387,9 @@
     freshly raised.  This function steals the references of the arguments.
     To clear the exception state, pass *NULL* for all three arguments.
     For general rules about the three arguments, see :c:func:`PyErr_Restore`.
- 
+
     .. note::
- 
+
        This function is not normally used by code that wants to handle
        exceptions.  Rather, it can be used when code needs to save and
        restore the exception state temporarily.  Use
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -700,7 +700,7 @@
     UnicodeSubtype3.tp_bases = Py_BuildValue("(OO)", &UnicodeSubtype,
                                                     &CustomType);
     if (PyType_Ready(&UnicodeSubtype3) < 0)
-        return;
+        return NULL;
 
     m = PyModule_Create(&moduledef);
     if (m == NULL)
diff --git a/pypy/module/cpyext/test/foo3.c b/pypy/module/cpyext/test/foo3.c
--- a/pypy/module/cpyext/test/foo3.c
+++ b/pypy/module/cpyext/test/foo3.c
@@ -62,23 +62,36 @@
 
 static PyMethodDef sbkMethods[] = {{NULL, NULL, 0, NULL}};
 
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    "foo",
+    "Module Doc",
+    -1,
+    &sbkMethods,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+};
+
 /* Initialize this module. */
 #ifdef __GNUC__
 extern __attribute__((visibility("default")))
 #endif
 
 PyMODINIT_FUNC
-initfoo3(void)
+PyInit_foo3(void)
 {
     PyObject *mod, *d;
     footype.tp_base = &PyType_Type;
     PyType_Ready(&footype);
-    mod = Py_InitModule("foo3", sbkMethods);
+    mod = PyModule_Create(&moduledef);
     if (mod == NULL)
-        return;
+        return NULL;
     d = PyModule_GetDict(mod);
     if (d == NULL)
-        return;
+        return NULL;
     if (PyDict_SetItemString(d, "footype", (PyObject *)&footype) < 0)
-        return;
+        return NULL;
+    return mod;
 }
diff --git a/pypy/module/cpyext/test/test_cpyext.py 
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -401,6 +401,8 @@
             init = """PyObject *mod = PyModule_Create(&moduledef);"""
             if more_init:
                 init += more_init
+            else:
+                init += "\nreturn mod;"
             return import_module(space, name=modname, init=init, body=body,
                                  w_include_dirs=w_include_dirs,
                                  PY_SSIZE_T_CLEAN=PY_SSIZE_T_CLEAN)
diff --git a/pypy/module/cpyext/test/test_getargs.py 
b/pypy/module/cpyext/test/test_getargs.py
--- a/pypy/module/cpyext/test/test_getargs.py
+++ b/pypy/module/cpyext/test/test_getargs.py
@@ -123,7 +123,6 @@
             return result;
             ''')
         assert b'foo\0bar\0baz' == pybuffer(b'foo\0bar\0baz')
-        assert 'foo\0bar\0baz' == pybuffer(bytearray('foo\0bar\0baz'))
 
 
     def test_pyarg_parse_string_fails(self):
diff --git a/pypy/module/cpyext/test/test_iterator.py 
b/pypy/module/cpyext/test/test_iterator.py
--- a/pypy/module/cpyext/test/test_iterator.py
+++ b/pypy/module/cpyext/test/test_iterator.py
@@ -40,7 +40,7 @@
             ),
            ("check", "METH_O",
             '''
-                return PyInt_FromLong(
+                return PyLong_FromLong(
                     PySequence_Check(args) +
                     PyMapping_Check(args) * 2);
             ''')
@@ -49,7 +49,7 @@
             static PyObject *
             mp_subscript(PyObject *self, PyObject *key)
             {
-                return PyInt_FromLong(42);
+                return PyLong_FromLong(42);
             }
             static Py_ssize_t
             mp_length(PyObject *self)
@@ -69,10 +69,6 @@
         e = raises(TypeError, iter, obj)
         assert str(e.value).endswith("object is not iterable")
         #
-        import operator
-        assert not operator.isSequenceType(obj)
-        assert operator.isMappingType(obj)
-        #
         assert module.check(obj) == 2
 
     def test_iterable_nonmapping_object(self):
@@ -90,7 +86,7 @@
             '''),
            ("check", "METH_O",
             '''
-                return PyInt_FromLong(
+                return PyLong_FromLong(
                     PySequence_Check(args) +
                     PyMapping_Check(args) * 2);
             ''')
@@ -99,7 +95,7 @@
             static PyObject *
             sq_item(PyObject *self, Py_ssize_t size)
             {
-                return PyInt_FromLong(42);
+                return PyLong_FromLong(42);
             }
             static Py_ssize_t
             sq_length(PyObject *self)
@@ -117,11 +113,7 @@
         assert len(obj) == 2
         assert not hasattr(obj, "__iter__")
         it = iter(obj)
-        assert it.next() == 42
-        assert it.next() == 42
-        #
-        import operator
-        assert operator.isSequenceType(obj)
-        assert not operator.isMappingType(obj)
+        assert next(it) == 42
+        assert next(it) == 42
         #
         assert module.check(obj) == 1
diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -151,7 +151,7 @@
         obj2 = module.UnicodeSubtype2()
         obj3 = module.UnicodeSubtype3()
         assert obj3.get_val() == 42
-        assert len(type(obj3).mro()) == 6
+        assert len(type(obj3).mro()) == 5
 
     def test_init(self):
         module = self.import_module(name="foo")
@@ -269,7 +269,7 @@
     def test_tp_dict(self):
         foo = self.import_module("foo")
         module = self.import_extension('test', [
-           ("read_tp_dict", "METH_O",
+            ("read_tp_dict", "METH_O",
             '''
                  PyObject *method;
                  if (!args->ob_type->tp_dict)
@@ -281,9 +281,7 @@
                      args->ob_type->tp_dict, "copy");
                  Py_INCREF(method);
                  return method;
-             '''
-             )
-            ])
+             ''')])
         obj = foo.new()
         assert module.read_tp_dict(obj) == foo.fooType.copy
 
@@ -377,7 +375,7 @@
         assert api.PyErr_Occurred() is None
 
     def test_ndarray_ref(self, space, api):
-        py.test.py3k_skip('Numpy not yet supported on py3k')
+        pytest.py3k_skip('Numpy not yet supported on py3k')
         w_obj = space.appexec([], """():
             import _numpypy
             return _numpypy.multiarray.dtype('int64').type(2)""")
@@ -536,21 +534,22 @@
         module = self.import_extension('foo', [
             ("tp_call", "METH_VARARGS",
              '''
-                 PyObject *obj = PyTuple_GET_ITEM(args, 0);
-                 PyObject *c_args = PyTuple_GET_ITEM(args, 1);
-                 if (!obj->ob_type->tp_call)
-                 {
-                     PyErr_SetNone(PyExc_ValueError);
-                     return NULL;
-                 }
-                 return obj->ob_type->tp_call(obj, c_args, NULL);
-             '''
-             )
-            ])
+                PyTypeObject *type = (PyTypeObject *)PyTuple_GET_ITEM(args, 0);
+                PyObject *obj = PyTuple_GET_ITEM(args, 1);
+                PyObject *c_args = PyTuple_GET_ITEM(args, 2);
+                if (!type->tp_call)
+                {
+                    PyErr_SetNone(PyExc_ValueError);
+                    return NULL;
+                }
+                return type->tp_call(obj, c_args, NULL);
+             ''')])
+
         class C:
             def __call__(self, *args):
                 return args
         assert module.tp_call(type(C()), C(), ('x', 2)) == ('x', 2)
+
         class D(type):
             def __call__(self, *args):
                 return "foo! %r" % (args,)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to