mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[3.12] gh-119506: fix _io.TextIOWrapper.write()
write during flush (GH-119507) (#119965)
gh-119506: fix `_io.TextIOWrapper.write()` write during flush (GH-119507)
(cherry picked from commit 52586f930f
)
Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
This commit is contained in:
parent
57f955f9af
commit
cde976d85c
3 changed files with 45 additions and 9 deletions
|
@ -4066,6 +4066,28 @@ class CTextIOWrapperTest(TextIOWrapperTest):
|
|||
t.write("x"*chunk_size)
|
||||
self.assertEqual([b"abcdef", b"ghi", b"x"*chunk_size], buf._write_stack)
|
||||
|
||||
def test_issue119506(self):
|
||||
chunk_size = 8192
|
||||
|
||||
class MockIO(self.MockRawIO):
|
||||
written = False
|
||||
def write(self, data):
|
||||
if not self.written:
|
||||
self.written = True
|
||||
t.write("middle")
|
||||
return super().write(data)
|
||||
|
||||
buf = MockIO()
|
||||
t = self.TextIOWrapper(buf)
|
||||
t.write("abc")
|
||||
t.write("def")
|
||||
# writing data which size >= chunk_size cause flushing buffer before write.
|
||||
t.write("g" * chunk_size)
|
||||
t.flush()
|
||||
|
||||
self.assertEqual([b"abcdef", b"middle", b"g"*chunk_size],
|
||||
buf._write_stack)
|
||||
|
||||
|
||||
class PyTextIOWrapperTest(TextIOWrapperTest):
|
||||
io = pyio
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue