Initial video AI analysis project
This commit is contained in:
51
tests/test_probe.py
Normal file
51
tests/test_probe.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from video_ai_analysis_poc.probe import probe_video
|
||||
|
||||
|
||||
class ProbeTests(unittest.TestCase):
|
||||
def test_probe_video_returns_structured_metadata(self):
|
||||
payload = (
|
||||
'{"streams":[{"codec_type":"video","codec_name":"h264",'
|
||||
'"width":1920,"height":1080,"avg_frame_rate":"30000/1001"}],'
|
||||
'"format":{"duration":"12.5","format_name":"mov,mp4,m4a,3gp,3g2,mj2",'
|
||||
'"start_time":"0.000000"}}'
|
||||
)
|
||||
completed = subprocess.CompletedProcess(
|
||||
args=["ffprobe"],
|
||||
returncode=0,
|
||||
stdout=payload,
|
||||
stderr="",
|
||||
)
|
||||
|
||||
with patch("subprocess.run", return_value=completed):
|
||||
result = probe_video(Path("/tmp/video.mp4"), timeout_seconds=3)
|
||||
|
||||
self.assertEqual(result["status"], "probed")
|
||||
self.assertEqual(result["codec_name"], "h264")
|
||||
self.assertEqual(result["width"], 1920)
|
||||
self.assertEqual(result["height"], 1080)
|
||||
self.assertAlmostEqual(result["fps"], 29.97002997)
|
||||
self.assertEqual(result["duration_seconds"], 12.5)
|
||||
self.assertIsNone(result["last_error"])
|
||||
|
||||
def test_probe_video_returns_structured_failure(self):
|
||||
failure = subprocess.CalledProcessError(
|
||||
returncode=1,
|
||||
cmd=["ffprobe"],
|
||||
stderr="Invalid data found when processing input",
|
||||
)
|
||||
|
||||
with patch("subprocess.run", side_effect=failure):
|
||||
result = probe_video(Path("/tmp/bad.mp4"), timeout_seconds=3)
|
||||
|
||||
self.assertEqual(result["status"], "probe_failed")
|
||||
self.assertEqual(result["retry_count"], 0)
|
||||
self.assertIn("Invalid data", result["last_error"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user