Skip to content

Commit 601dad0

Browse files
committed
add additional tests
1 parent 31f2c45 commit 601dad0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/test_persistence.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
from model2vec.model import StaticModel
9+
from model2vec.persistence.hf import maybe_get_cached_model_path
910

1011

1112
def test_local_loading(mock_static_model: StaticModel) -> None:
@@ -49,3 +50,30 @@ def test_garbage(mock_static_model: StaticModel) -> None:
4950
shutil.move(dir_name_path / "model.safetensors", dir_name_path / "model.safetenso")
5051
with pytest.raises(ValueError):
5152
StaticModel.from_pretrained(dir_name)
53+
54+
55+
def test_maybe_get_cached_model_path() -> None:
56+
"""Test cached model path."""
57+
model_id = "t/t"
58+
with TemporaryDirectory() as temp_dir:
59+
with patch("model2vec.persistence.hf.HF_HUB_CACHE", temp_dir):
60+
# No slash
61+
assert maybe_get_cached_model_path("t") is None
62+
# More than 1 slash
63+
assert maybe_get_cached_model_path("t/t/t") is None
64+
# Not created yet
65+
assert maybe_get_cached_model_path(model_id) is None
66+
normalized = model_id.replace("/", "--")
67+
repo_dir = Path(temp_dir) / f"models--{normalized}"
68+
repo_dir.mkdir(parents=True)
69+
# Snapshot not created
70+
assert maybe_get_cached_model_path(model_id) is None
71+
with_snapshot = repo_dir / "snapshots"
72+
with_snapshot.mkdir(parents=True, exist_ok=True)
73+
# No snapshots yet
74+
assert maybe_get_cached_model_path(model_id) == None
75+
repo_dir_a = with_snapshot / "a"
76+
repo_dir_a.mkdir(parents=True, exist_ok=True)
77+
repo_dir_b = with_snapshot / "b"
78+
repo_dir_b.mkdir(parents=True, exist_ok=True)
79+
assert maybe_get_cached_model_path(model_id) == repo_dir_b

0 commit comments

Comments
 (0)