mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-30 21:19:40 +00:00
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:
committed by
Steven Palma
parent
9782bfd64b
commit
13a261a08a
@@ -495,16 +495,30 @@ def test_bucket_metadata_url_root(tmp_path):
|
|||||||
|
|
||||||
|
|
||||||
def test_bucket_skips_get_safe_version(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)."""
|
"""repo_type='bucket' must NOT call get_safe_version (buckets have no git refs).
|
||||||
mock_fs = MagicMock()
|
|
||||||
|
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 (
|
with (
|
||||||
patch("lerobot.datasets.dataset_metadata.get_safe_version") as mock_gsv,
|
patch("lerobot.datasets.dataset_metadata.get_safe_version") as mock_gsv,
|
||||||
patch("huggingface_hub.HfFileSystem", return_value=mock_fs),
|
patch.object(
|
||||||
patch.object(LeRobotDatasetMetadata, "_load_metadata"),
|
LeRobotDatasetMetadata,
|
||||||
|
"_load_metadata",
|
||||||
|
side_effect=[FileNotFoundError, None],
|
||||||
|
),
|
||||||
|
patch.object(LeRobotDatasetMetadata, "_pull_from_repo") as mock_pull,
|
||||||
):
|
):
|
||||||
LeRobotDatasetMetadata(
|
LeRobotDatasetMetadata(
|
||||||
DUMMY_REPO_ID,
|
DUMMY_REPO_ID,
|
||||||
root=tmp_path,
|
root=tmp_path,
|
||||||
repo_type="bucket",
|
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()
|
mock_gsv.assert_not_called()
|
||||||
|
|||||||
Reference in New Issue
Block a user