PlanOpticon

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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button