mirror of https://github.com/python/cpython
gh-94808: Add coverage test for number check (gh-111445)
This commit is contained in:
parent
3ac9851d69
commit
842e5fcdcd
|
@ -817,6 +817,13 @@ class CAPITest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, xtuple, 42)
|
||||
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__":
|
||||
unittest.main()
|
||||
|
|
|
@ -180,6 +180,12 @@ object_delattrstring(PyObject *self, PyObject *args)
|
|||
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 *
|
||||
mapping_check(PyObject *self, PyObject *obj)
|
||||
|
@ -623,6 +629,7 @@ static PyMethodDef test_methods[] = {
|
|||
{"object_delattr", object_delattr, METH_VARARGS},
|
||||
{"object_delattrstring", object_delattrstring, METH_VARARGS},
|
||||
|
||||
{"number_check", number_check, METH_O},
|
||||
{"mapping_check", mapping_check, METH_O},
|
||||
{"mapping_size", mapping_size, METH_O},
|
||||
{"mapping_length", mapping_length, METH_O},
|
||||
|
|
Loading…
Reference in New Issue