Skip to content

Commit f5b3642

Browse files
committed
chore: Address co-pilot review feedback
1 parent d6c0e41 commit f5b3642

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

tests/fixtures/local_async_fixtures.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import asyncio
2+
import logging
3+
import warnings
24
from collections.abc import Awaitable, Callable, Generator
35
from typing import Any
46
from unittest.mock import Mock, patch
57

68
import pytest
79

10+
_LOGGER = logging.getLogger(__name__)
11+
812
AsyncLocalRequestHandler = Callable[[bytes], Awaitable[bytes | None]]
913

1014

@@ -16,10 +20,11 @@ def received_requests_fixture() -> asyncio.Queue[bytes]:
1620

1721
@pytest.fixture(name="local_response_queue")
1822
def response_queue_fixture() -> Generator[asyncio.Queue[bytes], None, None]:
19-
"""Fixture that provides access to the received requests."""
23+
"""Fixture that provides a queue of responses to be sent to the client."""
2024
response_queue: asyncio.Queue[bytes] = asyncio.Queue()
2125
yield response_queue
22-
# assert response_queue.empty(), "Not all fake responses were consumed"
26+
if not response_queue.empty():
27+
warnings.warn("Some enqueued local device responses were not consumed during the test")
2328

2429

2530
@pytest.fixture(name="local_async_request_handler")

tests/fixtures/pahomqtt_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def received_requests_fixture() -> Queue[bytes]:
7373

7474
@pytest.fixture(name="mqtt_response_queue")
7575
def response_queue_fixture() -> Generator[Queue[bytes], None, None]:
76-
"""Fixture that provides access to the received requests."""
76+
"""Fixture that provides a queue for enqueueing responses to be sent to the client under test."""
7777
response_queue: Queue[bytes] = Queue()
7878
yield response_queue
7979
assert response_queue.empty(), "Not all fake responses were consumed"

tests/test_local_api_v1.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import asyncio
44
import json
55
import logging
6-
from asyncio import Protocol
76
from collections.abc import AsyncGenerator, Callable, Generator
87
from queue import Queue
98
from typing import Any
109
from unittest.mock import Mock, patch
10+
import warnings
1111

1212
import pytest
1313
import syrupy
@@ -42,10 +42,11 @@ def received_requests_fixture() -> Queue[bytes]:
4242

4343
@pytest.fixture(name="local_response_queue")
4444
def response_queue_fixture() -> Generator[Queue[bytes], None, None]:
45-
"""Fixture that provides access to the received requests."""
45+
"""Fixture that provides a queue for enqueueing responses to be sent back to the client under test."""
4646
response_queue: Queue[bytes] = Queue()
4747
yield response_queue
48-
assert response_queue.empty(), "Not all fake responses were consumed"
48+
if not response_queue.empty():
49+
warnings.warn("Not all fake responses were consumed")
4950

5051

5152
@pytest.fixture(name="local_request_handler")
@@ -72,7 +73,7 @@ def create_local_connection_fixture(
7273
) -> Generator[None, None, None]:
7374
"""Fixture that overrides the transport creation to wire it up to the mock socket."""
7475

75-
async def create_connection(protocol_factory: Callable[[], Protocol], *args) -> tuple[Any, Any]:
76+
async def create_connection(protocol_factory: Callable[[], asyncio.Protocol], *args) -> tuple[Any, Any]:
7677
protocol = protocol_factory()
7778

7879
def handle_write(data: bytes) -> None:

0 commit comments

Comments
 (0)