Skip to content

Commit

Permalink
test: adjusted tests after refactor of _is_ros2_stack_ready method
Browse files Browse the repository at this point in the history
  • Loading branch information
MagdalenaKotynia committed Feb 27, 2025
1 parent 38402c6 commit 9b4e8df
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
20 changes: 17 additions & 3 deletions tests/rai_sim/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,23 @@ def sample_o3dexros2_config(tmp_path: Path) -> Path:
yaml_content = """
binary_path: /path/to/binary
robotic_stack_command: "ros2 launch robotic_stack.launch.py"
required_services: []
required_topics: []
required_actions: []
required_binary_ros2_stack:
services:
- /spawn_entity
- /delete_entity
topics:
- /color_image5
- /depth_image5
- /color_camera_info5
actions: []
required_robotic_ros2_stack:
services:
- /grounding_dino_classify
- /grounded_sam_segment
- /manipulator_move_to
topics: []
actions:
- /execute_trajectory
"""
file_path = tmp_path / "test_o3dexros2_config.yaml"
file_path.write_text(yaml_content)
Expand Down
26 changes: 18 additions & 8 deletions tests/rai_sim/test_o3de_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ def test_load_config(sample_base_yaml_config: Path, sample_o3dexros2_config: Pat
assert isinstance(config, O3DExROS2SimulationConfig)
assert config.binary_path == Path("/path/to/binary")
assert config.robotic_stack_command == "ros2 launch robotic_stack.launch.py"
assert config.required_binary_ros2_stack == {
"services": ["/spawn_entity", "/delete_entity"],
"topics": ["/color_image5", "/depth_image5", "/color_camera_info5"],
"actions": [],
}
assert config.required_robotic_ros2_stack == {
"services": [
"/grounding_dino_classify",
"/grounded_sam_segment",
"/manipulator_move_to",
],
"topics": [],
"actions": ["/execute_trajectory"],
}
assert isinstance(config.entities, list)
assert all(isinstance(e, Entity) for e in config.entities)

Expand Down Expand Up @@ -83,9 +97,8 @@ def setUp(self):
binary_path=Path("/path/to/binary"),
robotic_stack_command="ros2 launch robot.launch.py",
entities=[self.test_entity],
required_actions=[],
required_services=[],
required_topics=[],
required_binary_ros2_stack={"services": [], "topics": [], "actions": []},
required_robotic_ros2_stack={"services": [], "topics": [], "actions": []},
)

def test_init(self):
Expand All @@ -102,9 +115,7 @@ def test_launch_robotic_stack(self, mock_popen):
mock_process.poll.return_value = None
mock_process.pid = 54321
mock_popen.return_value = mock_process

command = "ros2 launch robot.launch.py"
self.bridge._launch_robotic_stack(command)
self.bridge._launch_robotic_stack(self.test_config)

mock_popen.assert_called_once_with(["ros2", "launch", "robot.launch.py"])
self.assertEqual(self.bridge.current_robotic_stack_process, mock_process)
Expand All @@ -116,8 +127,7 @@ def test_launch_binary(self, mock_popen):
mock_process.pid = 54322
mock_popen.return_value = mock_process

command = Path("/path/to/binary")
self.bridge._launch_binary(command)
self.bridge._launch_binary(self.test_config)

mock_popen.assert_called_once_with(["/path/to/binary"])
self.assertEqual(self.bridge.current_sim_process, mock_process)
Expand Down

0 comments on commit 9b4e8df

Please sign in to comment.