Skip to content

Commit 0fabfa9

Browse files
committed
chore: refactor tests to match new transition name
1 parent 85b775a commit 0fabfa9

7 files changed

+115
-97
lines changed

test/conftest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,20 @@ def start(self):
109109
def stop(self):
110110
self.started = False
111111

112-
class DummyVisualizationLauncher:
112+
class DummyToolsLauncher:
113113
def __init__(self, *args, **kwargs):
114114
self.launchers = []
115115

116-
def run(self):
117-
# Simulate running the visualization launcher
116+
def run(self, consumer):
117+
# Simulate running the tools launcher
118118
return
119119

120120
def terminate(self):
121121
pass
122122

123-
monkeypatch.setattr(
124-
"manager.manager.manager.LauncherVisualization", DummyVisualizationLauncher
125-
)
126-
monkeypatch.setattr("manager.manager.manager.Server", DummyServer)
127-
monkeypatch.setattr("manager.manager.manager.FileWatchdog", DummyFileWatchdog)
123+
monkeypatch.setattr("manager.manager.manager.LauncherTools", DummyToolsLauncher)
124+
# monkeypatch.setattr("manager.manager.manager.Server", DummyServer)
125+
# monkeypatch.setattr("manager.manager.manager.FileWatchdog", DummyFileWatchdog)
128126

129127
# Setup Manager with dummy consumer
130128
m = Manager(host="localhost", port=12345)

test/test_connected_to_world_ready.py

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
"""Tests for transitioning Manager from 'connected' to 'world_ready' state."""
22

33
import pytest
4+
from manager.libs.launch_world_model import ConfigurationModel
45
from test_utils import setup_manager_to_connected
6+
from manager.manager.launcher.launcher_robot import worlds
7+
8+
valid_world_cfg = ConfigurationModel(
9+
type=next(iter(worlds)), launch_file_path="/path/to/launch_file.launch"
10+
).model_dump()
11+
12+
valid_robot_cfg = {
13+
"world": None, # No robot specified
14+
"type": next(iter(worlds)), # Use the first world type
15+
"start_pose": [0, 0, 0, 0, 0, 0],
16+
"launch_file_path": "/path/to/robot_launch_file.launch",
17+
}
18+
19+
invalid_world_cfg = {
20+
"world": "bad_world",
21+
"type": next(iter(worlds)),
22+
"launch_file_path": None, # No launch file specified
23+
} # missing launch_file_path
524

625

726
def test_connected_to_world_ready(manager, monkeypatch):
827
"""Test transitioning Manager from 'connected' to 'world_ready' state."""
928
# Initial state should be 'connected'
1029
setup_manager_to_connected(manager, monkeypatch)
1130

12-
# Use ConfigurationModel for valid world config
13-
from manager.libs.launch_world_model import ConfigurationModel
14-
15-
valid_world_cfg = ConfigurationModel(
16-
world="test_world", launch_file_path="/path/to/launch_file.launch"
17-
).model_dump()
18-
event_data = {
19-
"world": valid_world_cfg,
20-
"robot": {
21-
"world": None, # No robot specified
22-
"robot_config": {"name": "test_robot", "type": "simple"},
23-
},
24-
}
31+
event_data = {"world": valid_world_cfg, "robot": valid_robot_cfg}
2532
manager.trigger("launch_world", data=event_data)
2633

2734
# State should now be 'world_ready'
@@ -51,19 +58,18 @@ def fake_validate(cfg):
5158
# Simulate logging error, but return a dummy config to avoid UnboundLocalError
5259
return DummyConfig()
5360

61+
def fake_prepare_custom_universe(cfg):
62+
raise ValueError("Invalid world configuration")
63+
5464
monkeypatch.setattr(
5565
"manager.libs.launch_world_model.ConfigurationManager.validate", fake_validate
5666
)
67+
manager.prepare_custom_universe = fake_prepare_custom_universe
5768

58-
invalid_world_cfg = {"world": "bad_world"} # missing launch_file_path
59-
event_data = {
60-
"world": invalid_world_cfg,
61-
"robot": {
62-
"world": None,
63-
"robot_config": {"name": "test_robot", "type": "simple"},
64-
},
65-
}
66-
manager.trigger("launch_world", data=event_data)
69+
event_data = {"world": invalid_world_cfg, "robot": valid_robot_cfg}
70+
71+
with pytest.raises(ValueError):
72+
manager.trigger("launch_world", data=event_data)
6773
# Assert that world_launcher is created but has no useful config
6874
assert manager.world_launcher is not None
6975
assert (
@@ -91,17 +97,10 @@ def fake_validate(cfg):
9197
"manager.libs.launch_world_model.ConfigurationManager.validate", fake_validate
9298
)
9399

