From f6a2396484c86cc16c98444554ff69b817930b06 Mon Sep 17 00:00:00 2001 From: Simon Alibert Date: Sat, 15 Mar 2025 22:19:50 +0100 Subject: [PATCH] Move test_configure_motors_all_ids_1 --- tests/motors/test_dynamixel.py | 25 +++++++++++++++++++++++- tests/motors/test_feetech.py | 25 +++++++++++++++++++++++- tests/motors/test_motors_bus.py | 34 --------------------------------- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/tests/motors/test_dynamixel.py b/tests/motors/test_dynamixel.py index de18f8dd..ba6d75ba 100644 --- a/tests/motors/test_dynamixel.py +++ b/tests/motors/test_dynamixel.py @@ -21,4 +21,27 @@ def test_abc_implementation(): from lerobot.common.motors.dynamixel import DynamixelMotorsBus # Instantiation should raise an error if the class doesn't implements abstract methods/properties - DynamixelMotorsBus(port="/dev/dummy-port", motors={"dummy", (1, "xl330-m077")}) + DynamixelMotorsBus(port="/dev/dummy-port", motors={"dummy": (1, "xl330-m077")}) + + +def test_configure_motors_all_ids_1(): + from lerobot.common.motors.dynamixel import DynamixelMotorsBus + + # see X_SERIES_BAUDRATE_TABLE + smaller_baudrate = 9_600 + smaller_baudrate_value = 0 + + # This test expect the configuration was already correct. + motors_bus = DynamixelMotorsBus(port="/dev/dummy-port", motors={"dummy": (1, "xl330-m077")}) + motors_bus.connect() + motors_bus.write("Baud_Rate", [smaller_baudrate_value] * len(motors_bus)) + + motors_bus.set_baudrate(smaller_baudrate) + motors_bus.write("ID", [1] * len(motors_bus)) + del motors_bus + + # Test configure + motors_bus = DynamixelMotorsBus(port="/dev/dummy-port", motors={"dummy": (1, "xl330-m077")}) + motors_bus.connect() + assert motors_bus.are_motors_configured() + del motors_bus diff --git a/tests/motors/test_feetech.py b/tests/motors/test_feetech.py index bd9368df..9805de84 100644 --- a/tests/motors/test_feetech.py +++ b/tests/motors/test_feetech.py @@ -21,4 +21,27 @@ def test_abc_implementation(): from lerobot.common.motors.feetech import FeetechMotorsBus # Instantiation should raise an error if the class doesn't implements abstract methods/properties - FeetechMotorsBus(port="/dev/dummy-port", motors={"dummy", (1, "sts3215")}) + FeetechMotorsBus(port="/dev/dummy-port", motors={"dummy": (1, "sts3215")}) + + +def test_configure_motors_all_ids_1(): + from lerobot.common.motors.feetech import FeetechMotorsBus + + # see SCS_SERIES_BAUDRATE_TABLE + smaller_baudrate = 19_200 + smaller_baudrate_value = 7 + + # This test expect the configuration was already correct. + motors_bus = FeetechMotorsBus(port="/dev/dummy-port", motors={"dummy": (1, "sts3215")}) + motors_bus.connect() + motors_bus.write("Baud_Rate", [smaller_baudrate_value] * len(motors_bus)) + + motors_bus.set_baudrate(smaller_baudrate) + motors_bus.write("ID", [1] * len(motors_bus)) + del motors_bus + + # Test configure + motors_bus = FeetechMotorsBus(port="/dev/dummy-port", motors={"dummy": (1, "sts3215")}) + motors_bus.connect() + assert motors_bus.are_motors_configured() + del motors_bus diff --git a/tests/motors/test_motors_bus.py b/tests/motors/test_motors_bus.py index 44c273d2..51588a58 100644 --- a/tests/motors/test_motors_bus.py +++ b/tests/motors/test_motors_bus.py @@ -59,40 +59,6 @@ def test_find_port(request, motor_type, mock): find_port() -@pytest.mark.parametrize("motor_type, mock", TEST_MOTOR_TYPES) -@require_motor -def test_configure_motors_all_ids_1(request, motor_type, mock): - if mock: - request.getfixturevalue("patch_builtins_input") - - if motor_type == "dynamixel": - # see X_SERIES_BAUDRATE_TABLE - smaller_baudrate = 9_600 - smaller_baudrate_value = 0 - elif motor_type == "feetech": - # see SCS_SERIES_BAUDRATE_TABLE - smaller_baudrate = 19_200 - smaller_baudrate_value = 7 - else: - raise ValueError(motor_type) - - input("Are you sure you want to re-configure the motors? Press enter to continue...") - # This test expect the configuration was already correct. - motors_bus = make_motors_bus(motor_type, mock=mock) - motors_bus.connect() - motors_bus.write("Baud_Rate", [smaller_baudrate_value] * len(motors_bus.motors)) - - motors_bus.set_bus_baudrate(smaller_baudrate) - motors_bus.write("ID", [1] * len(motors_bus.motors)) - del motors_bus - - # Test configure - motors_bus = make_motors_bus(motor_type, mock=mock) - motors_bus.connect() - assert motors_bus.are_motors_configured() - del motors_bus - - @pytest.mark.parametrize("motor_type, mock", TEST_MOTOR_TYPES) @require_motor def test_motors_bus(request, motor_type, mock):