mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.13] gh-71253: Match _io exception in _pyio (gh-133985) (gh-134431)
Test was only testing _io, expanded to cover _pyio.
(cherry picked from commit 06eaf4055c
)
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
parent
de6d199c1d
commit
046125e5b6
3 changed files with 7 additions and 3 deletions
|
@ -1559,7 +1559,8 @@ class FileIO(RawIOBase):
|
|||
if not isinstance(fd, int):
|
||||
raise TypeError('expected integer from opener')
|
||||
if fd < 0:
|
||||
raise OSError('Negative file descriptor')
|
||||
# bpo-27066: Raise a ValueError for bad value.
|
||||
raise ValueError(f'opener returned {fd}')
|
||||
owned_fd = fd
|
||||
if not noinherit_flag:
|
||||
os.set_inheritable(fd, False)
|
||||
|
|
|
@ -894,7 +894,7 @@ class IOTest(unittest.TestCase):
|
|||
def badopener(fname, flags):
|
||||
return -1
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
open('non-existent', 'r', opener=badopener)
|
||||
self.open('non-existent', 'r', opener=badopener)
|
||||
self.assertEqual(str(cm.exception), 'opener returned -1')
|
||||
|
||||
def test_bad_opener_other_negative(self):
|
||||
|
@ -902,7 +902,7 @@ class IOTest(unittest.TestCase):
|
|||
def badopener(fname, flags):
|
||||
return -2
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
open('non-existent', 'r', opener=badopener)
|
||||
self.open('non-existent', 'r', opener=badopener)
|
||||
self.assertEqual(str(cm.exception), 'opener returned -2')
|
||||
|
||||
def test_opener_invalid_fd(self):
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Raise :exc:`ValueError` in :func:`open` if *opener* returns a negative
|
||||
file-descriptor in the Python implementation of :mod:`io` to match the
|
||||
C implementation.
|
Loading…
Add table
Add a link
Reference in a new issue