From 0b35220e2f3d53fe1c6c2791a1de769e238b4fb0 Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 23 May 2021 23:31:21 +0200 Subject: [PATCH] tests: rewrite dash tests --- lib/svtplay_dl/tests/test_dash.py | 90 ++++++++++++++++--------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/lib/svtplay_dl/tests/test_dash.py b/lib/svtplay_dl/tests/test_dash.py index 09766cb..2ad2bce 100644 --- a/lib/svtplay_dl/tests/test_dash.py +++ b/lib/svtplay_dl/tests/test_dash.py @@ -1,6 +1,5 @@ import datetime import os -import unittest import pytest from svtplay_dl.fetcher.dash import _dashparse @@ -12,52 +11,59 @@ from svtplay_dl.utils.parser import setup_defaults def parse(playlist): with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "dash-manifests", playlist)) as fd: manifest = fd.read() - - return _dashparse(setup_defaults(), manifest, "http://localhost", {}, None) + streams = {} + for i in list(_dashparse(setup_defaults(), manifest, "http://localhost", {}, None)): + streams[i.bitrate] = i + return streams -class dashtest(unittest.TestCase): - def test_parse_cmore(self): - data = yield from parse("cmore.mpd") - assert len(data[3261.367].files) == 410 - assert len(data[3261.367].audio) == 615 - assert data[3261.367].segments +def test_parse_cmore(): + data = parse("cmore.mpd") + assert len(data[3261].files) == 410 + assert len(data[3261].audio) == 615 + assert data[3261].segments - def test_parse_fff(self): - data = yield from parse("fff.mpd") - assert len(data[3187.187].files) == 578 - assert len(data[3187.187].audio) == 577 - assert data[3187.187].segments - def test_parse_nya(self): - data = yield from parse("svtvod.mpd") - assert len(data[2793.0].files) == 350 - assert len(data[2793.0].audio) == 350 - assert data[2793.0].segments +def test_parse_fff(): + data = parse("fff.mpd") + assert len(data[3187].files) == 578 + assert len(data[3187].audio) == 577 + assert data[3187].segments - def test_parse_live(self): - data = yield from parse("svtplay-live.mpd") - assert len(data[2795.9959999999996].files) == 6 - assert len(data[2795.9959999999996].audio) == 6 - assert data[2795.9959999999996].segments - def test_parse_live2(self): - data = yield from parse("svtplay-live2.mpd") - assert len(data[2892.0].files) == 11 - assert len(data[2892.0].audio) == 11 - assert data[2892.0].segments +def test_parse_nya(): + data = parse("svtvod.mpd") + assert len(data[2793].files) == 350 + assert len(data[2793].audio) == 350 + assert data[2793].segments - def test_parse_duration(self): - assert parse_duration("PT3459.520S") == 3459.52 - assert parse_duration("PT2.00S") == 2.0 - assert parse_duration("PT1H0M30.000S") == 3630.0 - assert parse_duration("P1Y1M1DT1H0M30.000S") == 34218030.0 - assert parse_duration("mMWroNG") == 0 - def test_parse_date(self): - assert isinstance(parse_dates("2021-05-10T06:00:11.451554796Z"), datetime.datetime) - assert isinstance(parse_dates("2021-05-10T06:00:11.45Z"), datetime.datetime) - assert isinstance(parse_dates("2021-05-10T06:00:11Z"), datetime.datetime) - assert isinstance(parse_dates("2021-05-10T06:00:11"), datetime.datetime) - with pytest.raises(ValueError): - assert parse_dates("2021-05-10Z06:00:11.45Z") +def test_parse_live(): + data = parse("svtplay-live.mpd") + assert len(data[2795].files) == 6 + assert len(data[2795].audio) == 6 + assert data[2795].segments + + +def test_parse_live2(): + data = parse("svtplay-live2.mpd") + assert len(data[2892.0].files) == 11 + assert len(data[2892.0].audio) == 11 + assert data[2892.0].segments + + +def test_parse_duration(): + assert parse_duration("PT3459.520S") == 3459.52 + assert parse_duration("PT2.00S") == 2.0 + assert parse_duration("PT1H0M30.000S") == 3630.0 + assert parse_duration("P1Y1M1DT1H0M30.000S") == 34218030.0 + assert parse_duration("mMWroNG") == 0 + + +def test_parse_date(): + assert isinstance(parse_dates("2021-05-10T06:00:11.451554796Z"), datetime.datetime) + assert isinstance(parse_dates("2021-05-10T06:00:11.45Z"), datetime.datetime) + assert isinstance(parse_dates("2021-05-10T06:00:11Z"), datetime.datetime) + assert isinstance(parse_dates("2021-05-10T06:00:11"), datetime.datetime) + with pytest.raises(ValueError): + assert parse_dates("2021-05-10Z06:00:11.45Z")