Files
dl-organizer/tests/test_cli_scan.py
T
windyboy dcd87754cf Enhance project structure and add new files for enrichment and analysis
- 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.
2026-02-10 16:56:17 +08:00

90 lines
2.6 KiB
Python

"""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()
with patch("vlm.commands.scan.scan_library", return_value=[]) as mock_scan, patch(
"vlm.commands.scan.save_inventory_csv"
) 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()
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:
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