2026-02-09 23:55:35 +08:00
|
|
|
"""Tests for CLI scan command options."""
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
|
|
from click.testing import CliRunner
|
|
|
|
|
|
|
|
|
|
from vlm.cli import main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_scan_no_metadata_passes_flag_to_scanner(tmp_path):
|
|
|
|
|
"""Test `scan --no-metadata` disables ffprobe metadata extraction."""
|
|
|
|
|
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}
|
|
|
|
|
video_extensions:
|
|
|
|
|
- .mp4
|
|
|
|
|
categories:
|
|
|
|
|
movie: [movie, movies]
|
|
|
|
|
series: [series, tv, shows]
|
|
|
|
|
anime: [anime]
|
|
|
|
|
""".strip()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
runner = CliRunner()
|
2026-02-10 16:56:17 +08:00
|
|
|
with patch("vlm.commands.scan.scan_library", return_value=[]) as mock_scan, patch(
|
|
|
|
|
"vlm.commands.scan.save_inventory_csv"
|
2026-02-09 23:55:35 +08:00
|
|
|
) as mock_save:
|
|
|
|
|
result = runner.invoke(
|
|
|
|
|
main,
|
|
|
|
|
["--config", str(config_file), "scan", "--no-metadata", "--output", str(tmp_path / "inv.csv")]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert mock_scan.call_count == 1
|
|
|
|
|
_, kwargs = mock_scan.call_args
|
|
|
|
|
assert kwargs["include_video_metadata"] is False
|
|
|
|
|
assert "progress_callback" in kwargs
|
|
|
|
|
assert mock_save.call_count == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_scan_force_refresh_metadata_disables_cache(tmp_path):
|
|
|
|
|
"""Test `scan --force-refresh-metadata` skips cache loading."""
|
|
|
|
|
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}
|
|
|
|
|
video_extensions:
|
|
|
|
|
- .mp4
|
|
|
|
|
categories:
|
|
|
|
|
movie: [movie, movies]
|
|
|
|
|
series: [series, tv, shows]
|
|
|
|
|
anime: [anime]
|
|
|
|
|
""".strip()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
output_file = tmp_path / "inventory.csv"
|
|
|
|
|
output_file.write_text(
|
|
|
|
|
"# Generated: 2026-02-09T00:00:00\n"
|
|
|
|
|
f"# Library Root: {library_root}\n"
|
|
|
|
|
"path,filename,size_bytes,modified_timestamp,category,resolution,codec,duration_seconds,bitrate_kbps\n"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
runner = CliRunner()
|
2026-02-10 16:56:17 +08:00
|
|
|
with patch("vlm.commands.scan.load_inventory_csv") as mock_load_cache, patch(
|
|
|
|
|
"vlm.commands.scan.scan_library", return_value=[]
|
|
|
|
|
) as mock_scan, patch("vlm.commands.scan.save_inventory_csv") as mock_save:
|
2026-02-09 23:55:35 +08:00
|
|
|
result = runner.invoke(
|
|
|
|
|
main,
|
|
|
|
|
[
|
|
|
|
|
"--config", str(config_file), "scan",
|
|
|
|
|
"--output", str(output_file),
|
|
|
|
|
"--force-refresh-metadata"
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
mock_load_cache.assert_not_called()
|
|
|
|
|
_, kwargs = mock_scan.call_args
|
|
|
|
|
assert kwargs["include_video_metadata"] is True
|
|
|
|
|
assert kwargs["metadata_cache"] is None
|
|
|
|
|
assert mock_save.call_count == 1
|