gh-93649: Move _testcapi tests to specific files (#129544)

Move many functions from _testcapimodule.c into more specific files
in Modules/_testcapi/.

In moved code:

* Replace get_testerror() with PyExc_AssertionError.
* Replace raiseTestError() with
  PyErr_Format(PyExc_AssertionError, ...).
This commit is contained in:
Victor Stinner 2025-02-01 13:39:16 +01:00 committed by GitHub
parent 7d0521d5fc
commit 71ae93374d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 651 additions and 646 deletions

View file

@ -8,18 +8,37 @@ set_get_size(PyObject *self, PyObject *obj)
RETURN_SIZE(PySet_GET_SIZE(obj));
}
static PyObject*
test_set_type_size(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *obj = PyList_New(0);
if (obj == NULL) {
return NULL;
}
// Ensure that following tests don't modify the object,
// to ensure that Py_DECREF() will not crash.
assert(Py_TYPE(obj) == &PyList_Type);
assert(Py_SIZE(obj) == 0);
// bpo-39573: Test Py_SET_TYPE() and Py_SET_SIZE() functions.
Py_SET_TYPE(obj, &PyList_Type);
Py_SET_SIZE(obj, 0);
Py_DECREF(obj);
Py_RETURN_NONE;
}
static PyMethodDef test_methods[] = {
{"set_get_size", set_get_size, METH_O},
{"test_set_type_size", test_set_type_size, METH_NOARGS},
{NULL},
};
int
_PyTestCapi_Init_Set(PyObject *m)
{
if (PyModule_AddFunctions(m, test_methods) < 0) {
return -1;
}
return 0;
return PyModule_AddFunctions(m, test_methods);
}