2424import asyncio
2525import struct
2626import sys
27- import unittest
2827from unittest .mock import AsyncMock , MagicMock , patch
2928
3029sys .path [0 :0 ] = ["" ]
3130
31+ from test import unittest
32+
3233from pymongo .common import MAX_MESSAGE_SIZE
3334from pymongo .errors import ProtocolError
3435from pymongo .network_layer import (
4546# ---------------------------------------------------------------------------
4647
4748
48- def _run (coro ):
49- """Run a coroutine synchronously for testing."""
50- return asyncio .run (coro )
49+ def _run (coroutine ):
50+ return asyncio .run (coroutine )
5151
5252
5353async def _make_protocol (timeout = None ):
54- """Create a PyMongoProtocol with a stubbed transport."""
5554 proto = PyMongoProtocol (timeout = timeout )
5655 mock_transport = MagicMock ()
5756 mock_transport .is_closing .return_value = False
@@ -60,7 +59,6 @@ async def _make_protocol(timeout=None):
6059
6160
6261def _make_header (length , request_id , response_to , op_code ):
63- """Pack a 16-byte MongoDB wire-protocol header."""
6462 return struct .pack ("<iiii" , length , request_id , response_to , op_code )
6563
6664
@@ -141,7 +139,7 @@ def test_fileno_delegates(self):
141139 self .assertEqual (self .iface .fileno (), 42 )
142140
143141 def test_recv_into_delegates (self ):
144- buf = bytearray (10 )
142+ buf = memoryview ( bytearray (10 ) )
145143 self .mock_sock .recv_into .return_value = 7
146144 result = self .iface .recv_into (buf )
147145 self .assertEqual (result , 7 )
@@ -282,7 +280,7 @@ class TestPyMongoProtocolProcessCompressionHeader(unittest.TestCase):
282280 def test_returns_op_code_and_compressor_id (self ):
283281 async def _test ():
284282 proto = await _make_protocol ()
285- # op_code=2013, unknown int =0, compressor_id=1 (snappy)
283+ # op_code=2013, uncompressed_size =0, compressor_id=1 (snappy)
286284 data = struct .pack ("<iiB" , 2013 , 0 , 1 )
287285 proto ._compression_header = memoryview (bytearray (data ))
288286 return proto .process_compression_header ()
0 commit comments