diff options
author | Victor Stinner <vstinner@python.org> | 2024-03-14 09:28:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-14 09:28:58 (GMT) |
commit | d4028724f2c8c674202615b772913765423c69fd (patch) | |
tree | bb85d9e391bbcf68a21e4a7008712467a4d22f90 /Lib | |
parent | a18c9854e8c255981f07c0a1c1503253f85b7540 (diff) | |
download | cpython-d4028724f2c8c674202615b772913765423c69fd.zip cpython-d4028724f2c8c674202615b772913765423c69fd.tar.gz cpython-d4028724f2c8c674202615b772913765423c69fd.tar.bz2 |
gh-116646: Add limited C API support to AC fildes converter (#116769)
Add tests on the "fildes" converter to _testclinic_limited.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_clinic.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index cf3eeaa..a60f087 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -3698,6 +3698,39 @@ class LimitedCAPIFunctionalTest(unittest.TestCase): with self.assertRaises(TypeError): func(1., "2") + def test_get_file_descriptor(self): + # test 'file descriptor' converter: call PyObject_AsFileDescriptor() + get_fd = _testclinic_limited.get_file_descriptor + + class MyInt(int): + pass + + class MyFile: + def __init__(self, fd): + self._fd = fd + def fileno(self): + return self._fd + + for fd in (0, 1, 2, 5, 123_456): + self.assertEqual(get_fd(fd), fd) + + myint = MyInt(fd) + self.assertEqual(get_fd(myint), fd) + + myfile = MyFile(fd) + self.assertEqual(get_fd(myfile), fd) + + with self.assertRaises(OverflowError): + get_fd(2**256) + with self.assertWarnsRegex(RuntimeWarning, + "bool is used as a file descriptor"): + get_fd(True) + with self.assertRaises(TypeError): + get_fd(1.0) + with self.assertRaises(TypeError): + get_fd("abc") + with self.assertRaises(TypeError): + get_fd(None) class PermutationTests(unittest.TestCase): |