From 7f23972f3f4ac96d1c32474b7092abd3990c21fe Mon Sep 17 00:00:00 2001 From: Simon Alibert Date: Sat, 15 Mar 2025 21:45:05 +0100 Subject: [PATCH] Add Feetech & Dxl basic tests --- tests/motors/test_dynamixel.py | 24 ++++++++++++++++++++++++ tests/motors/test_feetech.py | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/motors/test_dynamixel.py create mode 100644 tests/motors/test_feetech.py diff --git a/tests/motors/test_dynamixel.py b/tests/motors/test_dynamixel.py new file mode 100644 index 000000000..de18f8dd0 --- /dev/null +++ b/tests/motors/test_dynamixel.py @@ -0,0 +1,24 @@ +import sys +from unittest.mock import patch + +import pytest + +from tests.mocks import mock_dynamixel_sdk + + +@pytest.fixture(autouse=True) +def patch_dynamixel_sdk(): + with patch.dict(sys.modules, {"dynamixel_sdk": mock_dynamixel_sdk}): + yield + + +def test_patch_sdk(): + assert "dynamixel_sdk" in sys.modules # Should be patched + assert sys.modules["dynamixel_sdk"] is mock_dynamixel_sdk # Should match the mock + + +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")}) diff --git a/tests/motors/test_feetech.py b/tests/motors/test_feetech.py new file mode 100644 index 000000000..bd9368df2 --- /dev/null +++ b/tests/motors/test_feetech.py @@ -0,0 +1,24 @@ +import sys +from unittest.mock import patch + +import pytest + +from tests.mocks import mock_scservo_sdk + + +@pytest.fixture(autouse=True) +def patch_scservo_sdk(): + with patch.dict(sys.modules, {"scservo_sdk": mock_scservo_sdk}): + yield + + +def test_patch_sdk(): + assert "scservo_sdk" in sys.modules # Should be patched + assert sys.modules["scservo_sdk"] is mock_scservo_sdk # Should match the mock + + +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")})