/
test_srt_conversion.py
52 lines (37 loc) · 1.74 KB
/
test_srt_conversion.py
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
import unittest
import six
from pycaption import (
SRTReader, SRTWriter, SAMIWriter, DFXPWriter, WebVTTWriter)
from tests.samples.dfxp import SAMPLE_DFXP
from tests.samples.srt import SAMPLE_SRT
from tests.samples.sami import SAMPLE_SAMI
from tests.samples.webvtt import SAMPLE_WEBVTT_FROM_SRT
from tests.mixins import (
SRTTestingMixIn, DFXPTestingMixIn, SAMITestingMixIn, WebVTTTestingMixIn)
class SRTtoSRTTestCase(unittest.TestCase, SRTTestingMixIn):
def test_srt_to_srt_conversion(self):
caption_set = SRTReader().read(SAMPLE_SRT)
results = SRTWriter().write(caption_set)
self.assertTrue(isinstance(results, six.text_type))
self.assertSRTEquals(SAMPLE_SRT, results)
class SRTtoSAMITestCase(unittest.TestCase, SAMITestingMixIn):
def test_srt_to_sami_conversion(self):
caption_set = SRTReader().read(SAMPLE_SRT)
results = SAMIWriter().write(caption_set)
self.assertTrue(isinstance(results, six.text_type))
self.assertSAMIEquals(SAMPLE_SAMI, results)
class SRTtoDFXPTestCase(unittest.TestCase, DFXPTestingMixIn):
def test_srt_to_dfxp_conversion(self):
caption_set = SRTReader().read(SAMPLE_SRT)
results = DFXPWriter().write(caption_set)
self.assertTrue(isinstance(results, six.text_type))
self.assertDFXPEquals(
SAMPLE_DFXP, results,
ignore_styling=True, ignore_spans=True
)
class SRTtoWebVTTTestCase(unittest.TestCase, WebVTTTestingMixIn):
def test_srt_to_webvtt_conversion(self):
caption_set = SRTReader().read(SAMPLE_SRT)
results = WebVTTWriter().write(caption_set)
self.assertTrue(isinstance(results, six.text_type))
self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_SRT, results)