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
-108
View File
@@ -13,14 +13,10 @@ from unittest.mock import MagicMock
import click
import pytest
from requests import Session
from tests.admission import refusal
from unshackle.core.config import config
from unshackle.core.manifests.dash import DASH
from unshackle.core.placement import sample_name
from unshackle.core.services import Services
from unshackle.core.titles import Episode, Movie
from unshackle.core.tracks import Audio, Chapter, Subtitle, Tracks, Video
from unshackle.core.tracks.track import parse_sidx
from unshackle.core.utils.click_types import SAMPLE_RANGE
@@ -37,10 +33,6 @@ def make_audio(url: str = "https://x/a") -> Audio:
return Audio(id_="a", url=url, codec=Audio.Codec.AAC, language="en", bitrate=128000)
def test_no_window_keeps_every_segment() -> None:
assert make_audio().sample_slice(STARTS, 1000) == slice(None)
def test_the_window_is_measured_from_the_first_segment() -> None:
track = make_audio()
assert track.sample_slice(STARTS, 1000, (62, 120)) == slice(15, 30)
@@ -63,11 +55,6 @@ def test_a_subtitle_keeps_one_segment_on_each_side_of_the_window() -> None:
assert subtitle.sample_slice(STARTS, 1000, None) == slice(None)
def test_a_subtitle_that_ends_before_the_window_keeps_its_last_segment() -> None:
subtitle = Subtitle(id_="s", url="https://x/s", codec=Subtitle.Codec.WebVTT, language="en")
assert subtitle.sample_slice([0, 4000], 1000, (120, 180)) == slice(0, None)
def test_a_window_after_the_end_stops_the_run() -> None:
with pytest.raises(click.ClickException, match="ends before the sample window"):
make_audio().sample_slice(STARTS[:10], 1000, (120, 180))
@@ -180,30 +167,6 @@ def served(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> str:
server.shutdown()
def test_an_hls_subtitle_downloads_the_segments_around_the_window(
tmp_path: Path, served: str, monkeypatch: pytest.MonkeyPatch
) -> None:
for n in range(8):
(tmp_path / f"s{n}.vtt").write_text(
f"WEBVTT\n\n00:00:{n * 10 + 1:02}.000 --> 00:00:{n * 10 + 2:02}.000\ncue {n}\n"
)
(tmp_path / "s.m3u8").write_text(
"#EXTM3U\n#EXT-X-TARGETDURATION:10\n"
+ "".join(f"#EXTINF:10.0,\ns{n}.vtt\n" for n in range(8))
+ "#EXT-X-ENDLIST\n"
)
monkeypatch.setattr(config, "sample", (32, 38))
subtitle = Subtitle(
id_="s", url=f"{served}/s.m3u8", codec=Subtitle.Codec.WebVTT, language="en", descriptor=Subtitle.Descriptor.HLS
)
subtitle.download(session=Session(), prepare_drm=lambda *a, **k: None, progress=lambda **k: None)
text = subtitle.path.read_text()
assert [n for n in range(8) if f"cue {n}" in text] == [2, 3, 4]
assert "00:00:31.000 --> 00:00:32.000" in text, "cue times stay absolute"
def test_subtitle_trim_keeps_the_cues_of_the_window_from_zero(tmp_path: Path) -> None:
subtitle = Subtitle(id_="s", url="https://x/s", codec=Subtitle.Codec.SubRip, language="en")
subtitle.path = tmp_path / "s.srt"
@@ -221,15 +184,6 @@ def test_subtitle_trim_keeps_the_cues_of_the_window_from_zero(tmp_path: Path) ->
assert subtitle.sample_start == 120
def test_subtitle_trim_leaves_an_unreadable_file_whole(tmp_path: Path) -> None:
subtitle = Subtitle(id_="s", url="https://x/s", codec=Subtitle.Codec.fTTML, language="en")
subtitle.path = tmp_path / "s.stpp"
subtitle.path.write_bytes(b"\x00\x01not a subtitle")
assert subtitle.trim(120, 180) is False
assert subtitle.path.read_bytes() == b"\x00\x01not a subtitle"
def mux_command(tmp_path: Path, mux_args: Callable[..., list[str]]) -> list[str]:
video, audio = make_video(), make_audio()
trimmed = Subtitle(id_="s1", url="https://x/s1", codec=Subtitle.Codec.SubRip, language="en")
@@ -299,15 +253,6 @@ def test_the_api_refuses_sample_with_include_sample() -> None:
assert "--include-sample" in (refusal({"sample": True, "include_sample": True}) or "")
def test_sample_name_uses_the_separator_of_the_template(monkeypatch: pytest.MonkeyPatch) -> None:
separators = {"movies": ".", "series": " "}
monkeypatch.setattr(config, "get_template_separator", lambda kind="movies": separators[kind])
movie = Movie.__new__(Movie)
episode = Episode.__new__(Episode)
assert sample_name("Some.Movie.2026.1080p-TAG", movie) == "Some.Movie.2026.1080p-TAG.SAMPLE"
assert sample_name("Some Show S01E01 1080p-TAG", episode) == "Some Show S01E01 1080p-TAG SAMPLE"
SIDX_MPD = """
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" type="static" mediaPresentationDuration="PT400S">
<Period id="0" start="PT0S">
@@ -345,30 +290,6 @@ def test_parse_sidx_refuses_what_it_cannot_cut() -> None:
assert parse_sidx(sidx_box(count=3)[:-4], 0) == (0, [])
def test_parse_sidx_is_right_when_tracks_parse_at_the_same_time() -> None:
boxes = {758: sidx_box(count=758), 1408: sidx_box(count=1408, size=500)}
wrong: list[int] = []
def parse(count: int) -> None:
for _ in range(100):
if len(parse_sidx(boxes[count], 0)[1]) != count:
wrong.append(count)
threads = [threading.Thread(target=parse, args=(count,)) for count in (758, 1408, 758, 1408)]
for thread in threads:
thread.start()
for thread in threads:
thread.join(timeout=30)
assert not wrong
assert not any(thread.is_alive() for thread in threads)
def test_parse_sidx_refuses_a_box_that_counts_more_references_than_it_holds() -> None:
box = bytearray(sidx_box(count=3))
box[30:32] = (5).to_bytes(2, "big")
assert parse_sidx(bytes(box) + bytes(100), 0) == (0, [])
def test_a_single_file_dash_track_is_cut_by_its_segment_index(monkeypatch: pytest.MonkeyPatch) -> None:
box = sidx_box()
requested: list[str] = []
@@ -407,35 +328,6 @@ def test_a_single_file_dash_track_is_cut_by_its_segment_index(monkeypatch: pytes
assert len(whole) == 1 and not any("800-" in r for r in requested), "a full download does not read the index"
@pytest.mark.parametrize(
("args", "window"),
[
(["--sample", "TAG", "-t", "x", "id"], (120, 180)),
(["--sample", "60-120", "TAG", "id"], (60, 120)),
(["TAG", "id"], None),
],
)
def test_a_bare_sample_option_does_not_take_the_service_tag(args: list[str], window: object) -> None:
seen: dict[str, object] = {}
class Group(Services):
def list_commands(self, ctx: click.Context) -> list[str]:
return ["TAG"]
def get_command(self, ctx: click.Context, name: str) -> click.Command:
return click.Command(
name, params=[click.Option(["-t"]), click.Argument(["title"])], callback=lambda **k: None
)
@click.group(cls=Group)
@click.option("--sample", type=SAMPLE_RANGE, default=None)
def group(sample: object) -> None:
seen["sample"] = sample
group(args, standalone_mode=False)
assert seen["sample"] == window
class RangeSession:
"""Serves byte ranges of one in-memory file and records each range it was asked for."""