|
3 | 3 | import pytest |
4 | 4 | from manager.manager.manager import Manager |
5 | 5 |
|
6 | | -# Patch Server and FileWatchdog to avoid starting real servers |
7 | | - |
8 | 6 |
|
9 | 7 | class DummyServer: |
| 8 | + """A dummy server class to simulate server behavior for testing purposes.""" |
| 9 | + |
10 | 10 | def __init__(self, host, port, loglevel): |
| 11 | + """Initialize the DummyServer with host, port, and loglevel.""" |
11 | 12 | self.host = host |
12 | 13 | self.port = port |
13 | 14 | self.loglevel = loglevel |
14 | 15 |
|
15 | 16 | def set_fn_new_client(self, fn): |
| 17 | + """Set the function to be called when a new client connects.""" |
16 | 18 | pass |
17 | 19 |
|
18 | 20 | def set_fn_client_left(self, fn): |
| 21 | + """Set the function to be called when a client leaves.""" |
19 | 22 | pass |
20 | 23 |
|
21 | 24 | def set_fn_message_received(self, fn): |
| 25 | + """Set the function to be called when a message is received.""" |
22 | 26 | pass |
23 | 27 |
|
24 | 28 | def deny_new_connections(self): |
| 29 | + """Simulate denying new connections (dummy implementation).""" |
25 | 30 | pass |
26 | 31 |
|
27 | 32 | def allow_new_connections(self): |
| 33 | + """Simulate allowing new connections (dummy implementation).""" |
28 | 34 | pass |
29 | 35 |
|
30 | 36 | def send_message(self, client, message): |
| 37 | + """Simulate sending a message to a client (dummy implementation).""" |
31 | 38 | pass |
32 | 39 |
|
33 | 40 | def run_forever(self, threaded=True): |
| 41 | + """Simulate running the server forever (dummy implementation).""" |
34 | 42 | pass |
35 | 43 |
|
36 | 44 | def shutdown_gracefully(self): |
| 45 | + """Simulate graceful shutdown of the server (dummy implementation).""" |
37 | 46 | pass |
38 | 47 |
|
39 | 48 |
|
40 | 49 | class DummyConsumer: |
41 | 50 | """A dummy consumer to capture messages sent by the Manager.""" |
42 | 51 |
|
43 | | - def __init__(self): |
| 52 | + def __init__(self, host=None, port=None, queue=None): |
44 | 53 | """ |
45 | 54 | Initialize the DummyConsumer with empty message storage. |
46 | 55 |
|
@@ -68,6 +77,7 @@ def manager(monkeypatch): |
68 | 77 | """Fixture to provide a Manager instance with patched dependencies for testing.""" |
69 | 78 |
|
70 | 79 | monkeypatch.setattr("manager.comms.websocket_server.WebsocketServer", DummyServer) |
| 80 | + monkeypatch.setattr("manager.manager.manager.ManagerConsumer", DummyConsumer) |
71 | 81 |
|
72 | 82 | # Patch subprocess.check_output for ROS_DISTRO and IMAGE_TAG |
73 | 83 | def fake_check_output(cmd, *a, **k): |
@@ -143,5 +153,4 @@ def terminate(self): |
143 | 153 |
|
144 | 154 | # Setup Manager with dummy consumer |
145 | 155 | m = Manager(host="localhost", port=12345) |
146 | | - m.consumer = DummyConsumer() |
147 | 156 | return m |
0 commit comments