1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-03 16:44:17 +01:00
svtplay-dl/lib/svtplay_dl/tests/test_protocol_prio.py

36 lines
1.0 KiB
Python
Raw Normal View History

2016-03-13 16:52:54 +01:00
#!/usr/bin/python
# ex:ts=4:sw=4:sts=4:et:fenc=utf-8
import unittest
2019-08-25 00:40:39 +02:00
from svtplay_dl.utils.stream import protocol_prio
2016-03-13 16:52:54 +01:00
2018-01-30 20:11:37 +01:00
2019-08-25 00:33:51 +02:00
class VideoRetriever:
2016-03-13 16:52:54 +01:00
def __init__(self, proto, bitrate):
self.proto = proto
self.bitrate = bitrate
self.name = proto
2018-01-30 20:11:37 +01:00
2016-03-13 16:52:54 +01:00
def __repr__(self):
2021-12-18 19:52:08 +01:00
return f"{self.proto.upper()}({self.bitrate})"
2016-03-13 16:52:54 +01:00
2018-01-30 20:11:37 +01:00
2016-03-13 16:52:54 +01:00
class PrioStreamsTest(unittest.TestCase):
def _gen_proto_case(self, ordered, unordered, expected=None):
streams = [VideoRetriever(x, 100) for x in unordered]
2016-03-13 16:52:54 +01:00
kwargs = {}
if expected is None:
expected = [str(VideoRetriever(x, 100)) for x in ordered]
2016-03-13 16:52:54 +01:00
2019-08-31 01:02:59 +02:00
return [str(x) for x in protocol_prio(streams, ordered, **kwargs)] == expected
2016-03-13 16:52:54 +01:00
def test_custom_order(self):
assert self._gen_proto_case(["http", "hls"], ["hls", "http"])
2016-03-13 16:52:54 +01:00
def test_custom_order_1(self):
assert self._gen_proto_case(["http"], ["hls", "http"])
2016-03-13 16:52:54 +01:00
def test_proto_unavail(self):
assert self._gen_proto_case(["http"], ["hls", "https"], expected=[])