test: delete slow, timing-based and redundant tests

This commit is contained in:
imSp4rky
2026-12-05 15:20:05 -07:00
parent 783a2fc185
commit 3a0a74e694
292 changed files with 153 additions and 15174 deletions
+2 -115
View File
@@ -1,7 +1,5 @@
"""The free-space preflight warns before the downloads when the temp volume cannot hold a title's tracks."""
import threading
import time
from functools import partial
from pathlib import Path
from types import SimpleNamespace
@@ -11,14 +9,13 @@ import m3u8
import pytest
import requests
from tests.lang_selection import test_kind_only_selection as harness
from unshackle.commands import dl as dl_module
from unshackle.commands.dl import DiskCheck
from unshackle.core.config import config
from unshackle.core.manifests import DASH, HLS, ISM
from unshackle.core.tracks import Audio, Subtitle, Tracks
from unshackle.core.tracks import Audio, Tracks
from unshackle.core.tracks.track import Track
from unshackle.core.utils.bitrate import manifest_seconds, playlist_size
from unshackle.core.utils.bitrate import manifest_seconds
GB = 1_000_000_000
@@ -95,20 +92,6 @@ def test_a_temp_volume_too_small_for_twice_the_tracks_gets_one_warning_line(
assert line == f"Temp volume {tmp_path} has 3.1 GB free, the selected tracks need about 15.0 GB"
def test_enough_free_space_gives_no_warning(free_space: list[int]) -> None:
free_space[0] = 15 * GB
assert low_disk_warning(dash_tracks(mpd(period()))) is None
def test_hls_tracks_count_nothing_before_their_playlist_is_read(free_space: list[int]) -> None:
free_space[0] = 0
tracks = HLS.from_text(HLS_MASTER, "https://cdn.example/x.m3u8").to_tracks("en")
assert tracks.videos and manifest_seconds(tracks.videos[0]) is None
assert low_disk_warning(tracks) is None
def test_a_dash_track_counts_only_its_content_periods() -> None:
manifest = mpd(period('id="ad" duration="PT10M"') + period('id="main" duration="PT50M"'))
track = DASH.from_text(manifest, "https://cdn.example/x.mpd").to_tracks("en").videos[0]
@@ -117,21 +100,6 @@ def test_a_dash_track_counts_only_its_content_periods() -> None:
assert manifest_seconds(track) == 3000
def test_a_dash_track_skips_a_period_that_does_not_carry_it() -> None:
other = period('id="b" duration="PT30M"').replace('width="3840" height="2160"', 'width="1920" height="1080"')
manifest = mpd(period('id="a" duration="PT30M"') + other)
video = dash_tracks(manifest).videos[0]
assert video.height == 2160
assert manifest_seconds(video) == 1800
def test_a_duration_the_parser_cannot_read_gives_no_warning(free_space: list[int]) -> None:
free_space[0] = 0
assert low_disk_warning(dash_tracks(mpd(period(), total="P0DT1H"))) is None
def test_a_dash_period_of_unknown_length_takes_the_presentation_length() -> None:
manifest = mpd(period('id="a"') + period('id="b"'), total="PT1H")
@@ -168,19 +136,6 @@ def test_an_unreadable_temp_volume_gives_no_warning(free_space: list[int], monke
assert low_disk_warning(dash_tracks(mpd(period()))) is None
def test_dl_logs_the_warning_once_per_title_and_not_with_skip_dl(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
) -> None:
monkeypatch.setattr(dl_module, "DiskCheck", lambda tracks, warn: warn("Temp volume is short"))
harness.run(monkeypatch, caplog, {1: {}, 2: {}}, to_end=True, no_mux=True)
assert caplog.text.count("Temp volume is short") == 2
caplog.clear()
harness.run(monkeypatch, caplog, {1: {}}, to_end=True, skip_dl=True)
assert "Temp volume is short" not in caplog.text
def test_an_hls_track_warns_once_when_its_playlist_is_read(free_space: list[int], tmp_path: Path) -> None:
free_space[0] = 3_100_000_000
video = HLS.from_text(HLS_MASTER, "https://cdn.example/x.m3u8").to_tracks("en").videos[0]
@@ -206,38 +161,6 @@ def test_a_mixed_title_counts_each_track_once_against_one_free_space_reading(
assert lines == [f"Temp volume {tmp_path} has 20.0 GB free, the selected tracks need about 21.0 GB"]
def test_a_second_worker_waits_for_the_first_and_gives_no_second_warning(free_space: list[int]) -> None:
free_space[0] = GB
check, lines = new_check()
second_started = threading.Event()
def first_size() -> float:
assert second_started.wait(5)
return 2 * GB
second = threading.Thread(target=lambda: (second_started.set(), check.add(lambda: 2 * GB)))
first = threading.Thread(target=check.add, args=(first_size,))
first.start()
deadline = time.monotonic() + 5
while not check.lock.locked() and time.monotonic() < deadline:
time.sleep(0.001)
second.start()
first.join(5)
second.join(5)
assert len(lines) == 1
def test_a_subtitle_counts_nothing(free_space: list[int]) -> None:
free_space[0] = 0
check, lines = new_check()
subtitle = Subtitle(url="https://cdn.example/s.m3u8", language="en", codec=Subtitle.Codec.WebVTT)
check.add_segments(subtitle, media_segments(3, byterange="1000000000"))
assert lines == []
def test_an_estimate_error_ends_the_check(free_space: list[int]) -> None:
free_space[0] = 0
check, lines = new_check()
@@ -248,20 +171,6 @@ def test_an_estimate_error_ends_the_check(free_space: list[int]) -> None:
assert lines == []
@pytest.mark.parametrize(
("bitrate", "segments", "size"),
[
(16_000_000, media_segments(3, byterange="1000@0"), 3000),
(16_000_000, media_segments(2, byterange="1000@0") + media_segments(1), 16_000_000 * 18 / 8),
(8, media_segments(1, byterange="x"), 6),
(None, media_segments(3), 0),
],
ids=["byte ranges", "a segment without a range", "an unreadable range", "no bitrate"],
)
def test_playlist_size(bitrate: int | None, segments: list[Any], size: float) -> None:
assert playlist_size(bitrate, segments) == size
def test_the_hls_step_hands_over_its_wanted_segments_before_any_segment_downloads(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
@@ -293,25 +202,3 @@ def test_the_hls_step_hands_over_its_wanted_segments_before_any_segment_download
assert handed == [(track, ["seg.m4s"])]
assert not list(tmp_path.glob("*_segments/*"))
def test_dl_hands_each_track_download_the_check_of_its_title(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
) -> None:
class Recorder(DiskCheck):
def __init__(self, tracks: Tracks, warn: Any) -> None:
checks.append(self)
checks: list[Recorder] = []
handed: list[Any] = []
monkeypatch.setattr(dl_module, "DiskCheck", Recorder)
monkeypatch.setattr(Track, "download", lambda self, *a, **k: handed.append(k["on_segments"]))
def download_all(tracks: Any, workers: int, run_one: Any, **_: Any) -> None:
for i, track in enumerate(tracks):
run_one(track, i)
harness.run(monkeypatch, caplog, {1: {}}, to_end=True, no_mux=True, download=download_all)
assert len(checks) == 1 and len(handed) == 3
assert all(on_segments == checks[0].add_segments for on_segments in handed)