gh-94808: Add coverage test for number check (gh-111445)

This commit is contained in:
Evan Kohilas 2023-10-29 09:00:19 +02:00 committed by GitHub
parent 3ac9851d69
commit 842e5fcdcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -817,6 +817,13 @@ class CAPITest(unittest.TestCase):
self.assertRaises(TypeError, xtuple, 42) self.assertRaises(TypeError, xtuple, 42)
self.assertRaises(SystemError, xtuple, NULL) self.assertRaises(SystemError, xtuple, NULL)
def test_number_check(self):
number_check = _testcapi.number_check
self.assertTrue(number_check(1 + 1j))
self.assertTrue(number_check(1))
self.assertTrue(number_check(0.5))
self.assertFalse(number_check("1 + 1j"))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@ -180,6 +180,12 @@ object_delattrstring(PyObject *self, PyObject *args)
RETURN_INT(PyObject_DelAttrString(obj, attr_name)); RETURN_INT(PyObject_DelAttrString(obj, attr_name));
} }
static PyObject *
number_check(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyBool_FromLong(PyNumber_Check(obj));
}
static PyObject * static PyObject *
mapping_check(PyObject *self, PyObject *obj) mapping_check(PyObject *self, PyObject *obj)
@ -623,6 +629,7 @@ static PyMethodDef test_methods[] = {
{"object_delattr", object_delattr, METH_VARARGS}, {"object_delattr", object_delattr, METH_VARARGS},
{"object_delattrstring", object_delattrstring, METH_VARARGS}, {"object_delattrstring", object_delattrstring, METH_VARARGS},
{"number_check", number_check, METH_O},
{"mapping_check", mapping_check, METH_O}, {"mapping_check", mapping_check, METH_O},
{"mapping_size", mapping_size, METH_O}, {"mapping_size", mapping_size, METH_O},
{"mapping_length", mapping_length, METH_O}, {"mapping_length", mapping_length, METH_O},