- Updated AGENTS.md to reflect changes in CLI commands and module organization, including the addition of an enrichment step and new functional modules. - Introduced analysis.json, identities.json, inventory.csv, and plan.json to support enriched metadata and execution planning. - Added CODE_IMPROVEMENTS.md to document identified code issues and proposed solutions for future enhancements. - Updated README.md to include new enrichment features and configuration options. - Removed unused dependency on ffmpeg-python from pyproject.toml. These changes improve the overall functionality and maintainability of the Video Library Manager project.
182 lines
4.6 KiB
Python
182 lines
4.6 KiB
Python
"""Tests for CLI enrich command."""
|
|
|
|
import json
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from vlm.cli import main
|
|
|
|
|
|
def test_enrich_in_place_updates_identities(tmp_path):
|
|
"""`vlm enrich` should update identities file in place by default."""
|
|
library_root = tmp_path / "library"
|
|
library_root.mkdir(parents=True)
|
|
|
|
config_file = tmp_path / "config.yaml"
|
|
config_file.write_text(
|
|
f"""
|
|
library_root: {library_root}
|
|
categories:
|
|
movie: [movie, movies]
|
|
series: [series, tv, shows]
|
|
anime: [anime]
|
|
enrichment:
|
|
cache_db: {tmp_path / 'cache.db'}
|
|
""".strip()
|
|
)
|
|
|
|
identities_file = tmp_path / "identities.json"
|
|
identities_file.write_text(json.dumps({
|
|
"metadata": {},
|
|
"movies": [
|
|
{
|
|
"path": "/library/movie/Test.2024.mkv",
|
|
"filename": "Test.2024.mkv",
|
|
"category": "movie",
|
|
"title": "Test",
|
|
"year": 2024,
|
|
"confidence": 0.9,
|
|
"needs_review": False,
|
|
}
|
|
],
|
|
"series": [],
|
|
"anime": [],
|
|
"other": [],
|
|
}, ensure_ascii=False))
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["--config", str(config_file), "enrich", "--input", str(identities_file)])
|
|
|
|
assert result.exit_code == 0
|
|
assert "Enrichment complete!" in result.output
|
|
|
|
updated = json.loads(identities_file.read_text(encoding="utf-8"))
|
|
assert updated["metadata"]["enriched"] is True
|
|
|
|
|
|
def test_enrich_refresh_all_option_runs_successfully(tmp_path):
|
|
"""`vlm enrich --refresh-all` should execute successfully."""
|
|
library_root = tmp_path / "library"
|
|
library_root.mkdir(parents=True)
|
|
|
|
config_file = tmp_path / "config.yaml"
|
|
config_file.write_text(
|
|
f"""
|
|
library_root: {library_root}
|
|
categories:
|
|
movie: [movie, movies]
|
|
series: [series, tv, shows]
|
|
anime: [anime]
|
|
enrichment:
|
|
cache_db: {tmp_path / 'cache.db'}
|
|
""".strip()
|
|
)
|
|
|
|
identities_file = tmp_path / "identities.json"
|
|
identities_file.write_text(json.dumps({
|
|
"metadata": {},
|
|
"movies": [],
|
|
"series": [],
|
|
"anime": [],
|
|
"other": [],
|
|
}))
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
main,
|
|
["--config", str(config_file), "enrich", "--input", str(identities_file), "--refresh-all"],
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
assert "Enrichment complete!" in result.output
|
|
|
|
|
|
def test_enrich_rejects_conflicting_refresh_flags(tmp_path):
|
|
"""Conflicting refresh flags should fail with a clear error."""
|
|
library_root = tmp_path / "library"
|
|
library_root.mkdir(parents=True)
|
|
|
|
config_file = tmp_path / "config.yaml"
|
|
config_file.write_text(
|
|
f"""
|
|
library_root: {library_root}
|
|
categories:
|
|
movie: [movie, movies]
|
|
series: [series, tv, shows]
|
|
anime: [anime]
|
|
enrichment:
|
|
cache_db: {tmp_path / 'cache.db'}
|
|
""".strip()
|
|
)
|
|
|
|
identities_file = tmp_path / "identities.json"
|
|
identities_file.write_text(json.dumps({
|
|
"metadata": {},
|
|
"movies": [],
|
|
"series": [],
|
|
"anime": [],
|
|
"other": [],
|
|
}))
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
main,
|
|
[
|
|
"--config",
|
|
str(config_file),
|
|
"enrich",
|
|
"--input",
|
|
str(identities_file),
|
|
"--refresh-all",
|
|
"--refresh-changed-only",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 1
|
|
assert "mutually exclusive" in result.output
|
|
|
|
|
|
def test_enrich_prints_text_progress_when_not_tty(tmp_path):
|
|
"""Non-TTY execution should emit textual progress updates."""
|
|
library_root = tmp_path / "library"
|
|
library_root.mkdir(parents=True)
|
|
|
|
config_file = tmp_path / "config.yaml"
|
|
config_file.write_text(
|
|
f"""
|
|
library_root: {library_root}
|
|
categories:
|
|
movie: [movie, movies]
|
|
series: [series, tv, shows]
|
|
anime: [anime]
|
|
enrichment:
|
|
cache_db: {tmp_path / 'cache.db'}
|
|
""".strip()
|
|
)
|
|
|
|
identities_file = tmp_path / "identities.json"
|
|
identities_file.write_text(json.dumps({
|
|
"metadata": {},
|
|
"movies": [
|
|
{
|
|
"path": "/library/movie/Test.2024.mkv",
|
|
"filename": "Test.2024.mkv",
|
|
"category": "movie",
|
|
"title": "Test",
|
|
"year": 2024,
|
|
"confidence": 0.9,
|
|
"needs_review": False,
|
|
}
|
|
],
|
|
"series": [],
|
|
"anime": [],
|
|
"other": [],
|
|
}))
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(main, ["--config", str(config_file), "enrich", "--input", str(identities_file)])
|
|
|
|
assert result.exit_code == 0
|
|
assert "Progress: 1/1 (100%)" in result.output
|
|
assert "Skip reasons: no_key=1" in result.output
|