Home - Summaries: (main) : (py3.11) : (py3.12) : Everything - Nightly builds - Benchmarks - RPython - Builders - About

pypy/module/cpyext/test/test_cpyext.py::AppTestCpythonExtension::()::test_internal_exceptions

self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00007fa078e23130>

    def test_internal_exceptions(self):
            if self.runappdirect:
                skip('cannot import module with undefined functions')
            import sys
            body = """
            PyAPI_FUNC(PyObject*) PyPy_Crash1(void);
            PyAPI_FUNC(Py_ssize_t) PyPy_Crash2(void);
            PyAPI_FUNC(PyObject*) PyPy_Noop(PyObject*);
            static PyObject* foo_crash1(PyObject* self, PyObject *args)
            {
                return PyPy_Crash1();
            }
            static PyObject* foo_crash2(PyObject* self, PyObject *args)
            {
                Py_ssize_t a = PyPy_Crash2();
                if (a == -1)
                    return NULL;
                return PyFloat_FromDouble((double)a);
            }
            static PyObject* foo_crash3(PyObject* self, PyObject *args)
            {
                Py_ssize_t a = PyPy_Crash2();
                if (a == -1)
                    PyErr_Clear();
                return PyFloat_FromDouble((double)a);
            }
            static PyObject* foo_crash4(PyObject* self, PyObject *args)
            {
                Py_ssize_t a = PyPy_Crash2();
                return PyFloat_FromDouble((double)a);
            }
            static PyObject* foo_noop(PyObject* self, PyObject* args)
            {
                Py_INCREF(args);
                return PyPy_Noop(args);
            }
            static PyObject* foo_set(PyObject* self, PyObject *args)
            {
                PyErr_SetString(PyExc_TypeError, "clear called with no error");
                if (PyLong_Check(args)) {
                    Py_INCREF(args);
                    return args;
                }
                return NULL;
            }
            static PyObject* foo_clear(PyObject* self, PyObject *args)
            {
                PyErr_Clear();
                if (PyLong_Check(args)) {
                    Py_INCREF(args);
                    return args;
                }
                return NULL;
            }
            static PyMethodDef methods[] = {
                { "crash1", foo_crash1, METH_NOARGS },
                { "crash2", foo_crash2, METH_NOARGS },
                { "crash3", foo_crash3, METH_NOARGS },
                { "crash4", foo_crash4, METH_NOARGS },
                { "clear",  foo_clear,  METH_O },
                { "set",    foo_set,    METH_O },
                { "noop",   foo_noop,   METH_O },
                { NULL }
            };
            static struct PyModuleDef moduledef = {
                PyModuleDef_HEAD_INIT,
                "%(modname)s",  /* m_name */
                NULL,           /* m_doc */
                -1,             /* m_size */
                methods,        /* m_methods */
            };
            """
            module = self.import_module(name='foo', body=body)
    
            # uncaught interplevel exceptions are turned into SystemError
            expected = "ZeroDivisionError('integer division"
            exc = raises(SystemError, module.crash1)
            # Work around difference in err msg btween CPython2 and PyPy2
            assert exc.value.args[0].startswith(expected)
    
            exc = raises(SystemError, module.crash2)
            assert exc.value.args[0].startswith(expected)
    
            # caught exception, api.cpython_api return value works
            assert module.crash3() == -1
    
            expected = 'c function call returned a result with an exception set'
            # PyPy only incompatibility/extension
            exc = raises(SystemError, module.crash4)
>           assert exc.value.args[0] == expected
E           (application-level) AssertionError

[/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/test/test_cpyext.py:817]:90: AssertionError
---------- Captured stderr call ----------
<function PyModule_Create2 at 0x00007fa058d7d100>  DONE
<function PyPy_Crash1 at 0x00007fa058efd880>Traceback (most recent call last):
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 1137, in wrapper_second_level
    result = callable(space, *boxed_args)
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/test/test_cpyext.py", line 23, in PyPy_Crash1
    1/0
ZeroDivisionError: integer division by zero
 <function PyPy_Crash2 at 0x00007fa058efd790>Traceback (most recent call last):
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 1137, in wrapper_second_level
    result = callable(space, *boxed_args)
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/test/test_cpyext.py", line 27, in PyPy_Crash2
    1/0
ZeroDivisionError: integer division by zero
 <function PyPy_Crash2 at 0x00007fa058efd790>Traceback (most recent call last):
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 1137, in wrapper_second_level
    result = callable(space, *boxed_args)
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/test/test_cpyext.py", line 27, in PyPy_Crash2
    1/0
ZeroDivisionError: integer division by zero
 <function PyErr_Clear at 0x00007fa0992874c0>  DONE
<function PyFloat_FromDouble at 0x00007fa078de03e0>  DONE
<function PyPy_Crash2 at 0x00007fa058efd790>Traceback (most recent call last):
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 1137, in wrapper_second_level
    result = callable(space, *boxed_args)
  File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/cpyext/test/test_cpyext.py", line 27, in PyPy_Crash2
    1/0
ZeroDivisionError: integer division by zero
 <function PyFloat_FromDouble at 0x00007fa078de03e0>  DONE
builder: own-macos-x86-64 build #1323+
test: pypy/module/cpyext/test/test_cpyext.py::AppTestCpythonExtension::()::test_internal_exceptions