mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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:
parent
7d0521d5fc
commit
71ae93374d
9 changed files with 651 additions and 646 deletions
|
@ -99,9 +99,68 @@ _testcapi_float_unpack_impl(PyObject *module, const char *data,
|
|||
return PyFloat_FromDouble(d);
|
||||
}
|
||||
|
||||
|
||||
/* Test PyOS_string_to_double. */
|
||||
static PyObject *
|
||||
test_string_to_double(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
double result;
|
||||
const char *msg;
|
||||
|
||||
#define CHECK_STRING(STR, expected) \
|
||||
do { \
|
||||
result = PyOS_string_to_double(STR, NULL, NULL); \
|
||||
if (result == -1.0 && PyErr_Occurred()) { \
|
||||
return NULL; \
|
||||
} \
|
||||
if (result != (double)expected) { \
|
||||
msg = "conversion of " STR " to float failed"; \
|
||||
goto fail; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_INVALID(STR) \
|
||||
do { \
|
||||
result = PyOS_string_to_double(STR, NULL, NULL); \
|
||||
if (result == -1.0 && PyErr_Occurred()) { \
|
||||
if (PyErr_ExceptionMatches(PyExc_ValueError)) { \
|
||||
PyErr_Clear(); \
|
||||
} \
|
||||
else { \
|
||||
return NULL; \
|
||||
} \
|
||||
} \
|
||||
else { \
|
||||
msg = "conversion of " STR " didn't raise ValueError"; \
|
||||
goto fail; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
CHECK_STRING("0.1", 0.1);
|
||||
CHECK_STRING("1.234", 1.234);
|
||||
CHECK_STRING("-1.35", -1.35);
|
||||
CHECK_STRING(".1e01", 1.0);
|
||||
CHECK_STRING("2.e-2", 0.02);
|
||||
|
||||
CHECK_INVALID(" 0.1");
|
||||
CHECK_INVALID("\t\n-3");
|
||||
CHECK_INVALID(".123 ");
|
||||
CHECK_INVALID("3\n");
|
||||
CHECK_INVALID("123abc");
|
||||
|
||||
Py_RETURN_NONE;
|
||||
fail:
|
||||
PyErr_Format(PyExc_AssertionError, "test_string_to_double: %s", msg);
|
||||
return NULL;
|
||||
#undef CHECK_STRING
|
||||
#undef CHECK_INVALID
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
_TESTCAPI_FLOAT_PACK_METHODDEF
|
||||
_TESTCAPI_FLOAT_UNPACK_METHODDEF
|
||||
{"test_string_to_double", test_string_to_double, METH_NOARGS},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue