feat: annotated video writer wraps OpenCV VideoWriter
This commit is contained in:
1 parent
f5982a4222
commit
61c9868ca1
2 files changed
+92
No files matched your search
@@ -0,0 +1,39 @@
|
||||
"""Tests for AnnotatedVideoWriter (src/video_writer.py)."""
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import pytest
|
||||
from src.video_writer import AnnotatedVideoWriter
|
||||
|
||||
|
||||
def test_writer_creates_output_file(tmp_path):
|
||||
out = tmp_path / "test_output.mp4"
|
||||
writer = AnnotatedVideoWriter(str(out), fps=25.0, frame_size=(640, 480))
|
||||
frame = np.zeros((480, 640, 3), dtype=np.uint8)
|
||||
writer.write_frame(frame)
|
||||
writer.finish()
|
||||
assert out.exists()
|
||||
assert out.stat().st_size > 0
|
||||
|
||||
|
||||
def test_writer_multiple_frames(tmp_path):
|
||||
out = tmp_path / "multi.mp4"
|
||||
writer = AnnotatedVideoWriter(str(out), fps=25.0, frame_size=(320, 240))
|
||||
for _ in range(10):
|
||||
writer.write_frame(np.zeros((240, 320, 3), dtype=np.uint8))
|
||||
writer.finish()
|
||||
assert out.exists()
|
||||
|
||||
|
||||
def test_writer_close_idempotent(tmp_path):
|
||||
out = tmp_path / "idem.mp4"
|
||||
writer = AnnotatedVideoWriter(str(out), fps=25.0, frame_size=(320, 240))
|
||||
writer.write_frame(np.zeros((240, 320, 3), dtype=np.uint8))
|
||||
writer.finish()
|
||||
writer.finish() # second call should not raise
|
||||
assert out.exists()
|
||||
|
||||
|
||||
def test_writer_invalid_fps():
|
||||
with pytest.raises(ValueError):
|
||||
AnnotatedVideoWriter("/tmp/x.mp4", fps=0.0, frame_size=(640, 480))
|
||||
Reference in new issue
Block a user