@@ -959,7 +959,7 @@ def test_write_sendmsg_full(self):
959959 @unittest .skipUnless (selector_events ._HAS_SENDMSG , 'no sendmsg' )
960960 def test_write_sendmsg_partial (self ):
961961 data = b'data'
962- for buf in data , memoryview (data ):
962+ for buf in data , bytearray ( data ), memoryview (data ):
963963 with self .subTest (type = type (buf ).__name__ ):
964964 self .sock .sendmsg = mock .Mock ()
965965 # Sent partial data
@@ -973,7 +973,15 @@ def test_write_sendmsg_partial(self):
973973 self .assertTrue (self .loop .writers )
974974 self .assertEqual (list_to_buffer ([b'ta' ]), transport ._buffer )
975975 # gh-159503: the remainder is a view, not a copy
976- self .assertIs (transport ._buffer [0 ].obj , data )
976+ rest = transport ._buffer [0 ]
977+ self .assertIsInstance (rest , memoryview )
978+ self .assertIs (
979+ rest .obj ,
980+ buf .obj if isinstance (buf , memoryview ) else buf )
981+ if isinstance (buf , bytearray ):
982+ # The unsent view pins the bytearray against resizing.
983+ with self .assertRaises (BufferError ):
984+ buf .append (0 )
977985
978986 @unittest .skipUnless (selector_events ._HAS_SENDMSG , 'no sendmsg' )
979987 def test_write_sendmsg_half_buffer (self ):
@@ -1075,7 +1083,7 @@ def test_write_ready_no_data(self):
10751083
10761084 def test_write_ready_partial (self ):
10771085 data = b'data'
1078- for buf in data , memoryview (data ):
1086+ for buf in data , bytearray ( data ), memoryview (data ):
10791087 with self .subTest (type = type (buf ).__name__ ):
10801088 self .sock .send .return_value = 2
10811089
@@ -1086,7 +1094,15 @@ def test_write_ready_partial(self):
10861094 self .loop .assert_writer (7 , transport ._write_ready )
10871095 self .assertEqual (list_to_buffer ([b'ta' ]), transport ._buffer )
10881096 # gh-159503: the remainder is a view, not a copy
1089- self .assertIs (transport ._buffer [0 ].obj , data )
1097+ rest = transport ._buffer [0 ]
1098+ self .assertIsInstance (rest , memoryview )
1099+ self .assertIs (
1100+ rest .obj ,
1101+ buf .obj if isinstance (buf , memoryview ) else buf )
1102+ if isinstance (buf , bytearray ):
1103+ # The unsent view pins the bytearray against resizing.
1104+ with self .assertRaises (BufferError ):
1105+ buf .append (0 )
10901106
10911107 def test_write_ready_partial_none (self ):
10921108 data = b'data'
0 commit comments