mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-19 00:03:36 +00:00
Test resumable library-scoped caption selection
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from scene_search.cli import _route_policy, _select_caption_rows
|
||||
from scene_search.database import connect, init_db
|
||||
|
||||
|
||||
class CaptionSelectionTests(unittest.TestCase):
|
||||
def test_resume_selects_only_frames_needing_caption_in_requested_library(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
db_path = Path(tmp) / "scenes.sqlite3"
|
||||
init_db(db_path)
|
||||
|
||||
fake_settings = SimpleNamespace(
|
||||
db_path=db_path,
|
||||
caption_general_model="general-model",
|
||||
caption_specialist_model="specialist-model",
|
||||
caption_router_enabled=False,
|
||||
jellyfin_force_specialist_tag="scene-search:specialist",
|
||||
jellyfin_force_general_tag="scene-search:general",
|
||||
jellyfin_specialist_tags=(),
|
||||
)
|
||||
|
||||
with patch("scene_search.cli.settings", fake_settings):
|
||||
policy = _route_policy()
|
||||
|
||||
with connect(db_path) as con:
|
||||
for media_id, library_id in [
|
||||
("media-a", "lib-a"),
|
||||
("media-b", "lib-b"),
|
||||
]:
|
||||
con.execute(
|
||||
"""
|
||||
INSERT INTO media (
|
||||
id, source_path, title, content_sha256, size_bytes,
|
||||
mtime_ns, interval_ms, model_id, embedding_dim,
|
||||
source_kind, jellyfin_item_id, jellyfin_library_id
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
media_id,
|
||||
f"jellyfin://{media_id}",
|
||||
media_id,
|
||||
"hash",
|
||||
0,
|
||||
0,
|
||||
10000,
|
||||
"embed-model",
|
||||
1,
|
||||
"jellyfin",
|
||||
media_id,
|
||||
library_id,
|
||||
),
|
||||
)
|
||||
|
||||
con.execute(
|
||||
"""
|
||||
INSERT INTO frames (
|
||||
id, media_id, frame_number, timestamp_ms, thumb_path,
|
||||
embedding_f16, caption, caption_model, route_policy
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
"done",
|
||||
"media-a",
|
||||
0,
|
||||
0,
|
||||
"/tmp/done.jpg",
|
||||
b"\x00\x00",
|
||||
"already captioned",
|
||||
"general-model",
|
||||
policy,
|
||||
),
|
||||
)
|
||||
con.execute(
|
||||
"""
|
||||
INSERT INTO frames (
|
||||
id, media_id, frame_number, timestamp_ms, thumb_path,
|
||||
embedding_f16
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
"resume-me",
|
||||
"media-a",
|
||||
1,
|
||||
10000,
|
||||
"/tmp/resume.jpg",
|
||||
b"\x00\x00",
|
||||
),
|
||||
)
|
||||
con.execute(
|
||||
"""
|
||||
INSERT INTO frames (
|
||||
id, media_id, frame_number, timestamp_ms, thumb_path,
|
||||
embedding_f16
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
"other-library",
|
||||
"media-b",
|
||||
0,
|
||||
0,
|
||||
"/tmp/other.jpg",
|
||||
b"\x00\x00",
|
||||
),
|
||||
)
|
||||
|
||||
args = SimpleNamespace(
|
||||
force=False,
|
||||
media_id=None,
|
||||
title=None,
|
||||
limit=None,
|
||||
library_ids=["lib-a"],
|
||||
)
|
||||
rows = _select_caption_rows(args, only_needing_caption=True)
|
||||
|
||||
self.assertEqual([row["id"] for row in rows], ["resume-me"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user