@@ -871,6 +871,22 @@ def test_RawIOBase_read(self):
871871 self .assertEqual (rawio .read (2 ), None )
872872 self .assertEqual (rawio .read (2 ), b"" )
873873
874+ def test_RawIOBase_read_bounds_checking (self ):
875+ # Make sure a `.readinto` call which returns a value outside
876+ # (0, len(buffer)) raises.
877+ class Misbehaved (self .RawIOBase ):
878+ def __init__ (self , readinto_return ) -> None :
879+ self ._readinto_return = readinto_return
880+ def readinto (self , b ):
881+ return self ._readinto_return
882+
883+ with self .assertRaises (ValueError ) as cm :
884+ Misbehaved (2 ).read (1 )
885+ self .assertEqual (str (cm .exception ), "readinto returned 2 outside buffer size 1" )
886+ for bad_size in (2147483647 , sys .maxsize , - 1 , - 1000 ):
887+ with self .assertRaises (ValueError ):
888+ Misbehaved (bad_size ).read ()
889+
874890 def test_types_have_dict (self ):
875891 test = (
876892 self .IOBase (),
@@ -1819,7 +1835,6 @@ def test_bad_readinto_value(self):
18191835 bufio .readline ()
18201836 self .assertIsNone (cm .exception .__cause__ )
18211837
1822- @unittest .expectedFailure # TODO: RUSTPYTHON; TypeError: 'bytes' object cannot be interpreted as an integer")
18231838 def test_bad_readinto_type (self ):
18241839 rawio = self .tp (self .BytesIO (b"12" ))
18251840 rawio .readinto = lambda buf : b''
@@ -1955,7 +1970,6 @@ def _seekrel(bufio):
19551970 def test_writes_and_truncates (self ):
19561971 self .check_writes (lambda bufio : bufio .truncate (bufio .tell ()))
19571972
1958- @unittest .expectedFailure # TODO: RUSTPYTHON
19591973 def test_write_non_blocking (self ):
19601974 raw = self .MockNonBlockWriterIO ()
19611975 bufio = self .tp (raw , 8 )
@@ -4281,7 +4295,6 @@ def test_reconfigure_write_through(self):
42814295 def test_repr (self ):
42824296 return super ().test_repr ()
42834297
4284- @unittest .expectedFailure # TODO: RUSTPYTHON
42854298 def test_uninitialized (self ):
42864299 return super ().test_uninitialized ()
42874300
@@ -4654,14 +4667,12 @@ def test_pickling(self):
46544667 with self .assertRaisesRegex (TypeError , msg ):
46554668 pickle .dumps (f , protocol )
46564669
4657- @unittest .expectedFailure # TODO: RUSTPYTHON
46584670 @unittest .skipIf (
46594671 support .is_emscripten , "fstat() of a pipe fd is not supported"
46604672 )
46614673 def test_nonblock_pipe_write_bigbuf (self ):
46624674 self ._test_nonblock_pipe_write (16 * 1024 )
46634675
4664- @unittest .expectedFailure # TODO: RUSTPYTHON
46654676 @unittest .skipIf (
46664677 support .is_emscripten , "fstat() of a pipe fd is not supported"
46674678 )
@@ -4825,6 +4836,14 @@ class CMiscIOTest(MiscIOTest):
48254836 name_of_module = "io" , "_io"
48264837 extra_exported = "BlockingIOError" ,
48274838
4839+ @unittest .expectedFailure # TODO: RUSTPYTHON; BufferedWriter seeks on non-seekable pipe
4840+ def test_nonblock_pipe_write_bigbuf (self ):
4841+ return super ().test_nonblock_pipe_write_bigbuf ()
4842+
4843+ @unittest .expectedFailure # TODO: RUSTPYTHON; BufferedWriter seeks on non-seekable pipe
4844+ def test_nonblock_pipe_write_smallbuf (self ):
4845+ return super ().test_nonblock_pipe_write_smallbuf ()
4846+
48284847 @unittest .expectedFailure # TODO: RUSTPYTHON
48294848 def test_warn_on_dealloc (self ):
48304849 return super ().test_warn_on_dealloc ()
0 commit comments