-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser.py
More file actions
executable file
·70 lines (54 loc) · 1.92 KB
/
test_parser.py
File metadata and controls
executable file
·70 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
"""
Simple test script to verify SRT parsing works correctly.
This tests the parser without making any API calls.
"""
import sys
import os
# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from translate_srt import SRTTranslator
def test_srt_parsing():
"""Test that SRT parsing works correctly."""
print("Testing SRT Parser...")
print("=" * 50)
# Find the SRT file
srt_files = [f for f in os.listdir('.') if f.endswith('.srt')]
if not srt_files:
print("❌ No SRT files found in current directory")
return False
srt_file = srt_files[0]
print(f"📄 Testing with: {srt_file}")
print()
# Create translator instance
translator = SRTTranslator()
try:
# Parse the SRT file
entries = translator.parse_srt(srt_file)
print(f"✅ Successfully parsed {len(entries)} subtitle entries")
print()
# Show first 3 entries
print("First 3 entries:")
print("-" * 50)
for i, entry in enumerate(entries[:3], 1):
print(f"\nEntry #{entry.index}:")
print(f" Time: {entry.timestamp}")
print(f" Text: {entry.text[:50]}..." if len(entry.text) > 50 else f" Text: {entry.text}")
print()
print("-" * 50)
print("✅ SRT Parser Test PASSED!")
print()
print("The parser is working correctly.")
print("You can now use translate_srt.py to translate your subtitles.")
print()
print("Example:")
print(f" python translate_srt.py \"{srt_file}\" -t es")
return True
except Exception as e:
print(f"❌ Error parsing SRT file: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == '__main__':
success = test_srt_parsing()
sys.exit(0 if success else 1)