11"""Tests for transitioning Manager from 'connected' to 'world_ready' state."""
22
33import pytest
4+ from manager .libs .launch_world_model import ConfigurationModel
45from 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
726def 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
0 commit comments