Skip to content

Commit 671dfbf

Browse files
committed
PYTHON-5781 Nit fixes
- Fix mypy type error in test_network_layer.py - Use 'from test import unittest', remove self-evident docstrings from helpers - Fix inaccurate comment: second field in compression header is uncompressed_size
1 parent 0f26878 commit 671dfbf

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

test/test_network_layer.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
import asyncio
2525
import struct
2626
import sys
27-
import unittest
2827
from unittest.mock import AsyncMock, MagicMock, patch
2928

3029
sys.path[0:0] = [""]
3130

31+
from test import unittest
32+
3233
from pymongo.common import MAX_MESSAGE_SIZE
3334
from pymongo.errors import ProtocolError
3435
from pymongo.network_layer import (
@@ -45,13 +46,11 @@
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

5353
async 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

6261
def _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

Comments
 (0)