twitch-dl/tests/test_progress.py

112 lines
2.8 KiB
Python
Raw Normal View History

2022-08-13 07:38:54 +00:00
from twitchdl.progress import Progress
def test_initial_values():
progress = Progress(10)
assert progress.downloaded == 0
assert progress.estimated_total is None
assert progress.progress_perc == 0
assert progress.remaining_time is None
assert progress.speed is None
assert progress.vod_count == 10
assert progress.vod_downloaded_count == 0
def test_downloaded():
progress = Progress(3)
progress.start(1, 300)
progress.start(2, 300)
progress.start(3, 300)
assert progress.downloaded == 0
assert progress.progress_bytes == 0
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 0
progress.advance(1, 100)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.downloaded == 100
assert progress.progress_bytes == 100
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 11
progress.advance(2, 200)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.downloaded == 300
assert progress.progress_bytes == 300
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 33
progress.advance(3, 150)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.downloaded == 450
assert progress.progress_bytes == 450
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 50
progress.advance(1, 50)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.downloaded == 500
assert progress.progress_bytes == 500
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 55
progress.abort(2)
2024-04-28 08:16:33 +00:00
progress._recalculate()
assert progress.downloaded == 500
assert progress.progress_bytes == 300
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 33
progress.start(2, 300)
progress.advance(1, 150)
progress.advance(2, 300)
progress.advance(3, 150)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.downloaded == 1100
assert progress.progress_bytes == 900
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 100
progress.end(1)
progress.end(2)
progress.end(3)
assert progress.downloaded == 1100
assert progress.progress_bytes == 900
2022-08-13 07:38:54 +00:00
assert progress.progress_perc == 100
def test_estimated_total():
progress = Progress(3)
assert progress.estimated_total is None
progress.start(1, 12000)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.estimated_total == 12000 * 3
progress.start(2, 11000)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.estimated_total == 11500 * 3
progress.start(3, 10000)
2024-04-28 08:16:33 +00:00
progress._recalculate()
2022-08-13 07:38:54 +00:00
assert progress.estimated_total == 11000 * 3
def test_vod_downloaded_count():
progress = Progress(3)
progress.start(1, 100)
progress.start(2, 100)
progress.start(3, 100)
assert progress.vod_downloaded_count == 0
progress.advance(1, 100)
progress.end(1)
assert progress.vod_downloaded_count == 1
progress.advance(2, 100)
progress.end(2)
assert progress.vod_downloaded_count == 2
progress.advance(3, 100)
progress.end(3)
assert progress.vod_downloaded_count == 3