gh-94751: Install, import and run the test C++ extension (MVP) (GH-94754) (#94780)

This is a quick-and-dirty way to run the C++ tests.
It can definitely be improved in the future, but it should fail when things go wrong.

- Run test functions on import (yes, this can definitely be improved)
- Fudge setuptools metadata (name & version) to make the extension installable
- Install and import the extension in test_cppext
(cherry picked from commit ec5db539b9)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-07-13 02:09:06 -07:00 committed by GitHub
parent 3c91f42918
commit ffbd6ae37c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 17 deletions

View file

@ -128,6 +128,9 @@ static PyMethodDef _testcppext_methods[] = {
{"add", _testcppext_add, METH_VARARGS, _testcppext_add_doc},
{"test_api_casts", test_api_casts, METH_NOARGS, _Py_NULL},
{"test_unicode", test_unicode, METH_NOARGS, _Py_NULL},
// Note: _testcppext_exec currently runs all test functions directly.
// When adding a new one, add a call there.
{_Py_NULL, _Py_NULL, 0, _Py_NULL} /* sentinel */
};
@ -138,6 +141,17 @@ _testcppext_exec(PyObject *module)
if (PyModule_AddIntMacro(module, __cplusplus) < 0) {
return -1;
}
PyObject *result;
result = PyObject_CallMethod(module, "test_api_casts", "");
if (!result) return -1;
Py_DECREF(result);
result = PyObject_CallMethod(module, "test_unicode", "");
if (!result) return -1;
Py_DECREF(result);
return 0;
}