-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest_datasets.py
More file actions
107 lines (81 loc) · 3.34 KB
/
Copy pathtest_datasets.py
File metadata and controls
107 lines (81 loc) · 3.34 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
# 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.datasets — local cache walk and merge logic."""
from __future__ import annotations
from pathlib import Path
from unittest.mock import patch
def _make_dataset(root: Path, repo_id: str) -> None:
"""Create the minimal layout `_is_dataset_dir` recognizes."""
d = root / repo_id
(d / "meta").mkdir(parents=True)
(d / "meta" / "info.json").write_text("{}")
def test_list_local_datasets_empty_when_root_missing(
tmp_lerobot_home: Path,
) -> None:
# tmp_lerobot_home creates the cache; remove it so the function sees the
# "missing root" branch.
import shutil
from lelab.datasets import list_local_datasets
shutil.rmtree(tmp_lerobot_home)
assert list_local_datasets() == []
def test_list_local_datasets_finds_top_level_dataset(
tmp_lerobot_home: Path,
) -> None:
from lelab.datasets import list_local_datasets
_make_dataset(tmp_lerobot_home, "pusht")
result = list_local_datasets()
repo_ids = [d["repo_id"] for d in result]
assert "pusht" in repo_ids
def test_list_local_datasets_finds_nested_user_dataset(
tmp_lerobot_home: Path,
) -> None:
from lelab.datasets import list_local_datasets
_make_dataset(tmp_lerobot_home, "alice/pusht")
result = list_local_datasets()
repo_ids = [d["repo_id"] for d in result]
assert "alice/pusht" in repo_ids
def test_list_local_datasets_skips_non_dataset_dirs(
tmp_lerobot_home: Path,
) -> None:
from lelab.datasets import list_local_datasets
(tmp_lerobot_home / "calibration").mkdir(exist_ok=True)
(tmp_lerobot_home / "ports").mkdir(exist_ok=True)
_make_dataset(tmp_lerobot_home, "real_dataset")
result = list_local_datasets()
repo_ids = [d["repo_id"] for d in result]
assert "real_dataset" in repo_ids
assert "calibration" not in repo_ids
assert "ports" not in repo_ids
def test_list_user_datasets_returns_empty_when_not_logged_in(
tmp_lerobot_home: Path,
) -> None:
from lelab.datasets import list_user_datasets
with patch("lelab.datasets.cached_whoami", return_value=None):
assert list_user_datasets() == []
def test_list_all_datasets_merges_hub_and_local(
tmp_lerobot_home: Path,
) -> None:
from lelab.datasets import list_all_datasets
_make_dataset(tmp_lerobot_home, "alice/pusht")
with patch(
"lelab.datasets.list_user_datasets",
return_value=[
{"repo_id": "alice/pusht", "last_modified": "2026-01-01T00:00:00Z", "private": False},
{"repo_id": "alice/aloha", "last_modified": "2026-02-01T00:00:00Z", "private": True},
],
):
result = list_all_datasets()
by_id = {d["repo_id"]: d for d in result}
assert by_id["alice/pusht"]["source"] == "both"
assert by_id["alice/aloha"]["source"] == "hub"