"""Tests for the FFmpeg engine module.""" import os import sys import unittest # Ensure the rewrite directory is on sys.path rewrite_dir = os.path.join(os.path.dirname(__file__), '..') if rewrite_dir not in sys.path: sys.path.insert(0, rewrite_dir) from transmutate_app.engine.ffmpeg_engine import ( StreamInfo, ProbeResult, _parse_time_to_seconds, ) class TestStreamInfo(unittest.TestCase): """Tests for the StreamInfo dataclass and label method.""" def test_label_with_language(self): stream = StreamInfo( index=1, codec_type="audio", codec_name="aac", language="eng", ) self.assertEqual(stream.label(), "Audio #1 — aac (eng)") def test_label_without_language(self): stream = StreamInfo( index=0, codec_type="video", codec_name="h264", language=None, ) self.assertEqual(stream.label(), "Video #0 — h264") def test_label_with_empty_string_language(self): stream = StreamInfo( index=2, codec_type="subtitle", codec_name="mov_text", language="", ) # Empty string language should be treated as None self.assertEqual(stream.label(), "Subtitle #2 — mov_text") def test_label_defaults(self): stream = StreamInfo(index=3, codec_type="data", codec_name="unknown") self.assertEqual(stream.label(), "Data #3 — unknown") class TestProbeResult(unittest.TestCase): """Tests for the ProbeResult dataclass defaults.""" def test_default_values(self): result = ProbeResult() self.assertEqual(result.streams, []) self.assertFalse(result.is_animated) self.assertEqual(result.mime_type, "") def test_custom_values(self): stream = StreamInfo(0, "audio", "aac", "eng") result = ProbeResult( streams=[stream], is_animated=True, mime_type="video/mp4", ) self.assertEqual(result.streams, [stream]) self.assertTrue(result.is_animated) self.assertEqual(result.mime_type, "video/mp4") class TestParseTime(unittest.TestCase): """Tests for the time parser used in progress reporting.""" def test_hh_mm_ss(self): result = _parse_time_to_seconds("01:23:45.67") self.assertAlmostEqual(result, 5025.67, places=2) def test_hh_mm_ss_int(self): result = _parse_time_to_seconds("00:00:01") self.assertAlmostEqual(result, 1.0, places=2) def test_mm_ss(self): result = _parse_time_to_seconds("01:23.45") self.assertAlmostEqual(result, 83.45, places=2) def test_ss_only(self): result = _parse_time_to_seconds("12.34") self.assertAlmostEqual(result, 12.34, places=2) def test_integer_seconds(self): result = _parse_time_to_seconds("42") self.assertAlmostEqual(result, 42.0, places=2) def test_zero(self): result = _parse_time_to_seconds("0") self.assertAlmostEqual(result, 0.0, places=2) def test_invalid(self): result = _parse_time_to_seconds("invalid") self.assertAlmostEqual(result, 0.0, places=2) def test_empty(self): result = _parse_time_to_seconds("") self.assertAlmostEqual(result, 0.0, places=2) if __name__ == "__main__": unittest.main()