55import pytest
66from pathlib import Path
77from src .subtitles import (
8- create_track ,
9- format_time_for_srt ,
8+ create_subtitles ,
109 format_time_for_vtt ,
11- format_time_for_ass ,
12- load_transcript ,
1310 chunk_transcript ,
1411)
1512from src .models .subtitles import (
2320)
2421
2522
23+ def load_transcript (fixture_transcript_path ) -> Transcript :
24+ """Load the transcript fixture."""
25+ with open (fixture_transcript_path , "r" ) as f :
26+ transcript_data = f .read ()
27+ transcript = Transcript .model_validate_json (transcript_data )
28+ return transcript
29+
30+
2631@pytest .fixture
2732def fixture_transcript_path () -> Path :
2833 """Fixture for the path to our mock transcript fixture."""
@@ -31,65 +36,13 @@ def fixture_transcript_path() -> Path:
3136
3237@pytest .fixture
3338def fixture_transcript (fixture_transcript_path ) -> Transcript :
34- """Load the transcript fixture."""
3539 return load_transcript (fixture_transcript_path )
3640
3741
38- def test_format_time_for_srt ():
39- """Test SRT timestamp formatting."""
40- assert format_time_for_srt (0 ) == "00:00:00,000"
41- assert format_time_for_srt (3661.5 ) == "01:01:01,500"
42- assert format_time_for_srt (123.456 ) == "00:02:03,456"
43-
44-
45- def test_format_time_for_vtt ():
46- """Test VTT timestamp formatting."""
47- assert format_time_for_vtt (0 ) == "00:00:00.000"
48- assert format_time_for_vtt (3661.5 ) == "01:01:01.500"
49- assert format_time_for_vtt (123.456 ) == "00:02:03.456"
50-
51-
52- def test_format_time_for_ass ():
53- """Test ASS timestamp formatting."""
54- assert format_time_for_ass (0 ) == "0:00:00.00"
55- assert format_time_for_ass (3661.5 ) == "1:01:01.50"
56- assert format_time_for_ass (123.456 ) == "0:02:03.45"
57-
58-
59- def test_create_srt_track (fixture_transcript_path ):
60- """Test creating an SRT track from a transcript."""
61- srt_track = create_track (
62- fixture_transcript_path ,
63- format = "srt" ,
64- max_duration = 5.0 ,
65- max_words = 14 ,
66- include_speaker_prefix = True ,
67- )
68-
69- # Verify track metadata
70- assert srt_track .metadata .format == TrackFormat .SRT
71- assert srt_track .metadata .language == "en"
72-
73- # Verify that entries were created
74- assert len (srt_track .entries ) > 0
75- assert all (isinstance (entry , SrtEntry ) for entry in srt_track .entries )
76-
77- # Check that speaker prefixes were added
78- assert any ("[Speaker" in entry .text for entry in srt_track .entries )
79-
80- # Test content generation using unified method
81- srt_content = srt_track .content ()
82- assert srt_content .startswith ("1\n " )
83- assert "-->" in srt_content
84-
85- # Verify old method still works for backward compatibility
86- assert srt_track .to_srt_content () == srt_content
87-
88-
89- def test_create_vtt_track (fixture_transcript_path ):
42+ def test_create_vtt_track (fixture_transcript ):
9043 """Test creating a VTT track from a transcript."""
91- vtt_track = create_track (
92- fixture_transcript_path ,
44+ vtt_track = create_subtitles (
45+ fixture_transcript ,
9346 format = "vtt" ,
9447 max_duration = 4.0 ,
9548 max_words = 12 ,
@@ -108,53 +61,8 @@ def test_create_vtt_track(fixture_transcript_path):
10861 assert vtt_content .startswith ("WEBVTT" )
10962 assert "-->" in vtt_content
11063
111- # Verify old method still works for backward compatibility
112- assert vtt_track .to_vtt_content () == vtt_content
113-
114-
115- def test_create_ass_track (fixture_transcript_path ):
116- """Test creating an ASS track from a transcript."""
117- ass_track = create_track (
118- fixture_transcript_path ,
119- format = "ass" ,
120- font_size = 28 ,
121- bg_opacity = 0.3 ,
122- )
123-
124- # Verify track metadata
125- assert ass_track .metadata .format == TrackFormat .ASS
126- assert ass_track .metadata .language == "en"
127- assert ass_track .metadata .style .font_size == 28
128-
129- # Verify that entries were created
130- assert len (ass_track .entries ) > 0
131- assert all (isinstance (entry , AssEntry ) for entry in ass_track .entries )
132-
133- # Test content generation using unified method
134- ass_content = ass_track .content ()
135- assert "[Script Info]" in ass_content
136- assert "Dialogue:" in ass_content
137-
138- # Verify old method still works for backward compatibility
139- assert ass_track .to_ass_content () == ass_content
140-
141-
142- def test_load_transcript (fixture_transcript_path ):
143- """Test that a transcript can be loaded from a JSON file."""
144- transcript = load_transcript (fixture_transcript_path )
145- assert transcript .language == "en"
146- assert len (transcript .segments ) > 0
147-
148- # Test at least one speaker from our fixture
149- speakers = set (
150- segment .speaker for segment in transcript .segments if segment .speaker
151- )
152- assert "SPEAKER_01" in speakers
153- assert "SPEAKER_02" in speakers
154-
15564
15665def test_chunk_transcript (fixture_transcript ):
157- """Test the transcript chunking functionality."""
15866 chunks = chunk_transcript (
15967 fixture_transcript ,
16068 max_duration = 5.0 ,
0 commit comments