Author: Armin Rigo <ar...@tunes.org>
Branch: static-callback
Changeset: r2399:e0c7c1c5c761
Date: 2015-11-15 09:12 +0100
http://bitbucket.org/cffi/cffi/changeset/e0c7c1c5c761/

Log:    More tests for what I thought would work because it uses the same
        code as ffi.callback(). Alas, it didn't

diff --git a/c/ffi_obj.c b/c/ffi_obj.c
--- a/c/ffi_obj.c
+++ b/c/ffi_obj.c
@@ -745,10 +745,9 @@
                              (PyCFunction)_ffi_call_python_decorator, METH_O};
     PyObject *name = Py_None, *error = Py_None;
     PyObject *res, *onerror = Py_None;
-    static char *keywords[] = {"name", "python_callable", "error",
-                               "onerror", NULL};
+    static char *keywords[] = {"name", "error", "onerror", NULL};
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", keywords,
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", keywords,
                                      &name, &error, &onerror))
         return NULL;
 
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -1531,7 +1531,7 @@
     assert type(seen[0][1]) is type(seen[0][2]) is int
     assert baz == lib.baz
 
-    @ffi.call_python()
+    @ffi.call_python(name="bok")
     def bok():
         seen.append("Bok")
         return 42
@@ -1662,3 +1662,44 @@
         return expected
     res = lib.bok()
     assert repr(res) == repr(expected)
+
+def test_call_python_signature():
+    ffi = FFI()
+    lib = verify(ffi, 'test_call_python_signature', "")
+    py.test.raises(TypeError, ffi.call_python(425), None)
+    py.test.raises(TypeError, ffi.call_python, 'a', 'b', 'c', 'd')
+
+def test_call_python_errors():
+    ffi = FFI()
+    ffi.cdef("""
+        CFFI_CALL_PYTHON int bar(int);
+    """)
+    lib = verify(ffi, 'test_call_python_errors', "")
+
+    seen = []
+    def oops(*args):
+        seen.append(args)
+
+    @ffi.call_python(onerror=oops)
+    def bar(x):
+        return x + ""
+    assert bar(10) == 0
+
+    @ffi.call_python(name="bar", onerror=oops, error=-66)
+    def bar2(x):
+        return x + ""
+    assert bar(10) == -66
+
+    assert len(seen) == 2
+    exc, val, tb = seen[0]
+    assert exc is TypeError
+    assert isinstance(val, TypeError)
+    assert tb.tb_frame.f_code.co_name == "bar"
+    exc, val, tb = seen[1]
+    assert exc is TypeError
+    assert isinstance(val, TypeError)
+    assert tb.tb_frame.f_code.co_name == "bar2"
+    #
+    # a case where 'onerror' is not callable
+    py.test.raises(TypeError, ffi.call_python(name='bar', onerror=42),
+                   lambda x: x)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to