-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest_record.py
More file actions
121 lines (85 loc) · 4.42 KB
/
Copy pathtest_record.py
File metadata and controls
121 lines (85 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for lelab.record — request schemas and handler entry points."""
from __future__ import annotations
import pytest
def test_recording_request_rejects_missing_required_fields() -> None:
from pydantic import ValidationError
from lelab.record import RecordingRequest
with pytest.raises(ValidationError):
RecordingRequest()
def test_recording_status_handler_exposes_state_fields() -> None:
from lelab.record import handle_recording_status
result = handle_recording_status()
assert isinstance(result, dict)
# Pinning the exact keys so a rename in handle_recording_status surfaces here.
assert "recording_active" in result
assert "current_phase" in result
assert "session_ended" in result
assert "available_controls" in result
def test_handle_stop_recording_when_idle_returns_dict(tmp_lerobot_home) -> None:
from lelab.record import handle_stop_recording
result = handle_stop_recording()
assert isinstance(result, dict)
def test_create_record_config_pins_dshow_on_windows(monkeypatch: pytest.MonkeyPatch) -> None:
"""On Windows, recording must use the DSHOW backend so a camera_index opens
the same device /available-cameras enumerated (via pygrabber, DSHOW order).
"""
import lelab.record as record
from lerobot.cameras.configs import Cv2Backends
monkeypatch.setattr("platform.system", lambda: "Windows")
monkeypatch.setattr(record, "setup_calibration_files", lambda leader, follower: ("leader", "follower"))
request = record.RecordingRequest(
leader_port="COM_LEADER",
follower_port="COM_FOLLOWER",
leader_config="leader",
follower_config="follower",
dataset_repo_id="user/dataset",
single_task="pick up the cube",
cameras={"wrist": {"type": "opencv", "camera_index": 0, "width": 640, "height": 480, "fps": 30}},
)
config = record.create_record_config(request)
assert config.robot.cameras["wrist"].backend == Cv2Backends.DSHOW
def test_build_camera_configs_uses_default_backend_when_unset() -> None:
from lelab.record import _build_camera_configs
from lerobot.cameras.configs import Cv2Backends
cameras = {"cam": {"type": "opencv", "camera_index": 0, "width": 640, "height": 480, "fps": 30}}
configs = _build_camera_configs(cameras, Cv2Backends.AVFOUNDATION)
assert configs["cam"].backend == Cv2Backends.AVFOUNDATION
assert configs["cam"].fourcc is None
assert configs["cam"].index_or_path == 0
def test_build_camera_configs_passes_fourcc_through() -> None:
from lelab.record import _build_camera_configs
from lerobot.cameras.configs import Cv2Backends
cameras = {"cam": {"type": "opencv", "camera_index": 0, "fourcc": "MJPG"}}
configs = _build_camera_configs(cameras, Cv2Backends.ANY)
assert configs["cam"].fourcc == "MJPG"
def test_build_camera_configs_explicit_backend_overrides_default() -> None:
from lelab.record import _build_camera_configs
from lerobot.cameras.configs import Cv2Backends
cameras = {"cam": {"type": "opencv", "camera_index": 0, "backend": "V4L2"}}
configs = _build_camera_configs(cameras, Cv2Backends.AVFOUNDATION)
assert configs["cam"].backend == Cv2Backends.V4L2
def test_build_camera_configs_invalid_backend_raises() -> None:
from lelab.record import _build_camera_configs
from lerobot.cameras.configs import Cv2Backends
cameras = {"cam": {"type": "opencv", "camera_index": 0, "backend": "NOPE"}}
with pytest.raises(KeyError):
_build_camera_configs(cameras, Cv2Backends.ANY)
def test_build_camera_configs_skips_non_opencv_type() -> None:
from lelab.record import _build_camera_configs
from lerobot.cameras.configs import Cv2Backends
cameras = {"cam": {"type": "realsense", "camera_index": 0}}
configs = _build_camera_configs(cameras, Cv2Backends.ANY)
assert configs == {}