1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-23 11:45:38 +01:00

Add support for pytest

This commit is contained in:
Johan Andersson 2019-08-31 01:02:59 +02:00
parent 4a91967144
commit 375f7d8946
12 changed files with 109 additions and 86 deletions

6
.coveragerc Normal file
View File

@ -0,0 +1,6 @@
[run]
branch = true
include = lib/svtplay_dl/*
omit =
lib/svtplay_dl/__version__.py
*/tests/*

View File

@ -16,8 +16,7 @@ install:
- pip install -r requirements-dev.txt -r requirements.txt awscli
script:
- python --version
- flake8 --jobs 8 lib/svtplay_dl
- nosetests -v --all-modules --with-doctest svtplay_dl
- pytest --cov
- make
- |
if [[ "$CIBUILD" == "1" && "$TRAVIS_PULL_REQUEST" == "false" ]]

View File

@ -1,54 +0,0 @@
from __future__ import absolute_import
import os
import unittest
from svtplay_dl.fetcher.dash import _dashparse
from svtplay_dl.fetcher.dash import parse_duration
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, None)
class dashtest(unittest.TestCase):
def test_parse_cmore(self):
data = parse("cmore.mpd")
self.assertEquals(len(data[3261.367].files), 410)
self.assertEqual(len(data[3261.367].audio), 615)
self.assertTrue(data[3261.367].segments)
def test_parse_fff(self):
data = parse("fff.mpd")
self.assertEquals(len(data[3187.187].files), 578)
self.assertEqual(len(data[3187.187].audio), 577)
self.assertTrue(data[3187.187].segments)
def test_parse_nya(self):
data = parse("svtvod.mpd")
self.assertEquals(len(data[2793.0].files), 350)
self.assertEqual(len(data[2793.0].audio), 350)
self.assertTrue(data[2793.0].segments)
def test_parse_live(self):
data = parse("svtplay-live.mpd")
self.assertEquals(len(data[2795.9959999999996].files), 6)
self.assertEqual(len(data[2795.9959999999996].audio), 6)
self.assertTrue(data[2795.9959999999996].segments)
def test_parse_live2(self):
data = parse("svtplay-live2.mpd")
self.assertEquals(len(data[2892.0].files), 11)
self.assertEqual(len(data[2892.0].audio), 11)
self.assertTrue(data[2892.0].segments)
def test_parse_duration(self):
self.assertEquals(parse_duration("PT3459.520S"), 3459.52)
self.assertEquals(parse_duration("PT2.00S"), 2.0)
self.assertEquals(parse_duration("PT1H0M30.000S"), 3630.0)
self.assertEquals(parse_duration("P1Y1M1DT1H0M30.000S"), 34218030.0)
self.assertEquals(parse_duration("PWroNG"), 0)

View File

@ -0,0 +1,54 @@
from __future__ import absolute_import
import os
import unittest
from svtplay_dl.fetcher.dash import _dashparse
from svtplay_dl.fetcher.dash import parse_duration
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, None)
class dashtest(unittest.TestCase):
def test_parse_cmore(self):
data = 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_fff(self):
data = 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 = 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_live(self):
data = 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 = 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(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("PWroNG") == 0

View File

@ -303,4 +303,4 @@ class formatnameTest(unittest.TestCase):
config.set("filename", item[0])
service = Service(config, "localhost")
service.output.update(item[1])
self.assertEqual(_formatname(service.output, config, "mp4"), item[2])
assert _formatname(service.output, config, "mp4") == item[2]

View File

@ -75,4 +75,4 @@ class HlsTest(unittest.TestCase):
}
# More examples can be found on "https://developer.apple.com/streaming/examples/"
]:
self.assertEqual(M3U8(test["playlist"]).master_playlist, test["expected"])
assert M3U8(test["playlist"]).master_playlist == test["expected"]

View File

@ -22,4 +22,4 @@ class HttpTest(unittest.TestCase):
# with query parameters
{"srcurl": "http://example.com/bar?baz=qux", "segment": "foo.ts", "expected": "http://example.com/foo.ts"},
]:
self.assertEqual(get_full_url(test["segment"], test["srcurl"]), test["expected"])
assert get_full_url(test["segment"], test["srcurl"]) == test["expected"]

View File

@ -31,7 +31,7 @@ class progressTest(unittest.TestCase):
@patch("svtplay_dl.utils.output.progressbar")
def test_0_0(self, pbar):
svtplay_dl.utils.output.progress(0, 0)
self.assertFalse(pbar.called)
assert not pbar.called
@patch("svtplay_dl.utils.output.progressbar")
def test_0_100(self, pbar):
@ -52,32 +52,32 @@ class progressbarTest(unittest.TestCase):
def test_0_100(self):
svtplay_dl.utils.output.progressbar(100, 0)
self.assertEqual(self.mockfile.read(), "\r[000/100][..........] ")
assert self.mockfile.read() == "\r[000/100][..........] "
def test_progress_1_100(self):
svtplay_dl.utils.output.progressbar(100, 1)
self.assertEqual(self.mockfile.read(), "\r[001/100][..........] ")
assert self.mockfile.read() == "\r[001/100][..........] "
def test_progress_2_100(self):
svtplay_dl.utils.output.progressbar(100, 2)
self.assertEqual(self.mockfile.read(), "\r[002/100][..........] ")
assert self.mockfile.read() == "\r[002/100][..........] "
def test_progress_50_100(self):
svtplay_dl.utils.output.progressbar(100, 50)
self.assertEqual(self.mockfile.read(), "\r[050/100][=====.....] ")
assert self.mockfile.read() == "\r[050/100][=====.....] "
def test_progress_100_100(self):
svtplay_dl.utils.output.progressbar(100, 100)
self.assertEqual(self.mockfile.read(), "\r[100/100][==========] ")
assert self.mockfile.read() == "\r[100/100][==========] "
def test_progress_20_100_msg(self):
svtplay_dl.utils.output.progressbar(100, 20, "msg")
self.assertEqual(self.mockfile.read(), "\r[020/100][==........] msg")
assert self.mockfile.read() == "\r[020/100][==........] msg"
def test_progress_20_100_termwidth(self):
svtplay_dl.utils.output.get_terminal_size = lambda: (75, 25)
svtplay_dl.utils.output.progressbar(100, 20)
self.assertEqual(self.mockfile.read(), "\r[020/100][=======............................] ")
assert self.mockfile.read() == "\r[020/100][=======............................] "
class EtaTest(unittest.TestCase):
@ -89,25 +89,25 @@ class EtaTest(unittest.TestCase):
# processes one item per second, and make the size be
# 100.
eta = svtplay_dl.utils.output.ETA(100)
self.assertEqual(eta.left, 100) # no progress yet
self.assertEqual(str(eta), "(unknown)") # no progress yet
assert eta.left == 100 # no progress yet
assert str(eta) == "(unknown)" # no progress yet
mock_time.return_value = float(10) # sleep(10)
eta.update(10)
self.assertEqual(eta.left, 90)
self.assertEqual(str(eta), "0:01:30") # 90 items left, 90s left
assert eta.left == 90
assert str(eta) == "0:01:30" # 90 items left, 90s left
mock_time.return_value += 1
eta.increment() # another item completed in one second!
self.assertEqual(eta.left, 89)
self.assertEqual(str(eta), "0:01:29")
assert eta.left == 89
assert str(eta) == "0:01:29"
mock_time.return_value += 9
eta.increment(9) # another item completed in one second!
self.assertEqual(eta.left, 80)
self.assertEqual(str(eta), "0:01:20")
assert eta.left == 80
assert str(eta) == "0:01:20"
mock_time.return_value = float(90) # sleep(79)
eta.update(90)
self.assertEqual(eta.left, 10)
self.assertEqual(str(eta), "0:00:10")
assert eta.left == 10
assert str(eta) == "0:00:10"

View File

@ -25,13 +25,13 @@ class PrioStreamsTest(unittest.TestCase):
if expected is None:
expected = [str(VideoRetriever(x, 100)) for x in ordered]
return self.assertEqual([str(x) for x in protocol_prio(streams, ordered, **kwargs)], expected)
return [str(x) for x in protocol_prio(streams, ordered, **kwargs)] == expected
def test_custom_order(self):
return self._gen_proto_case(["http", "hds", "hls"], ["hds", "hls", "http"])
assert self._gen_proto_case(["http", "hds", "hls"], ["hds", "hls", "http"])
def test_custom_order_1(self):
return self._gen_proto_case(["http"], ["hds", "hls", "http"])
assert self._gen_proto_case(["http"], ["hds", "hls", "http"])
def test_proto_unavail(self):
return self._gen_proto_case(["http", "hds"], ["hls", "https"], expected=[])
assert self._gen_proto_case(["http", "hds"], ["hls", "https"], expected=[])

View File

@ -18,13 +18,13 @@ class timestrTest(unittest.TestCase):
# pylint: disable-msg=no-member
def test_1(self):
self.assertEqual(svtplay_dl.subtitle.timestr(1), "00:00:00,001")
assert svtplay_dl.subtitle.timestr(1) == "00:00:00,001"
def test_100(self):
self.assertEqual(svtplay_dl.subtitle.timestr(100), "00:00:00,100")
assert svtplay_dl.subtitle.timestr(100) == "00:00:00,100"
def test_3600(self):
self.assertEqual(svtplay_dl.subtitle.timestr(3600), "00:00:03,600")
assert svtplay_dl.subtitle.timestr(3600) == "00:00:03,600"
def test_3600000(self):
self.assertEqual(svtplay_dl.subtitle.timestr(3600000), "01:00:00,000")
assert svtplay_dl.subtitle.timestr(3600000) == "01:00:00,000"

View File

@ -6,6 +6,8 @@ from __future__ import absolute_import
import unittest
from svtplay_dl.utils.parser import setup_defaults
from svtplay_dl.utils.text import exclude
from svtplay_dl.utils.text import filenamify
@ -22,4 +24,18 @@ class filenamifyTest(unittest.TestCase):
def test(self):
for inp, ref in self.test_values:
self.assertEqual(filenamify(inp), ref)
assert filenamify(inp) == ref
def test_exclude_true(self):
config = setup_defaults()
config.set("exclude", "hej")
assert exclude(config, "hejsanhoppsan")
def test_exclude_false(self):
config = setup_defaults()
config.set("exclude", "hej")
assert not exclude(config, "hoppsan")
def test_exlude_default(self):
config = setup_defaults()
assert not exclude(config, "hoppsan")

View File

@ -3,3 +3,5 @@ nose
mock
wheel
pre-commit
pytest
pytest-cov