Skip to content

Commit 3dbeb31

Browse files
committed
tests: patch consumer
1 parent b7fdaeb commit 3dbeb31

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

test/conftest.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,53 @@
33
import pytest
44
from manager.manager.manager import Manager
55

6-
# Patch Server and FileWatchdog to avoid starting real servers
7-
86

97
class DummyServer:
8+
"""A dummy server class to simulate server behavior for testing purposes."""
9+
1010
def __init__(self, host, port, loglevel):
11+
"""Initialize the DummyServer with host, port, and loglevel."""
1112
self.host = host
1213
self.port = port
1314
self.loglevel = loglevel
1415

1516
def set_fn_new_client(self, fn):
17+
"""Set the function to be called when a new client connects."""
1618
pass
1719

1820
def set_fn_client_left(self, fn):
21+
"""Set the function to be called when a client leaves."""
1922
pass
2023

2124
def set_fn_message_received(self, fn):
25+
"""Set the function to be called when a message is received."""
2226
pass
2327

2428
def deny_new_connections(self):
29+
"""Simulate denying new connections (dummy implementation)."""
2530
pass
2631

2732
def allow_new_connections(self):
33+
"""Simulate allowing new connections (dummy implementation)."""
2834
pass
2935

3036
def send_message(self, client, message):
37+
"""Simulate sending a message to a client (dummy implementation)."""
3138
pass
3239

3340
def run_forever(self, threaded=True):
41+
"""Simulate running the server forever (dummy implementation)."""
3442
pass
3543

3644
def shutdown_gracefully(self):
45+
"""Simulate graceful shutdown of the server (dummy implementation)."""
3746
pass
3847

3948

4049
class DummyConsumer:
4150
"""A dummy consumer to capture messages sent by the Manager."""
4251

43-
def __init__(self):
52+
def __init__(self, host=None, port=None, queue=None):
4453
"""
4554
Initialize the DummyConsumer with empty message storage.
4655
@@ -68,6 +77,7 @@ def manager(monkeypatch):
6877
"""Fixture to provide a Manager instance with patched dependencies for testing."""
6978

7079
monkeypatch.setattr("manager.comms.websocket_server.WebsocketServer", DummyServer)
80+
monkeypatch.setattr("manager.manager.manager.ManagerConsumer", DummyConsumer)
7181

7282
# Patch subprocess.check_output for ROS_DISTRO and IMAGE_TAG
7383
def fake_check_output(cmd, *a, **k):
@@ -143,5 +153,4 @@ def terminate(self):
143153

144154
# Setup Manager with dummy consumer
145155
m = Manager(host="localhost", port=12345)
146-
m.consumer = DummyConsumer()
147156
return m

0 commit comments

Comments
 (0)