Spaces:
Sleeping
Sleeping
File size: 1,672 Bytes
7fa723a | 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 37 38 39 40 41 42 43 44 45 46 47 48 | """Section photo vision disk cache."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from app.services.photo_vision import (
_read_vision_cache,
_vision_cache_path,
_write_vision_cache,
invalidate_section_photo_vision_cache,
)
def test_vision_cache_roundtrip(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("app.services.photo_vision.settings.upload_dir", tmp_path / "uploads")
path = _vision_cache_path("t1", "r1", "E1")
_write_vision_cache(
path,
photo_ids=["a", "b"],
observations=["Crack in render"],
note=None,
)
out = _read_vision_cache(path, photo_ids=["b", "a"])
assert out is not None
obs, note = out
assert obs == ["Crack in render"]
assert note is None
def test_vision_cache_invalidates_on_photo_set_change(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("app.services.photo_vision.settings.upload_dir", tmp_path / "uploads")
path = _vision_cache_path("t1", "r1", "E1")
_write_vision_cache(path, photo_ids=["a"], observations=["x"], note=None)
assert _read_vision_cache(path, photo_ids=["a", "b"]) is None
def test_invalidate_removes_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("app.services.photo_vision.settings.upload_dir", tmp_path / "uploads")
path = _vision_cache_path("t1", "r1", "E1")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps({"photo_ids": []}), encoding="utf-8")
invalidate_section_photo_vision_cache("t1", "r1", "E1")
assert not path.is_file()
|