From 13a261a08a2ec0fc595d132ebf785119214758b2 Mon Sep 17 00:00:00 2001 From: Sundar Raghavan Date: Thu, 23 Jul 2026 17:45:51 -0700 Subject: [PATCH] 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 --- tests/datasets/test_streaming.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/datasets/test_streaming.py b/tests/datasets/test_streaming.py index ac9f06841..ee4df4981 100644 --- a/tests/datasets/test_streaming.py +++ b/tests/datasets/test_streaming.py @@ -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()