[pypy-svn] r72456 - pypy/trunk/pypy/module/cpyext/test

xoraxax at codespeak.net xoraxax at codespeak.net
Sat Mar 20 16:24:06 CET 2010


Author: xoraxax
Date: Sat Mar 20 16:24:05 2010
New Revision: 72456

Modified:
   pypy/trunk/pypy/module/cpyext/test/test_cpyext.py
Log:
Add skipped tests that is useful to see how an rpython exception behaves.

Modified: pypy/trunk/pypy/module/cpyext/test/test_cpyext.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_cpyext.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_cpyext.py	Sat Mar 20 16:24:05 2010
@@ -11,6 +11,14 @@
 from pypy.translator.goal import autopath
 
 
+ at api.cpython_api([], api.PyObject)
+def PyPy_Crash1(space):
+    1/0
+
+ at api.cpython_api([], lltype.Signed)
+def PyPy_Crash2(space):
+    1/0
+
 class TestApi():
     def test_signature(self):
         assert 'Py_InitModule' in api.FUNCTIONS
@@ -151,7 +159,7 @@
             Py_InitModule("foo", methods);
         """
         body = """
-        PyObject* foo_pi(PyObject* self, PyObject *args)
+        static PyObject* foo_pi(PyObject* self, PyObject *args)
         {
             PyErr_SetString(PyExc_Exception, "moo!");
             return NULL;
@@ -168,4 +176,33 @@
 
         assert exc.value.message == "moo!"
 
+    def test_internal_exceptions(self):
+        py.test.skip("Useful to see how programming errors look like")
+        import sys
+        init = """
+        if (Py_IsInitialized())
+            Py_InitModule("foo", methods);
+        """
+        body = """
+        static PyObject* foo_crash1(PyObject* self, PyObject *args)
+        {
+            return PyPy_Crash1();
+        }
+        static PyObject* foo_crash2(PyObject* self, PyObject *args)
+        {
+            int a = PyPy_Crash2();
+            if (a == -1)
+                return NULL;
+            return PyFloat_FromDouble(a);
+        }
+        static PyMethodDef methods[] = {
+            { "crash1", foo_crash1, METH_NOARGS },
+            { "crash2", foo_crash2, METH_NOARGS },
+            { NULL }
+        };
+        """
+        module = self.import_module(name='foo', init=init, body=body)
+        module.crash1()
+        module.crash2()
+
 



More information about the Pypy-commit mailing list