-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
65 lines (51 loc) · 1.77 KB
/
tests.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
53
54
55
56
57
58
59
60
61
62
63
64
65
from main import read_srt, merge_overlapping
def test_simple_srt_block():
text = """1
00:00:03,100 --> 00:00:03,560
Within the spreading darkness
"""
expected = {
'index': "1",
'start': "00:00:03,100",
'end': "00:00:03,560",
'text': "Within the spreading darkness",
}
srt_blocks = list(read_srt(text))
assert srt_blocks == [expected]
def test_multiline_srt_block():
text = """1
00:00:03,100 --> 00:00:03,560
Within the spreading darkness
Is eternal damnation
"""
expected = {
'index': "1",
'start': "00:00:03,100",
'end': "00:00:03,560",
'text': "Within the spreading darkness\nIs eternal damnation",
}
srt_blocks = list(read_srt(text))
assert srt_blocks == [expected]
def test_merge_overlapping_one():
srt_blocks = [
{ 'index': '1', 'start': "00:00:03,100", 'end': "00:00:03,560", 'text': "foo" },
]
assert list(merge_overlapping(srt_blocks)) == srt_blocks
def test_merge_overlapping_two():
srt_blocks = [
{ 'index': '1', 'start': "00:00:03,100", 'end': "00:00:03,560", 'text': "foo" },
{ 'index': '2', 'start': "00:00:03,400", 'end': "00:00:03,800", 'text': "bar" },
]
expected = [
{ 'index': '1', 'start': "00:00:03,100", 'end': "00:00:03,800", 'text': "foo\nbar" },
]
assert list(merge_overlapping(srt_blocks)) == expected
def test_expand_same_text():
srt_blocks = [
{ 'index': '1', 'start': "00:00:03,100", 'end': "00:00:03,560", 'text': "foo" },
{ 'index': '2', 'start': "00:00:03,400", 'end': "00:00:03,800", 'text': "foo" },
]
expected = [
{ 'index': '1', 'start': "00:00:03,100", 'end': "00:00:03,800", 'text': "foo" },
]
assert list(merge_overlapping(srt_blocks)) == expected