Skip to content

Commit d66d0b3

Browse files
committed
fix test
1 parent 66eeeb0 commit d66d0b3

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

tests/test_cli.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,24 @@ def test_verify_success(self, runner: CliRunner) -> None:
269269

270270
with (
271271
patch("huggingface_hub.cli.cache.scan_cache_dir", return_value=hf_cache_info),
272-
patch(
273-
"huggingface_hub.cli.cache.list_repo_tree",
274-
return_value=[SimpleNamespace(path=file_name, blob_id="unused", lfs={"sha256": blob_identifier})],
275-
) as list_tree_mock,
272+
patch("huggingface_hub.cli.cache.get_hf_api") as get_api_mock,
276273
):
274+
api = get_api_mock.return_value
275+
api.list_repo_tree.return_value = [
276+
SimpleNamespace(path=file_name, blob_id="unused", lfs={"sha256": blob_identifier})
277+
]
277278
result = runner.invoke(app, ["cache", "verify", repo.cache_id])
278279

279280
assert result.exit_code == 0
280281
assert "Verified 1 file(s) across 1 revision(s)" in result.stdout
281-
list_tree_mock.assert_called_once()
282-
kwargs = list_tree_mock.call_args.kwargs
282+
get_api_mock.assert_called_once()
283+
api = get_api_mock.return_value
284+
api.list_repo_tree.assert_called_once()
285+
kwargs = api.list_repo_tree.call_args.kwargs
283286
assert kwargs["repo_id"] == repo_id
284287
assert kwargs["recursive"] is True
285288
assert kwargs["revision"] == commit_hash
286289
assert kwargs["repo_type"] == "model"
287-
assert kwargs["token"] is None
288290

289291
def test_verify_reports_mismatch(self, runner: CliRunner) -> None:
290292
commit_hash = "2" * 40
@@ -339,11 +341,12 @@ def test_verify_reports_mismatch(self, runner: CliRunner) -> None:
339341

340342
with (
341343
patch("huggingface_hub.cli.cache.scan_cache_dir", return_value=hf_cache_info),
342-
patch(
343-
"huggingface_hub.cli.cache.list_repo_tree",
344-
return_value=[SimpleNamespace(path=file_name, blob_id="unused", lfs={"sha256": "c" * 64})],
345-
),
344+
patch("huggingface_hub.cli.cache.get_hf_api") as get_api_mock,
346345
):
346+
api = get_api_mock.return_value
347+
api.list_repo_tree.return_value = [
348+
SimpleNamespace(path=file_name, blob_id="unused", lfs={"sha256": "c" * 64})
349+
]
347350
result = runner.invoke(app, ["cache", "verify", repo.cache_id])
348351

349352
assert result.exit_code == 1
@@ -404,16 +407,17 @@ def test_verify_reports_missing_local_file(self, runner: CliRunner) -> None:
404407

405408
with (
406409
patch("huggingface_hub.cli.cache.scan_cache_dir", return_value=hf_cache_info),
407-
patch(
408-
"huggingface_hub.cli.cache.list_repo_tree",
409-
return_value=[
410-
SimpleNamespace(path=file_name, blob_id="unused", lfs=None),
411-
SimpleNamespace(
412-
path="missing.txt", blob_id="deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", lfs=None
413-
),
414-
],
415-
),
410+
patch("huggingface_hub.cli.cache.get_hf_api") as get_api_mock,
416411
):
412+
api = get_api_mock.return_value
413+
api.list_repo_tree.return_value = [
414+
SimpleNamespace(path=file_name, blob_id="unused", lfs=None),
415+
SimpleNamespace(
416+
path="missing.txt",
417+
blob_id="blobid",
418+
lfs=None,
419+
),
420+
]
417421
result = runner.invoke(app, ["cache", "verify", repo.cache_id])
418422

419423
assert result.exit_code == 1

0 commit comments

Comments
 (0)