-
Notifications
You must be signed in to change notification settings - Fork 475
/
test_version_matching_rules.py
145 lines (127 loc) · 3.61 KB
/
test_version_matching_rules.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from m3u8.version_matching_rules import (
ValidEXTXBYTERANGEOrEXTXIFRAMESONLY,
ValidFloatingPointEXTINF,
ValidIVInEXTXKEY,
)
def test_invalid_iv_in_EXT_X_KEY():
validator = ValidIVInEXTXKEY(
version=1,
line_number=1,
line="#EXT-X-KEY: METHOD=AES-128, IV=0x123456789ABCDEF0123456789ABCDEF0, URI=https://example.com/key.bin",
)
assert not validator.validate()
def test_valid_iv_in_EXT_X_KEY():
examples = [
{
"line": "#EXT-X-KEY: METHOD=AES-128, URI=https://example.com/key.bin",
"version": 1,
"expected": True,
},
{
"line": "#EXT-X-KEY: METHOD=AES-128, IV=0x123456789ABCDEF0123456789ABCDEF0, URI=https://example.com/key.bin",
"version": 2,
"expected": True,
},
{
"line": "#EXT-X-KEY: METHOD=AES-128, IV=0x123456789ABCDEF0123456789ABCDEF0, URI=https://example.com/key.bin",
"version": 3,
"expected": True,
},
# Invalid case
{
"line": "#EXT-X-KEY: METHOD=AES-128, IV=0x123456789ABCDEF0123456789ABCDEF0, URI=https://example.com/key.bin",
"version": 1,
"expected": False,
},
]
for example in examples:
validator = ValidIVInEXTXKEY(
version=example["version"],
line_number=1,
line=example["line"],
)
assert validator.validate() == example["expected"]
def test_invalid_floating_point_EXTINF():
examples = [
{
"line": "#EXTINF: 10.5,",
"version": 2,
},
{
"line": "#EXTINF: A,",
"version": 3,
},
]
for example in examples:
validator = ValidFloatingPointEXTINF(
version=example["version"],
line_number=1,
line=example["line"],
)
assert not validator.validate()
def test_valid_floating_point_EXTINF():
examples = [
{
"line": "#EXTINF: 10,",
"version": 2,
},
{
"line": "#EXTINF: 10.5,",
"version": 3,
},
{
"line": "#EXTINF: 10.5,",
"version": 4,
},
]
for example in examples:
validator = ValidFloatingPointEXTINF(
version=example["version"],
line_number=1,
line=example["line"],
)
assert validator.validate()
def test_invalid_EXT_X_BYTERANGE_or_EXT_X_I_FRAMES_ONLY():
examples = [
{
"line": "#EXT-X-BYTERANGE: 200000@1000",
"version": 3,
},
{
"line": "#EXT-X-I-FRAMES-ONLY",
"version": 3,
},
]
for example in examples:
validator = ValidEXTXBYTERANGEOrEXTXIFRAMESONLY(
version=example["version"],
line_number=1,
line=example["line"],
)
assert not validator.validate()
def test_valid_EXT_X_BYTERANGE_or_EXT_X_I_FRAMES_ONLY():
examples = [
{
"line": "#EXT-X-BYTERANGE: 200000@1000",
"version": 4,
},
{
"line": "#EXT-X-I-FRAMES-ONLY",
"version": 4,
},
{
"line": "#EXT-X-BYTERANGE: 200000@1000",
"version": 5,
},
{
"line": "#EXT-X-I-FRAMES-ONLY",
"version": 5,
},
]
for example in examples:
validator = ValidEXTXBYTERANGEOrEXTXIFRAMESONLY(
version=example["version"],
line_number=1,
line=example["line"],
)
assert validator.validate()