forked from tangger/lerobot
Mock robots (WIP segmentation fault)
This commit is contained in:
@@ -9,7 +9,6 @@ pytest -sx tests/test_motors.py::test_find_port
|
|||||||
pytest -sx tests/test_motors.py::test_motors_bus
|
pytest -sx tests/test_motors.py::test_motors_bus
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Example of running test on real dynamixel motors connected to the computer:
|
Example of running test on real dynamixel motors connected to the computer:
|
||||||
```bash
|
```bash
|
||||||
pytest -sx tests/test_motors.py::test_motors_bus[dynamixel]
|
pytest -sx tests/test_motors.py::test_motors_bus[dynamixel]
|
||||||
|
|||||||
@@ -1,10 +1,27 @@
|
|||||||
"""
|
"""
|
||||||
Tests meant to be used locally and launched manually.
|
Tests for physical robots and their mocked versions.
|
||||||
|
If the physical robots are not connected to the computer, or not working,
|
||||||
|
the test will be skipped.
|
||||||
|
|
||||||
Example usage:
|
Example of running a specific test:
|
||||||
```bash
|
```bash
|
||||||
pytest -sx tests/test_robots.py::test_robot
|
pytest -sx tests/test_robots.py::test_robot
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example of running test on real robots connected to the computer:
|
||||||
|
```bash
|
||||||
|
pytest -sx tests/test_robots.py::test_robot[koch]
|
||||||
|
pytest -sx tests/test_robots.py::test_robot[koch_bimanual]
|
||||||
|
pytest -sx tests/test_robots.py::test_robot[aloha]
|
||||||
|
```
|
||||||
|
|
||||||
|
Example of running test on a mocked version of robots:
|
||||||
|
```bash
|
||||||
|
pytest -sx -k "mocked_koch" tests/test_robots.py::test_robot
|
||||||
|
pytest -sx -k "mocked_koch_bimanual" tests/test_robots.py::test_robot
|
||||||
|
pytest -sx -k "mocked_aloha" tests/test_robots.py::test_robot
|
||||||
|
```
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -12,12 +29,11 @@ from pathlib import Path
|
|||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from lerobot import available_robots
|
|
||||||
from lerobot.common.robot_devices.robots.factory import make_robot as make_robot_from_cfg
|
from lerobot.common.robot_devices.robots.factory import make_robot as make_robot_from_cfg
|
||||||
from lerobot.common.robot_devices.robots.utils import Robot
|
from lerobot.common.robot_devices.robots.utils import Robot
|
||||||
from lerobot.common.robot_devices.utils import RobotDeviceAlreadyConnectedError, RobotDeviceNotConnectedError
|
from lerobot.common.robot_devices.utils import RobotDeviceAlreadyConnectedError, RobotDeviceNotConnectedError
|
||||||
from lerobot.common.utils.utils import init_hydra_config
|
from lerobot.common.utils.utils import init_hydra_config
|
||||||
from tests.utils import ROBOT_CONFIG_PATH_TEMPLATE, require_robot
|
from tests.utils import ROBOT_CONFIG_PATH_TEMPLATE, TEST_ROBOT_TYPES, require_robot
|
||||||
|
|
||||||
|
|
||||||
def make_robot(robot_type: str, overrides: list[str] | None = None) -> Robot:
|
def make_robot(robot_type: str, overrides: list[str] | None = None) -> Robot:
|
||||||
@@ -27,7 +43,7 @@ def make_robot(robot_type: str, overrides: list[str] | None = None) -> Robot:
|
|||||||
return robot
|
return robot
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("robot_type", available_robots)
|
@pytest.mark.parametrize("robot_type", TEST_ROBOT_TYPES)
|
||||||
@require_robot
|
@require_robot
|
||||||
def test_robot(tmpdir, request, robot_type):
|
def test_robot(tmpdir, request, robot_type):
|
||||||
# TODO(rcadene): measure fps in nightly?
|
# TODO(rcadene): measure fps in nightly?
|
||||||
|
|||||||
@@ -197,6 +197,13 @@ def require_robot(func):
|
|||||||
mock_cameras(request)
|
mock_cameras(request)
|
||||||
mock_motors(request)
|
mock_motors(request)
|
||||||
|
|
||||||
|
def mock_input(text):
|
||||||
|
print(text)
|
||||||
|
|
||||||
|
monkeypatch = request.getfixturevalue("monkeypatch")
|
||||||
|
# To run calibration without user input
|
||||||
|
monkeypatch.setattr("builtins.input", mock_input)
|
||||||
|
|
||||||
# Run test with a real robot. Skip test if robot connection fails.
|
# Run test with a real robot. Skip test if robot connection fails.
|
||||||
else:
|
else:
|
||||||
# `is_robot_available` is defined in `tests/conftest.py`
|
# `is_robot_available` is defined in `tests/conftest.py`
|
||||||
|
|||||||
Reference in New Issue
Block a user