94-
valid_world_cfg = {
95-
"world": "test_world",
96-
"launch_file_path": "/path/to/launch_file.launch",
97-
}
98100
invalid_robot_cfg = {"name": "", "type": ""} # Invalid robot config
99101
event_data = {
100102
"world": valid_world_cfg,
101-
"robot": {
102-
"world": valid_world_cfg,
103-
"robot_config": invalid_robot_cfg,
104-
},
103+
"robot": invalid_robot_cfg,
105104
}
106105

107106
with pytest.raises(ValueError):
@@ -121,17 +120,11 @@ def test_launch_world_with_no_world_config(manager, monkeypatch):
121120
# Initial state should be 'connected'
122121
setup_manager_to_connected(manager, monkeypatch)
123122

124-
# Use ConfigurationModel for valid robot config
125-
from manager.libs.launch_world_model import ConfigurationModel
126-
127-
valid_robot_cfg = ConfigurationModel(
128-
world="test_world", # No world specified
129-
launch_file_path="/path/to/robot_launch_file.launch",
130-
).model_dump()
131123
event_data = {
132124
"world": {
133125
"world": None, # No world specified
134126
"launch_file_path": None, # No launch file specified
127+
"type": None,
135128
}, # No world specified
136129
"robot": valid_robot_cfg,
137130
}
@@ -148,16 +141,13 @@ def test_launch_world_with_no_robot_config(manager, monkeypatch):
148141
# Initial state should be 'connected'
149142
setup_manager_to_connected(manager, monkeypatch)
150143

151-
# Use ConfigurationModel for valid world config
152-
from manager.libs.launch_world_model import ConfigurationModel
153-
154-
valid_world_cfg = ConfigurationModel(
155-
world="test_world", launch_file_path="/path/to/launch_file.launch"
156-
).model_dump()
157-
158144
event_data = {
159145
"world": valid_world_cfg,
160-
"robot": {"world": None, "robot_config": None}, # No robot specified
146+
"robot": {
147+
"world": None,
148+
"robot_config": None,
149+
"type": None,
150+
}, # No robot specified
161151
}
162152
manager.trigger("launch_world", data=event_data)
163153

test/test_resume_and_pause_transitions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from transitions import MachineError
55
from test_utils import setup_manager_to_application_running
6-
from test_utils import setup_manager_to_visualization_ready
6+
from test_utils import setup_manager_to_tools_ready
77

88

99
class DummyProc:
@@ -38,7 +38,7 @@ def test_pause_transition_valid(manager, monkeypatch):
3838
def test_pause_transition_invalid_machine_error(manager, monkeypatch):
3939
"""Test the invalid pause transition in the Manager."""
4040
# Ensure the manager is in a state where it can pause
41-
setup_manager_to_visualization_ready(manager, monkeypatch)
41+
setup_manager_to_tools_ready(manager, monkeypatch)
4242

4343
# Mock needed methods and attributes
4444
monkeypatch.setattr("psutil.Process", lambda pid: DummyProc())
@@ -47,7 +47,7 @@ def test_pause_transition_invalid_machine_error(manager, monkeypatch):
4747
with pytest.raises(MachineError):
4848
manager.trigger("pause")
4949
# Check that the state has changed to 'paused'
50-
assert manager.state == "visualization_ready"
50+
assert manager.state == "tools_ready"
5151

5252

5353
def test_resume_transition_valid(manager, monkeypatch):

test/test_terminate_transitions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from conftest import DummyServer
66
from test_utils import setup_manager_to_application_running
77
from test_utils import setup_manager_to_world_ready
8-
from test_utils import setup_manager_to_visualization_ready
8+
from test_utils import setup_manager_to_tools_ready
99

1010

1111
class DummyProc:
@@ -55,7 +55,7 @@ def dummy_stop_process_and_children(proc):
5555
# Trigger the terminate transition
5656
manager.trigger("terminate_application")
5757
# Check that the state has changed to 'visualization_ready'
58-
assert manager.state == "visualization_ready"
58+
assert manager.state == "tools_ready"
5959

6060

6161
def test_terminate_application_invalid_machine_error(manager, monkeypatch):
@@ -85,21 +85,21 @@ def dummy_stop_process_and_children(proc):
8585
assert manager.state == "world_ready"
8686

8787

88-
def test_terminate_visualization_valid(manager, monkeypatch):
88+
def test_terminate_tools_valid(manager, monkeypatch):
8989
"""Test the valid terminate visualization transition in the Manager."""
9090
# Ensure the manager is in a state where it can stop
91-
setup_manager_to_visualization_ready(manager, monkeypatch)
91+
setup_manager_to_tools_ready(manager, monkeypatch)
9292
# Mock needed methods and attributes
9393
manager.visualization_launcher = DummyVisualizationLauncher()
9494
manager.terminate_harmonic_processes = lambda: None
9595

