mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
[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:
parent
d65e145f9d
commit
9be94f9ce6
3 changed files with 45 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue