♻ | New project structure

This commit is contained in:
2026-06-01 02:06:49 +03:00
parent 192a02df45
commit 75808cfed8
13 changed files with 2114 additions and 150 deletions

1
tests/__init__.py Normal file
View File

@@ -0,0 +1 @@
"""Test package for transmutate_app."""

113
tests/test_engine.py Normal file
View File

@@ -0,0 +1,113 @@
"""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()