@@ -59,7 +59,7 @@ def test_delegates_to_sock_sendall(self):
5959
6060
6161class TestNetworkingInterfaceBase (AsyncUnitTest ):
62- def setUp (self ):
62+ async def asyncSetUp (self ):
6363 self .base = NetworkingInterfaceBase (MagicMock ())
6464
6565 def test_gettimeout_raises (self ):
@@ -181,7 +181,7 @@ async def test_default_timeout_is_none(self):
181181 self .assertIsNone (protocol .gettimeout )
182182
183183 async def test_normal_op_msg (self ):
184- header = _make_header (32 , 1 , 99 , 2013 )
184+ header = _make_header (length = 32 , request_id = 1 , response_to = 99 , op_code = 2013 )
185185 protocol = await self ._make_proto_with_header (header )
186186 body_len , op_code , response_to , expecting_compression = protocol .process_header ()
187187 self .assertEqual (body_len , 16 )
@@ -190,41 +190,45 @@ async def test_normal_op_msg(self):
190190 self .assertFalse (expecting_compression )
191191
192192 async def test_op_compressed (self ):
193- # OP_COMPRESSED=2012, length=35 → adjusted=35-9=26 → body=26-16=10
194- header = _make_header (35 , 1 , 0 , 2012 )
193+ # OP_COMPRESSED=2012; process_header strips the 9-byte compression sub-header
194+ # (op code + uncompressed size + compressor id), then the 16-byte standard header.
195+ # length=35 → after compression sub-header: 26 → body: 10
196+ header = _make_header (length = 35 , request_id = 1 , response_to = 0 , op_code = 2012 )
195197 protocol = await self ._make_proto_with_header (header )
196198 body_len , op_code , _response_to , expecting_compression = protocol .process_header ()
197199 self .assertEqual (body_len , 10 )
198200 self .assertEqual (op_code , 2012 )
199201 self .assertTrue (expecting_compression )
200202
201203 async def test_op_compressed_length_too_small_raises (self ):
202- header = _make_header (25 , 1 , 0 , 2012 )
204+ header = _make_header (length = 25 , request_id = 1 , response_to = 0 , op_code = 2012 )
203205 protocol = await self ._make_proto_with_header (header )
204206 with self .assertRaises (ProtocolError ):
205207 protocol .process_header ()
206208
207209 async def test_non_compressed_length_too_small_raises (self ):
208- header = _make_header (16 , 1 , 0 , 2013 )
210+ header = _make_header (length = 16 , request_id = 1 , response_to = 0 , op_code = 2013 )
209211 protocol = await self ._make_proto_with_header (header )
210212 with self .assertRaises (ProtocolError ):
211213 protocol .process_header ()
212214
213215 async def test_length_exceeds_max_raises (self ):
214- header = _make_header (MAX_MESSAGE_SIZE + 1 , 1 , 0 , 2013 )
216+ header = _make_header (
217+ length = MAX_MESSAGE_SIZE + 1 , request_id = 1 , response_to = 0 , op_code = 2013
218+ )
215219 protocol = await self ._make_proto_with_header (header )
216220 with self .assertRaises (ProtocolError ):
217221 protocol .process_header ()
218222
219223 async def test_op_reply_op_code (self ):
220- header = _make_header (20 , 0 , 0 , 1 )
224+ header = _make_header (length = 20 , request_id = 0 , response_to = 0 , op_code = 1 )
221225 protocol = await self ._make_proto_with_header (header )
222226 body_len , op_code , _response_to , expecting_compression = protocol .process_header ()
223227 self .assertEqual (body_len , 4 )
224228 self .assertEqual (op_code , 1 )
225229 self .assertFalse (expecting_compression )
226230
227- async def test_compression_header_returns_op_code_and_compressor_id (self ):
231+ async def test_compression_header_snappy_compressor_id (self ):
228232 protocol = await _make_protocol ()
229233 # <iiB: little-endian, i32 op code=2013, i32 uncompressed size=0, u8 compressor id=1 (snappy)
230234 data = struct .pack ("<iiB" , 2013 , 0 , 1 )
@@ -277,9 +281,8 @@ async def test_close_with_exception_propagates_to_pending(self):
277281 protocol ._pending_messages .append (future )
278282 exc = OSError ("connection reset" )
279283 protocol .close (exc )
280- with self .assertRaises (OSError ) as ctx :
284+ with self .assertRaisesRegex (OSError , "connection reset" ) :
281285 await future
282- self .assertIn ("connection reset" , str (ctx .exception ))
283286
284287 class TestAsyncSocketReceive (AsyncUnitTest ):
285288 async def test_reads_full_data_in_one_call (self ):
0 commit comments