Skip to content

Commit 05ab6e0

Browse files
committed
Add test
1 parent 9572c1e commit 05ab6e0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_io.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,6 +3767,33 @@ def test_del__CHUNK_SIZE_SystemError(self):
37673767
with self.assertRaises(AttributeError):
37683768
del t._CHUNK_SIZE
37693769

3770+
def test_internal_buffer_size(self):
3771+
# bpo-43260: TextIOWrapper's internal buffer should not store
3772+
# data larger than chunk size.
3773+
chunk_size = 8192 # default chunk size, updated later
3774+
3775+
class MockIO(self.MockRawIO):
3776+
def write(self, data):
3777+
if len(data) > chunk_size:
3778+
raise RuntimeError
3779+
return super().write(data)
3780+
3781+
buf = MockIO()
3782+
t = self.TextIOWrapper(buf, encoding="ascii")
3783+
chunk_size = t._CHUNK_SIZE
3784+
t.write("abc")
3785+
t.write("def")
3786+
# default chunk size is 8192 bytes so t don't write data to buf.
3787+
self.assertEqual([], buf._write_stack)
3788+
3789+
with self.assertRaises(RuntimeError):
3790+
t.write("x"*(chunk_size+1))
3791+
3792+
self.assertEqual([b"abcdef"], buf._write_stack)
3793+
t.write("ghi")
3794+
t.write("x"*chunk_size)
3795+
self.assertEqual([b"abcdef", b"ghi", b"x"*chunk_size], buf._write_stack)
3796+
37703797

37713798
class PyTextIOWrapperTest(TextIOWrapperTest):
37723799
io = pyio

0 commit comments

Comments
 (0)