9696
# Trigger the stop transition
97-
manager.trigger("terminate_visualization")
97+
manager.trigger("terminate_tools")
9898
# Check that the state has changed to 'world_ready'
9999
assert manager.state == "world_ready"
100100

101101

102-
def test_terminate_visualization_invalid_machine_error(manager, monkeypatch):
102+
def test_terminate_tools_invalid_machine_error(manager, monkeypatch):
103103
"""
104104
Test the invalid terminate visualization transition in the Manager.
105105
@@ -113,7 +113,7 @@ def test_terminate_visualization_invalid_machine_error(manager, monkeypatch):
113113

114114
# Trigger the stop transition
115115
with pytest.raises(MachineError):
116-
manager.trigger("terminate_visualization")
116+
manager.trigger("terminate_tools")
117117
# Check that the state has not changed
118118
assert manager.state == "application_running"
119119

test/test_visualization_ready_to_application_running.py renamed to test/test_tools_ready_to_application_running.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
import io
44
import pytest
55
import builtins
6-
from test_utils import setup_manager_to_visualization_ready
6+
from test_utils import setup_manager_to_tools_ready
77

8+
valid_app_data = {
9+
"entrypoint": "main.py",
10+
"linter": "pylint",
11+
"code": "data:base64,ZmFrZV9jb2Rl",
12+
}
813

9-
def test_visualization_ready_to_application_running_valid(manager, monkeypatch):
14+
15+
def test_tools_ready_to_application_running_valid(manager, monkeypatch):
1016
"""
11-
Test transitioning from 'visualization_ready' to 'application_running' state.
17+
Test transitioning from 'tools_ready' to 'application_running' state.
1218
1319
This test verifies the state transitions in case of valid values.
1420
"""
15-
setup_manager_to_visualization_ready(manager, monkeypatch)
21+
setup_manager_to_tools_ready(manager, monkeypatch)
1622

1723
class DummyProc:
1824
def __init__(self):
@@ -59,15 +65,15 @@ def fake_open(file, mode="r", *args, **kwargs):
5965
# Trigger application running state
6066
manager.trigger(
6167
"run_application",
62-
data={"type": "robotics-academy", "code": "data:base64,ZmFrZV9jb2Rl"},
68+
data=valid_app_data,
6369
)
6470
# Assert state is now application_running
6571
assert manager.state == "application_running"
6672

6773

6874
def test_on_run_application_missing_code(manager, monkeypatch):
6975
"""Test running application with missing code file."""
70-
setup_manager_to_visualization_ready(manager, monkeypatch)
76+
setup_manager_to_tools_ready(manager, monkeypatch)
7177

7278
# Mock file system so code file is missing
7379
monkeypatch.setattr("os.path.isfile", lambda path: False)
@@ -103,18 +109,18 @@ def fake_open(file, mode="r", *args, **kwargs):
103109
# Mock linter to return no errors
104110
manager.linter.evaluate_code = lambda code, ros_version: ""
105111
# Prep data
106-
data = {"type": "robotics-academy", "code": "data:base64,ZmFrZV9jb2Rl"}
112+
data = valid_app_data
107113
# Trigger run_application with missing code
108114
with pytest.raises(Exception, match="User code not found"):
109115
manager.trigger("run_application", data=data)
110116
assert manager.application_process is None
111-
# Ensure state is still visualization_ready
112-
assert manager.state == "visualization_ready"
117+
# Ensure state is still tools_ready
118+
assert manager.state == "tools_ready"
113119

114120

115121
def test_on_run_application_corrupt_zip(manager, monkeypatch):
116122
"""Test running application with corrupt zip/base64."""
117-
setup_manager_to_visualization_ready(manager, monkeypatch)
123+
setup_manager_to_tools_ready(manager, monkeypatch)
118124

119125
# Mock file system so code dir exists
120126
monkeypatch.setattr("os.path.isfile", lambda path: True)
@@ -150,8 +156,8 @@ def fake_open(file, mode="r", *args, **kwargs):
150156
"manager.manager.manager.Manager.unpause_sim", lambda self: None
151157
)
152158
manager.linter.evaluate_code = lambda code, ros_version: ""
153-
data = {"type": "robotics-academy", "code": "data:base64,ZmFrZV9jb2Rl"}
154-
with pytest.raises(Exception, match="Corrupt base64"):
159+
data = valid_app_data
160+
with pytest.raises(Exception):
155161
manager.trigger("run_application", data=data)
156162
assert manager.application_process is None
157-
assert manager.state == "visualization_ready"
163+
assert manager.state == "tools_ready"

0 commit comments

Comments
 (0)