|
1
|
"""Tests for output structure and manifest I/O.""" |
|
2
|
|
|
3
|
import json |
|
4
|
|
|
5
|
from video_processor.models import ( |
|
6
|
ActionItem, |
|
7
|
BatchManifest, |
|
8
|
BatchVideoEntry, |
|
9
|
DiagramResult, |
|
10
|
KeyPoint, |
|
11
|
ProcessingStats, |
|
12
|
VideoManifest, |
|
13
|
VideoMetadata, |
|
14
|
) |
|
15
|
from video_processor.output_structure import ( |
|
16
|
create_batch_output_dirs, |
|
17
|
create_video_output_dirs, |
|
18
|
read_batch_manifest, |
|
19
|
read_video_manifest, |
|
20
|
write_batch_manifest, |
|
21
|
write_video_manifest, |
|
22
|
) |
|
23
|
|
|
24
|
|
|
25
|
class TestCreateVideoOutputDirs: |
|
26
|
def test_creates_all_directories(self, tmp_path): |
|
27
|
dirs = create_video_output_dirs(tmp_path / "output", "test_video") |
|
28
|
assert dirs["root"].exists() |
|
29
|
assert dirs["transcript"].exists() |
|
30
|
assert dirs["frames"].exists() |
|
31
|
assert dirs["diagrams"].exists() |
|
32
|
assert dirs["captures"].exists() |
|
33
|
assert dirs["results"].exists() |
|
34
|
assert dirs["cache"].exists() |
|
35
|
|
|
36
|
def test_expected_layout(self, tmp_path): |
|
37
|
dirs = create_video_output_dirs(tmp_path / "output", "my_video") |
|
38
|
base = tmp_path / "output" |
|
39
|
assert dirs["transcript"] == base / "transcript" |
|
40
|
assert dirs["frames"] == base / "frames" |
|
41
|
assert dirs["diagrams"] == base / "diagrams" |
|
42
|
assert dirs["captures"] == base / "captures" |
|
43
|
assert dirs["results"] == base / "results" |
|
44
|
assert dirs["cache"] == base / "cache" |
|
45
|
|
|
46
|
def test_idempotent(self, tmp_path): |
|
47
|
out = tmp_path / "output" |
|
48
|
dirs1 = create_video_output_dirs(out, "v") |
|
49
|
dirs2 = create_video_output_dirs(out, "v") |
|
50
|
assert dirs1 == dirs2 |
|
51
|
|
|
52
|
|
|
53
|
class TestCreateBatchOutputDirs: |
|
54
|
def test_creates_directories(self, tmp_path): |
|
55
|
dirs = create_batch_output_dirs(tmp_path / "batch", "my_batch") |
|
56
|
assert dirs["root"].exists() |
|
57
|
assert dirs["videos"].exists() |
|
58
|
|
|
59
|
def test_expected_layout(self, tmp_path): |
|
60
|
dirs = create_batch_output_dirs(tmp_path / "batch", "b") |
|
61
|
base = tmp_path / "batch" |
|
62
|
assert dirs["videos"] == base / "videos" |
|
63
|
|
|
64
|
|
|
65
|
class TestVideoManifestIO: |
|
66
|
def _sample_manifest(self) -> VideoManifest: |
|
67
|
return VideoManifest( |
|
68
|
video=VideoMetadata(title="Test", duration_seconds=120.0), |
|
69
|
stats=ProcessingStats(frames_extracted=10, diagrams_detected=2), |
|
70
|
transcript_json="transcript/transcript.json", |
|
71
|
analysis_md="results/analysis.md", |
|
72
|
key_points=[KeyPoint(point="Point 1")], |
|
73
|
action_items=[ActionItem(action="Do thing")], |
|
74
|
diagrams=[DiagramResult(frame_index=0, confidence=0.9)], |
|
75
|
) |
|
76
|
|
|
77
|
def test_write_and_read(self, tmp_path): |
|
78
|
manifest = self._sample_manifest() |
|
79
|
write_video_manifest(manifest, tmp_path) |
|
80
|
|
|
81
|
restored = read_video_manifest(tmp_path) |
|
82
|
assert restored.video.title == "Test" |
|
83
|
assert restored.stats.frames_extracted == 10 |
|
84
|
assert len(restored.key_points) == 1 |
|
85
|
assert len(restored.diagrams) == 1 |
|
86
|
|
|
87
|
def test_manifest_file_is_valid_json(self, tmp_path): |
|
88
|
manifest = self._sample_manifest() |
|
89
|
write_video_manifest(manifest, tmp_path) |
|
90
|
|
|
91
|
path = tmp_path / "manifest.json" |
|
92
|
data = json.loads(path.read_text()) |
|
93
|
assert data["version"] == "1.0" |
|
94
|
assert data["video"]["title"] == "Test" |
|
95
|
|
|
96
|
def test_creates_parent_dirs(self, tmp_path): |
|
97
|
manifest = self._sample_manifest() |
|
98
|
nested = tmp_path / "a" / "b" / "c" |
|
99
|
write_video_manifest(manifest, nested) |
|
100
|
assert (nested / "manifest.json").exists() |
|
101
|
|
|
102
|
|
|
103
|
class TestBatchManifestIO: |
|
104
|
def _sample_batch(self) -> BatchManifest: |
|
105
|
return BatchManifest( |
|
106
|
title="Test Batch", |
|
107
|
total_videos=2, |
|
108
|
completed_videos=2, |
|
109
|
videos=[ |
|
110
|
BatchVideoEntry( |
|
111
|
video_name="v1", |
|
112
|
manifest_path="videos/v1/manifest.json", |
|
113
|
status="completed", |
|
114
|
), |
|
115
|
BatchVideoEntry( |
|
116
|
video_name="v2", |
|
117
|
manifest_path="videos/v2/manifest.json", |
|
118
|
status="completed", |
|
119
|
), |
|
120
|
], |
|
121
|
batch_summary_md="batch_summary.md", |
|
122
|
) |
|
123
|
|
|
124
|
def test_write_and_read(self, tmp_path): |
|
125
|
manifest = self._sample_batch() |
|
126
|
write_batch_manifest(manifest, tmp_path) |
|
127
|
|
|
128
|
restored = read_batch_manifest(tmp_path) |
|
129
|
assert restored.title == "Test Batch" |
|
130
|
assert restored.total_videos == 2 |
|
131
|
assert len(restored.videos) == 2 |
|
132
|
assert restored.videos[0].video_name == "v1" |
|
133
|
|
|
134
|
def test_manifest_file_is_valid_json(self, tmp_path): |
|
135
|
manifest = self._sample_batch() |
|
136
|
write_batch_manifest(manifest, tmp_path) |
|
137
|
|
|
138
|
path = tmp_path / "manifest.json" |
|
139
|
data = json.loads(path.read_text()) |
|
140
|
assert data["title"] == "Test Batch" |
|
141
|
|