"""Tests for writable HF cache configuration.""" from __future__ import annotations import os import pytest from vivamais.hf_cache import configure_hf_cache, hf_home class TestHfCache: def test_configure_hf_cache_sets_env(self, tmp_path: os.PathLike[str]) -> None: app_root = str(tmp_path / "app") os.makedirs(app_root, exist_ok=True) hf = configure_hf_cache(app_root) assert hf == os.path.join(app_root, ".cache", "huggingface") assert os.environ["HF_HOME"] == hf assert os.environ["HUGGINGFACE_HUB_CACHE"] == os.path.join(hf, "hub") assert os.path.isdir(os.path.join(app_root, ".cache", "tmp")) def test_hf_home_reads_configured_env(self, monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("HF_HOME", "/tmp/test-hf") assert hf_home() == "/tmp/test-hf"