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
|
|
|
|
2018-09-08 22:21:54 +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
|
2018-09-08 22:21:54 +02:00
|
|
|
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):
|
2016-03-29 19:39:26 +02:00
|
|
|
def _gen_proto_case(self, ordered, unordered, expected=None):
|
2018-09-08 22:21:54 +02:00
|
|
|
streams = [VideoRetriever(x, 100) for x in unordered]
|
2016-03-13 16:52:54 +01:00
|
|
|
|
|
|
|
kwargs = {}
|
|
|
|
if expected is None:
|
2018-09-08 22:21:54 +02:00
|
|
|
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):
|
2021-05-09 01:16:16 +02:00
|
|
|
assert self._gen_proto_case(["http", "hls"], ["hls", "http"])
|
2016-03-13 16:52:54 +01:00
|
|
|
|
|
|
|
def test_custom_order_1(self):
|
2021-05-09 01:16:16 +02:00
|
|
|
assert self._gen_proto_case(["http"], ["hls", "http"])
|
2016-03-13 16:52:54 +01:00
|
|
|
|
|
|
|
def test_proto_unavail(self):
|
2021-05-09 01:16:16 +02:00
|
|
|
assert self._gen_proto_case(["http"], ["hls", "https"], expected=[])
|