test: add characterization tests for core modules

33 tests covering env/io helpers, config parsers, pipeline meta I/O,
worker inbox logic, and FastAPI smoke routes. No gmic/rembg subprocesses.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Frank Schwenk
2026-07-18 17:12:09 +02:00
parent 1cf4ea0f07
commit c29186a227
8 changed files with 306 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
"""Tests for worker inbox helpers."""
from __future__ import annotations
from pathlib import Path
from app import config
from app.worker import _file_key, _is_ignored_name, find_new_files, load_processed, save_processed
def test_is_ignored_name() -> None:
assert _is_ignored_name(".stfolder") is True
assert _is_ignored_name(".syncthing.tmp") is True
assert _is_ignored_name("photo.jpg") is False
def test_find_new_files_skips_processed(data_dir: Path) -> None:
photo = config.INBOX_DIR / "party.jpg"
photo.write_bytes(b"fake")
stat = photo.stat()
processed = {
_file_key(photo): {
"size": stat.st_size,
"mtime": stat.st_mtime,
}
}
assert find_new_files(processed) == []
def test_find_new_files_picks_supported(data_dir: Path) -> None:
(config.INBOX_DIR / "party.jpg").write_bytes(b"fake")
(config.INBOX_DIR / "notes.txt").write_text("nope", encoding="utf-8")
assert len(find_new_files({})) == 1
def test_load_processed_corrupt_warns(data_dir: Path, caplog) -> None:
config.PROCESSED_FILE.write_text("{bad", encoding="utf-8")
with caplog.at_level("WARNING"):
assert load_processed() == {}
assert "processed.json unreadable" in caplog.text
def test_save_processed_roundtrip(data_dir: Path) -> None:
payload = {"incoming/party.jpg": {"size": 1, "mtime": 2}}
save_processed(payload)
assert load_processed() == payload