test(streaming): make bucket get_safe_version test actually exercise the except branch

The prior test patched _load_metadata as a plain no-op, so __init__'s try
block succeeded and never entered the except branch where the
repo_type != "bucket" guard and get_safe_version live - the assertion passed
vacuously (verified: it still passed with the guard removed).

Use side_effect=[FileNotFoundError, None] so the first _load_metadata raises
(forcing the except path) and the second succeeds after the meta pull, and
stub _pull_from_repo so the path runs without a network call. Now the test
fails if the bucket guard is removed. Thanks @mohitydv09 for the catch.

Signed-off-by: Sundar Raghavan <sdraghav@amazon.com>
This commit is contained in:
Sundar Raghavan
2026-07-23 17:45:51 -07:00
committed by Steven Palma
parent 9782bfd64b
commit 13a261a08a
+18 -4
View File
@@ -495,16 +495,30 @@ def test_bucket_metadata_url_root(tmp_path):
def test_bucket_skips_get_safe_version(tmp_path):
"""repo_type='bucket' must NOT call get_safe_version (buckets have no git refs)."""
mock_fs = MagicMock()
"""repo_type='bucket' must NOT call get_safe_version (buckets have no git refs).
The first ``_load_metadata()`` raises ``FileNotFoundError`` so ``__init__``
enters the except branch where the ``repo_type != "bucket"`` guard and
``get_safe_version`` live; the second call (after the bucket meta pull)
succeeds. ``_pull_from_repo`` is stubbed so the except path runs without a
network call. Without the raise, the try block would succeed and the guard
branch would never execute, so the assertion would pass vacuously.
"""
with (
patch("lerobot.datasets.dataset_metadata.get_safe_version") as mock_gsv,
patch("huggingface_hub.HfFileSystem", return_value=mock_fs),
patch.object(LeRobotDatasetMetadata, "_load_metadata"),
patch.object(
LeRobotDatasetMetadata,
"_load_metadata",
side_effect=[FileNotFoundError, None],
),
patch.object(LeRobotDatasetMetadata, "_pull_from_repo") as mock_pull,
):
LeRobotDatasetMetadata(
DUMMY_REPO_ID,
root=tmp_path,
repo_type="bucket",
)
# The except branch ran (proven by the pull), but the bucket guard skipped
# version resolution.
mock_pull.assert_called_once()
mock_gsv.assert_not_called()