Files
dl-organizer/tests/test_reports_integration.py
T
windyboy 1705275e99 Initial commit: Video Library Manager
- Add core VLM modules (scanner, parser, planner, executor, analysis)
- Add CLI with quarantine, reports, rollback, and state management
- Add comprehensive test suite
- Add project configuration and documentation
- Add .gitignore for Python project
2026-02-09 17:43:35 +08:00

146 lines
5.9 KiB
Python

"""Integration tests for report generation with analysis engine.
Tests the complete workflow from analysis to report generation.
"""
import json
from pathlib import Path
from datetime import datetime
from vlm.models import SeriesIdentity, VideoFile, MovieIdentity
from vlm.analysis import analyze_series_completeness, detect_duplicates
from vlm.reports import generate_completeness_report, generate_duplicate_report, generate_summary_report
class TestReportsIntegration:
"""Test report generation integrated with analysis engine."""
def test_completeness_workflow(self):
"""Test complete workflow from series analysis to completeness report."""
# Create test episodes with gaps
episodes = [
SeriesIdentity("Breaking Bad", 1, [1], 0.9, False, "Breaking.Bad.S01E01.mkv"),
SeriesIdentity("Breaking Bad", 1, [2], 0.9, False, "Breaking.Bad.S01E02.mkv"),
SeriesIdentity("Breaking Bad", 1, [4], 0.9, False, "Breaking.Bad.S01E04.mkv"),
SeriesIdentity("The Wire", 1, [1], 0.9, False, "The.Wire.S01E01.mkv"),
SeriesIdentity("The Wire", 1, [3], 0.9, False, "The.Wire.S01E03.mkv"),
]
# Analyze completeness
analysis = analyze_series_completeness(episodes)
# Generate text report
library_root = Path("/mnt/nas/videos")
text_report = generate_completeness_report(analysis, "text", library_root)
# Verify report contains expected information
assert "Breaking Bad" in text_report
assert "The Wire" in text_report
assert "Episodes missing:" in text_report
# Generate JSON report
json_report = generate_completeness_report(analysis, "json", library_root)
data = json.loads(json_report)
# Verify JSON structure
assert data["metadata"]["series_count"] == 2
assert len(data["series"]) == 2
def test_duplicate_workflow(self):
"""Test complete workflow from duplicate detection to duplicate report."""
# Create test identities and files
identities = [
MovieIdentity("The Matrix", 1999, 0.9, False, "The.Matrix.1999.1080p.mkv"),
MovieIdentity("The Matrix", 1999, 0.9, False, "The.Matrix.1999.720p.mkv"),
MovieIdentity("Inception", 2010, 0.9, False, "Inception.2010.mkv"),
]
files = [
VideoFile(
Path("/movies/The.Matrix.1999.1080p.mkv"),
"The.Matrix.1999.1080p.mkv",
2000000000,
datetime.now(),
"movie",
resolution="1920x1080",
codec="h264"
),
VideoFile(
Path("/movies/The.Matrix.1999.720p.mkv"),
"The.Matrix.1999.720p.mkv",
1000000000,
datetime.now(),
"movie",
resolution="1280x720",
codec="h264"
),
VideoFile(
Path("/movies/Inception.2010.mkv"),
"Inception.2010.mkv",
1500000000,
datetime.now(),
"movie"
),
]
# Detect duplicates
duplicates = detect_duplicates(identities, files)
# Generate text report
library_root = Path("/mnt/nas/videos")
text_report = generate_duplicate_report(duplicates, "text", library_root)
# Verify report contains expected information
assert "The Matrix (1999)" in text_report
assert "1920x1080" in text_report
assert "1280x720" in text_report
# Generate JSON report
json_report = generate_duplicate_report(duplicates, "json", library_root)
data = json.loads(json_report)
# Verify JSON structure
assert data["metadata"]["duplicate_groups"] == 1
assert len(data["duplicates"]) == 1
assert data["duplicates"][0]["file_count"] == 2
def test_summary_workflow(self):
"""Test summary report generation with mixed file types."""
# Create test files
files = [
VideoFile(Path("/movies/Movie1.mkv"), "Movie1.mkv", 2000000000, datetime.now(), "movie"),
VideoFile(Path("/movies/Movie2.mkv"), "Movie2.mkv", 1500000000, datetime.now(), "movie"),
VideoFile(Path("/series/Show.S01E01.mkv"), "Show.S01E01.mkv", 1000000000, datetime.now(), "series"),
VideoFile(Path("/series/Show.S01E02.mkv"), "Show.S01E02.mkv", 1000000000, datetime.now(), "series"),
VideoFile(Path("/anime/Anime1.mkv"), "Anime1.mkv", 800000000, datetime.now(), "anime"),
]
# Generate summary report
library_root = Path("/mnt/nas/videos")
report = generate_summary_report(files, library_root)
# Verify report contains expected information
assert "Total Files: 5" in report
assert "Movie:" in report
assert "Series:" in report
assert "Anime:" in report
assert "Category Breakdown:" in report
def test_all_reports_include_metadata(self):
"""Test that all reports include generation timestamp and library root."""
library_root = Path("/mnt/nas/videos")
# Test completeness report
completeness_report = generate_completeness_report([], "text", library_root)
assert "Generated:" in completeness_report
assert str(library_root) in completeness_report
# Test duplicate report
duplicate_report = generate_duplicate_report([], "text", library_root)
assert "Generated:" in duplicate_report
assert str(library_root) in duplicate_report
# Test summary report
summary_report = generate_summary_report([], library_root)
assert "Generated:" in summary_report
assert str(library_root) in summary_report