mirror of
https://github.com/python/cpython.git
synced 2025-09-11 03:07:01 +00:00
gh-109523: Raise a BlockingIOError if reading text from a non-blocking stream cannot immediately return bytes. (GH-122933)
This commit is contained in:
parent
930ba0ce60
commit
31f16e427b
7 changed files with 57 additions and 1 deletions
|
@ -3932,6 +3932,22 @@ class TextIOWrapperTest(unittest.TestCase):
|
|||
f.write(res)
|
||||
self.assertEqual(res + f.readline(), 'foo\nbar\n')
|
||||
|
||||
@unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
|
||||
def test_read_non_blocking(self):
|
||||
import os
|
||||
r, w = os.pipe()
|
||||
try:
|
||||
os.set_blocking(r, False)
|
||||
with self.io.open(r, 'rt') as textfile:
|
||||
r = None
|
||||
# Nothing has been written so a non-blocking read raises a BlockingIOError exception.
|
||||
with self.assertRaises(BlockingIOError):
|
||||
textfile.read()
|
||||
finally:
|
||||
if r is not None:
|
||||
os.close(r)
|
||||
os.close(w)
|
||||
|
||||
|
||||
class MemviewBytesIO(io.BytesIO):
|
||||
'''A BytesIO object whose read method returns memoryviews
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue