FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-94808: Add coverage test for number check by ekohilas · Pull Request #111445 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions Lib/test/test_capi/test_abstract.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,13 @@ def test_sequence_tuple(self):
self.assertRaises(TypeError, xtuple, 42)
self.assertRaises(SystemError, xtuple, NULL)

def test_number_check(self):
number_check = _testcapi.number_check
Comment thread
ekohilas marked this conversation as resolved.
self.assertTrue(number_check(1 + 1j))
Comment thread
ekohilas marked this conversation as resolved.
self.assertTrue(number_check(1))
self.assertTrue(number_check(0.5))
self.assertFalse(number_check("1 + 1j"))


if __name__ == "__main__":
unittest.main()
7 changes: 7 additions & 0 deletions Modules/_testcapi/abstract.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down

Back | FazBrowse Home | New Git URL