forked from tangger/lerobot
Fix unit test
This commit is contained in:
@@ -108,3 +108,21 @@ class MockDepthFrame:
|
|||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
return np.ones((self.config.height, self.config.width), dtype=np.uint16)
|
return np.ones((self.config.height, self.config.width), dtype=np.uint16)
|
||||||
|
|
||||||
|
|
||||||
|
class MockDevice:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_info(self, camera_info) -> str:
|
||||||
|
del camera_info # unused
|
||||||
|
# return fake serial number
|
||||||
|
return "123456789"
|
||||||
|
|
||||||
|
|
||||||
|
class MockContext:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def query_devices(self):
|
||||||
|
return [MockDevice()]
|
||||||
|
|||||||
@@ -8,14 +8,16 @@ Example of running a specific test:
|
|||||||
pytest -sx tests/test_cameras.py::test_camera
|
pytest -sx tests/test_cameras.py::test_camera
|
||||||
```
|
```
|
||||||
|
|
||||||
Example of running test on a real OpenCV camera connected to the computer:
|
Example of running test on a real camera connected to the computer:
|
||||||
```bash
|
```bash
|
||||||
pytest -sx tests/test_cameras.py::test_camera[opencv]
|
pytest -sx tests/test_cameras.py::test_camera[opencv]
|
||||||
|
pytest -sx tests/test_cameras.py::test_camera[intelrealsense]
|
||||||
```
|
```
|
||||||
|
|
||||||
Example of running test on a mocked version of an OpenCV camera:
|
Example of running test on a mocked version of the camera:
|
||||||
```bash
|
```bash
|
||||||
pytest -sx -k "mocked_opencv" tests/test_cameras.py::test_camera
|
pytest -sx -k "mocked_opencv" tests/test_cameras.py::test_camera
|
||||||
|
pytest -sx -k "mocked_intelrealsense" tests/test_cameras.py::test_camera
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,14 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from lerobot import available_robots
|
|
||||||
from lerobot.common.policies.factory import make_policy
|
from lerobot.common.policies.factory import make_policy
|
||||||
from lerobot.common.utils.utils import init_hydra_config
|
from lerobot.common.utils.utils import init_hydra_config
|
||||||
from lerobot.scripts.control_robot import calibrate, record, replay, teleoperate
|
from lerobot.scripts.control_robot import calibrate, record, replay, teleoperate
|
||||||
from tests.test_robots import make_robot
|
from tests.test_robots import make_robot
|
||||||
from tests.utils import DEFAULT_CONFIG_PATH, DEVICE, require_robot
|
from tests.utils import DEFAULT_CONFIG_PATH, DEVICE, TEST_MOTOR_TYPES, require_robot
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("robot_type", available_robots)
|
@pytest.mark.parametrize("robot_type", TEST_MOTOR_TYPES)
|
||||||
@require_robot
|
@require_robot
|
||||||
def test_teleoperate(request, robot_type):
|
def test_teleoperate(request, robot_type):
|
||||||
robot = make_robot(robot_type)
|
robot = make_robot(robot_type)
|
||||||
@@ -20,7 +19,7 @@ def test_teleoperate(request, robot_type):
|
|||||||
del robot
|
del robot
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("robot_type", available_robots)
|
@pytest.mark.parametrize("robot_type", TEST_MOTOR_TYPES)
|
||||||
@require_robot
|
@require_robot
|
||||||
def test_calibrate(request, robot_type):
|
def test_calibrate(request, robot_type):
|
||||||
robot = make_robot(robot_type)
|
robot = make_robot(robot_type)
|
||||||
@@ -28,7 +27,7 @@ def test_calibrate(request, robot_type):
|
|||||||
del robot
|
del robot
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("robot_type", available_robots)
|
@pytest.mark.parametrize("robot_type", TEST_MOTOR_TYPES)
|
||||||
@require_robot
|
@require_robot
|
||||||
def test_record_without_cameras(tmpdir, request, robot_type):
|
def test_record_without_cameras(tmpdir, request, robot_type):
|
||||||
root = Path(tmpdir)
|
root = Path(tmpdir)
|
||||||
@@ -38,7 +37,7 @@ def test_record_without_cameras(tmpdir, request, robot_type):
|
|||||||
record(robot, fps=30, root=root, repo_id=repo_id, warmup_time_s=1, episode_time_s=1, num_episodes=2)
|
record(robot, fps=30, root=root, repo_id=repo_id, warmup_time_s=1, episode_time_s=1, num_episodes=2)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("robot_type", available_robots)
|
@pytest.mark.parametrize("robot_type", TEST_MOTOR_TYPES)
|
||||||
@require_robot
|
@require_robot
|
||||||
def test_record_and_replay_and_policy(tmpdir, request, robot_type):
|
def test_record_and_replay_and_policy(tmpdir, request, robot_type):
|
||||||
env_name = "koch_real"
|
env_name = "koch_real"
|
||||||
|
|||||||
@@ -298,12 +298,13 @@ def mock_cameras(request):
|
|||||||
try:
|
try:
|
||||||
import pyrealsense2 as rs
|
import pyrealsense2 as rs
|
||||||
|
|
||||||
from tests.mock_intelrealsense import MockConfig, MockFormat, MockPipeline, MockStream
|
from tests.mock_intelrealsense import MockConfig, MockContext, MockFormat, MockPipeline, MockStream
|
||||||
|
|
||||||
monkeypatch.setattr(rs, "config", MockConfig)
|
monkeypatch.setattr(rs, "config", MockConfig)
|
||||||
monkeypatch.setattr(rs, "pipeline", MockPipeline)
|
monkeypatch.setattr(rs, "pipeline", MockPipeline)
|
||||||
monkeypatch.setattr(rs, "stream", MockStream)
|
monkeypatch.setattr(rs, "stream", MockStream)
|
||||||
monkeypatch.setattr(rs, "format", MockFormat)
|
monkeypatch.setattr(rs, "format", MockFormat)
|
||||||
|
monkeypatch.setattr(rs, "context", MockContext)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user