78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from launch import LaunchContext
|
|
from launch.actions import DeclareLaunchArgument, Shutdown
|
|
from launch.utilities import perform_substitutions
|
|
|
|
|
|
MODULE_PATH = Path(__file__).parents[1] / "launch" / "arm_debug.launch.py"
|
|
SPEC = importlib.util.spec_from_file_location("arm_debug_launch", MODULE_PATH)
|
|
arm_debug_launch = importlib.util.module_from_spec(SPEC)
|
|
assert SPEC.loader is not None
|
|
SPEC.loader.exec_module(arm_debug_launch)
|
|
|
|
|
|
def test_launch_declares_mujoco_disabled_by_default() -> None:
|
|
description = arm_debug_launch.generate_launch_description()
|
|
arguments = {
|
|
entity.name: entity
|
|
for entity in description.entities
|
|
if isinstance(entity, DeclareLaunchArgument)
|
|
}
|
|
|
|
assert "use_mujoco" in arguments
|
|
assert perform_substitutions(
|
|
LaunchContext(),
|
|
arguments["use_mujoco"].default_value,
|
|
) == "false"
|
|
|
|
|
|
def test_mujoco_mode_requires_both_arms() -> None:
|
|
arm_debug_launch._validate_mujoco_mode("both", True)
|
|
arm_debug_launch._validate_mujoco_mode("left", False)
|
|
|
|
with pytest.raises(ValueError, match="arm:=both"):
|
|
arm_debug_launch._validate_mujoco_mode("left", True)
|
|
|
|
|
|
def test_udp_receiver_exit_shuts_down_launch() -> None:
|
|
receiver = arm_debug_launch._udp_receiver_node()
|
|
|
|
assert isinstance(receiver._ExecuteLocal__on_exit, Shutdown)
|
|
|
|
|
|
def test_act_recording_is_disabled_by_default() -> None:
|
|
description = arm_debug_launch.generate_launch_description()
|
|
arguments = {
|
|
entity.name: entity
|
|
for entity in description.entities
|
|
if isinstance(entity, DeclareLaunchArgument)
|
|
}
|
|
|
|
assert perform_substitutions(
|
|
LaunchContext(),
|
|
arguments["record_act"].default_value,
|
|
) == "false"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("arm", "use_mock"),
|
|
[("left", False), ("both", False), ("right", True)],
|
|
)
|
|
def test_act_recording_rejects_unsupported_modes(arm, use_mock) -> None:
|
|
with pytest.raises(ValueError, match="arm:=right use_mock:=false"):
|
|
arm_debug_launch._validate_act_mode(arm, use_mock, True)
|
|
|
|
|
|
def test_act_recording_accepts_right_real_mode() -> None:
|
|
arm_debug_launch._validate_act_mode("right", False, True)
|
|
arm_debug_launch._validate_act_mode("both", True, False)
|
|
|
|
|
|
def test_act_recorder_exit_does_not_shutdown_teleoperation() -> None:
|
|
recorder = arm_debug_launch._act_recorder_node()
|
|
|
|
assert recorder._ExecuteLocal__on_exit is None
|