Spaces:
Running
Running
File size: 1,188 Bytes
df97e68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | from pathlib import Path
from app.persistence import PersistenceStore
def test_persistence_falls_back_when_configured_path_is_not_directory(
tmp_path: Path,
monkeypatch,
) -> None:
blocked_path = tmp_path / "blocked-target"
blocked_path.write_text("not-a-directory", encoding="utf-8")
monkeypatch.setenv("STORAGE_ENABLED", "true")
monkeypatch.setenv("OPENENV_DATA_DIR", str(blocked_path))
monkeypatch.delenv("STORAGE_DATA_DIR", raising=False)
store = PersistenceStore(repo_root=tmp_path)
expected_dir = (tmp_path / "outputs" / "persist").resolve()
assert store.enabled is True
assert store.data_dir == expected_dir
assert store.db_path.exists()
assert store.training_runs_dir.exists()
def test_persistence_is_disabled_via_env(tmp_path: Path, monkeypatch) -> None:
monkeypatch.setenv("STORAGE_ENABLED", "false")
monkeypatch.delenv("OPENENV_DATA_DIR", raising=False)
monkeypatch.delenv("STORAGE_DATA_DIR", raising=False)
store = PersistenceStore(repo_root=tmp_path)
assert store.enabled is False
assert store.data_dir == (tmp_path / "outputs" / "persist").resolve()
assert not store.db_path.exists()
|