[3.13] gh-119506: fix _io.TextIOWrapper.write() write during flush (GH-119507) (#119964)

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:
Miss Islington (bot) 2024-06-19 12:11:07 +02:00 committed by GitHub
parent d65e145f9d
commit 9be94f9ce6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 9 deletions

View file

@ -4016,6 +4016,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