Skip to content

Commit 7680f35

Browse files
committed
tests: refactoring
1 parent 9104d0a commit 7680f35

2 files changed

Lines changed: 31 additions & 14 deletions

File tree

test/conftest.py

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

6+
# Patch Server and FileWatchdog to avoid starting real servers
7+
8+
9+
class DummyServer:
10+
"""A dummy server to simulate server behavior for testing purposes."""
11+
12+
def __init__(self, port, update_callback):
13+
"""
14+
Initialize the DummyServer with a port and update callback.
15+
16+
Args:
17+
port (int): The port number for the dummy server.
18+
update_callback (callable): The callback function for updates.
19+
"""
20+
self.port = port
21+
self.update_callback = update_callback
22+
self.started = False
23+
24+
def start(self):
25+
"""Simulate starting the dummy server."""
26+
self.started = True
27+
28+
def stop(self):
29+
"""Simulate stopping the dummy server."""
30+
self.started = False
31+
632

733
class DummyConsumer:
834
"""A dummy consumer to capture messages sent by the Manager."""
@@ -71,19 +97,6 @@ def terminate(self):
7197

7298
monkeypatch.setattr("manager.manager.manager.LauncherWorld", DummyLauncherWorld)
7399

74-
# Patch Server and FileWatchdog to avoid starting real servers
75-
class DummyServer:
76-
def __init__(self, port, update_callback):
77-
self.port = port
78-
self.update_callback = update_callback
79-
self.started = False
80-
81-
def start(self):
82-
self.started = True
83-
84-
def stop(self):
85-
self.started = False
86-
87100
class DummyFileWatchdog:
88101
def __init__(self, path, update_callback):
89102
self.path = path

test/test_terminate_transitions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
from transitions import MachineError
5+
from conftest import DummyServer
56
from test_utils import setup_manager_to_application_running
67
from test_utils import setup_manager_to_world_ready
78
from test_utils import setup_manager_to_visualization_ready
@@ -100,10 +101,13 @@ def test_terminate_visualization_valid(manager, monkeypatch):
100101

101102
def test_terminate_visualization_invalid_machine_error(manager, monkeypatch):
102103
"""
103-
Test the valid terminate visualization transition in the Manager.
104+
Test the invalid terminate visualization transition in the Manager.
104105
105106
Ensure that the transition raises an error when executed from an invalid state.
106107
"""
108+
monkeypatch.setattr(
109+
"manager.libs.applications.compatibility.server.Server", DummyServer
110+
)
107111
# Ensure the manager is in a state where it can stop
108112
setup_manager_to_application_running(manager, monkeypatch)
109113

0 commit comments

Comments
 (0)