Skip to content

Commit f6eb99f

Browse files
committed
chore: share test fixtures
1 parent 66e828b commit f6eb99f

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
from roborock.version_1_apis.roborock_mqtt_client_v1 import RoborockMqttClientV1
2121
from tests.mock_data import HOME_DATA_RAW, HOME_DATA_SCENES_RAW, TEST_LOCAL_API_HOST, USER_DATA
2222

23+
# Fixtures for the newer APIs in subdirectories
24+
pytest_plugins = [
25+
"tests.mqtt_fixtures",
26+
]
27+
2328
_LOGGER = logging.getLogger(__name__)
2429

2530

tests/e2e/test_local_session.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def build_response(
7979
return encoder(msg)
8080

8181

82-
async def test_connect(local_channel: LocalChannel, response_queue: Queue[bytes], received_requests: Queue[bytes]):
82+
async def test_connect(
83+
local_channel: LocalChannel, response_queue: Queue[bytes], received_requests: Queue[bytes]
84+
) -> None:
8385
"""Test connecting to the device."""
8486
# Queue HELLO response with payload to ensure it can be parsed
8587
response_queue.put(build_response(RoborockMessageProtocol.HELLO_RESPONSE, 1, payload=b"ok", random=TEST_RANDOM))
@@ -101,7 +103,9 @@ async def test_connect(local_channel: LocalChannel, response_queue: Queue[bytes]
101103
assert int.from_bytes(protocol_bytes, "big") == RoborockMessageProtocol.HELLO_REQUEST
102104

103105

104-
async def test_send_command(local_channel: LocalChannel, response_queue: Queue[bytes], received_requests: Queue[bytes]):
106+
async def test_send_command(
107+
local_channel: LocalChannel, response_queue: Queue[bytes], received_requests: Queue[bytes]
108+
) -> None:
105109
"""Test sending a command."""
106110
# Queue HELLO response
107111
response_queue.put(build_response(RoborockMessageProtocol.HELLO_RESPONSE, 1, payload=b"ok", random=TEST_RANDOM))

tests/e2e/test_mqtt_session.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
These tests use a fake MQTT broker to verify the session implementation. We
44
mock out the lower level socket connections to simulate a broker which gets us
55
close to an "end to end" test without needing an actual MQTT broker server.
6+
7+
These are higher level tests that the similar tests in tests/mqtt/test_roborock_session.py
8+
which use mocks to verify specific behaviors.
69
"""
710

811
from collections.abc import AsyncGenerator, Callable
@@ -16,10 +19,7 @@
1619
from roborock.roborock_message import RoborockMessage, RoborockMessageProtocol
1720
from tests import mqtt_packet
1821
from tests.mock_data import LOCAL_KEY
19-
from tests.mqtt.common import (
20-
FAKE_PARAMS,
21-
Subscriber,
22-
)
22+
from tests.mqtt_fixtures import FAKE_PARAMS, Subscriber
2323

2424

2525
@pytest.fixture(autouse=True)
@@ -96,7 +96,7 @@ async def test_session_e2e_publish_message(
9696
) -> None:
9797
"""Test publishing a real Roborock message."""
9898

99-
# Publish a message to the broker
99+
# Publish a message to the brokwer
100100
msg = RoborockMessage(
101101
protocol=RoborockMessageProtocol.RPC_REQUEST,
102102
payload=b'{"method":"get_status"}',

tests/mqtt/test_roborock_session.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from roborock.mqtt.roborock_session import RoborockMqttSession, create_mqtt_session
1212
from roborock.mqtt.session import MqttParams, MqttSessionException, MqttSessionUnauthorized
1313
from tests import mqtt_packet
14-
from tests.mqtt.common import (
15-
FAKE_PARAMS,
16-
Subscriber,
17-
)
14+
from tests.mqtt_fixtures import FAKE_PARAMS, Subscriber
1815

1916

2017
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)