summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2022-11-25 12:55:26 (GMT)
committerGitHub <noreply@github.com>2022-11-25 12:55:26 (GMT)
commitd386115039e75c332c8471c239cf7dc5dee791a7 (patch)
tree8a75a98e6bffea8269616d9e16bef7fd0b6277ae /Lib
parentb1dcdefc3abf496a3e37e12b85dd9959f5b70341 (diff)
downloadcpython-d386115039e75c332c8471c239cf7dc5dee791a7.zip
cpython-d386115039e75c332c8471c239cf7dc5dee791a7.tar.gz
cpython-d386115039e75c332c8471c239cf7dc5dee791a7.tar.bz2
bpo-38031: Fix a possible assertion failure in _io.FileIO() (#GH-5688)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_io.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index bc6071f..c927f15 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -888,6 +888,14 @@ class IOTest(unittest.TestCase):
open('non-existent', 'r', opener=badopener)
self.assertEqual(str(cm.exception), 'opener returned -2')
+ def test_opener_invalid_fd(self):
+ # Check that OSError is raised with error code EBADF if the
+ # opener returns an invalid file descriptor (see gh-82212).
+ fd = os_helper.make_bad_fd()
+ with self.assertRaises(OSError) as cm:
+ self.open('foo', opener=lambda name, flags: fd)
+ self.assertEqual(cm.exception.errno, errno.EBADF)
+
def test_fileio_closefd(self):
# Issue #4841
with self.open(__file__, 'rb') as f1, \