Le sam. 1 sept. 2018 à 08:20, Stefan Behnel <python_capi@behnel.de> a écrit :
Totally agree with Jeroen. Cython makes it trivial to integrate with the current CPython testing infrastructure (as I mentioned somewhere else, we're even using doctests for Cython itself), while giving you any freedom you need for fine grained C-level testing.
I don't know. For me, Cython adds a big layer on top of the C API, and if something bad happens, I would be able to know if the issue comes from the C API, Cython or something else. I like unit tests written in C, because you can debug them directly using gdb: the code that you see in gdb is the code that you debug. Moreover, I'm not sure that Cython does not do anything "magic" behind my back.
Here's a simple PyMalloc test that might be relevant for the case at hand:
https://github.com/cython/cython/blob/master/tests/run/cpython_capi.pyx
The advantage of these tests is the try/finally.
Check is designed for the good case: when the test pass. I don't see how to release resources when a test fails. But since Check does fork by default, side effects of a failing test should be limited. Moreover, the side effects only concern tests which fail, and I'm optimistic: tests should pass in the normal case :-)
Apart of that, it doesn't seem *to me* that tests written with Check are more verbose: https://github.com/pythoncapi/cpython/blob/pythoncapi/capi_tests/test_tuple....
And some doctest intensive generator tests:
https://github.com/cython/cython/blob/master/tests/run/generators.pyx
Hum, IMHO doctests are too high level for the C API. If possible, I would prefer to not execute Python code in C tests. But it's likely that I will need some Python somewhere ;-)
I find doctests a really nice way to write parametrised C tests.
Using Check, parametrised tests are a litlte bit verbose, I agree:
static void check_PyTuple_New(size_t size) { /* ... */ }
START_TEST(test_PyTuple_New) { check_PyTuple_New(0); check_PyTuple_New(1); check_PyTuple_New(5);
PyObject *tuple = PyTuple_New(-1);
ck_assert_ptr_null(tuple);
} END_TEST
Of course you may have other reasons to not want Cython...
Cython adds another dependency, I would prefer to limit dependencies.
Well, I don't want to take decisions alone. What do other people think about writing tests using Cython instead of Check?
Victor