File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -3767,6 +3767,33 @@ def test_del__CHUNK_SIZE_SystemError(self):
3767
3767
with self .assertRaises (AttributeError ):
3768
3768
del t ._CHUNK_SIZE
3769
3769
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
+
3770
3797
3771
3798
class PyTextIOWrapperTest (TextIOWrapperTest ):
3772
3799
io = pyio
You can’t perform that action at this time.
0 commit comments