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
+1 -96
View File
@@ -2,7 +2,6 @@
from __future__ import annotations
import logging
from pathlib import Path
from typing import Any
from uuid import UUID
@@ -17,7 +16,7 @@ from tests.remote.key_source import MemoryKeySource, remote_keys
from unshackle.commands import dl as dl_module
from unshackle.core.config import config
from unshackle.core.credential import Credential
from unshackle.core.drm import ClearKeyCTR, CustomDRM, PlayReady, Widevine
from unshackle.core.drm import ClearKeyCTR, PlayReady, Widevine
from unshackle.core.drm.cenc import drm_stub
from unshackle.core.import_service import ImportService
from unshackle.core.service import Service
@@ -46,11 +45,6 @@ def an_import(tmp_path: Path) -> ImportService:
return ImportService(import_ctx(), "EXAMPLE", "movie-1", str(crit_export(tmp_path / "export.json")))
def test_a_service_licenses_through_its_callbacks_and_has_no_key_source() -> None:
svc = service()
assert (svc.key_arrival, svc.key_source) == (KeyArrival.CALLBACK, None)
@pytest.mark.parametrize(("server_cdm", "arrival"), [(True, KeyArrival.SERVER), (False, KeyArrival.CALLBACK)])
def test_a_remote_session_follows_the_server_cdm_and_is_its_own_key_source(
server_cdm: bool, arrival: KeyArrival
@@ -71,10 +65,6 @@ def test_a_service_is_cached_under_the_title_id_it_keeps(attr: str) -> None:
assert svc.cache_identity() == CacheIdentity("cacher", "show-1", "gb", get_account_hash(None))
def test_a_service_with_no_title_id_has_none_to_cache_under() -> None:
assert service().cache_identity().title_id is None
def test_a_remote_session_and_an_import_have_no_title_cache(tmp_path: Path) -> None:
remote = remote_keys()
remote.title_id = "show-1"
@@ -152,18 +142,6 @@ def test_only_a_service_saves_its_login_cookies(tmp_path: Path) -> None:
assert an_import(tmp_path).login_cookies is None
def test_the_source_defaults_leave_a_track_alone() -> None:
"""A source that defines no hooks, sample decrypter or licence callback gets the no-op base."""
svc = service(log=logging.getLogger("test"))
assert not svc.decrypts_samples(None) # type: ignore[arg-type]
assert svc.get_widevine_license(challenge=b"", title=None, track=None) is None # type: ignore[arg-type]
assert svc.get_playready_license(challenge=b"", title=None, track=None) is None # type: ignore[arg-type]
with pytest.raises(NotImplementedError):
svc.get_sample_decrypter(None, 1) # type: ignore[arg-type]
assert svc.sample_decrypter(None) is None # type: ignore[arg-type]
svc.close()
def test_a_source_that_decrypts_samples_hands_its_decrypter_for_the_track() -> None:
class Decrypting(ExampleService):
def decrypts_samples(self, track: Any) -> bool:
@@ -218,83 +196,10 @@ class KeyedSource(FakeService):
self.closed += 1
@pytest.mark.parametrize(
("arrival", "line"),
[
(KeyArrival.EXPORT, "Using keys from the export; no CDM required"),
(KeyArrival.SERVER, "Using server CDM (Widevine); no local CDM required"),
],
)
def test_dl_licenses_with_no_cdm_of_its_own_when_the_keys_arrive_from_the_source(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, arrival: KeyArrival, line: str
) -> None:
lines: list[str] = []
monkeypatch.setattr(logging.getLogger("test_kind_only"), "info", lambda msg, *a, **k: lines.append(msg))
saved: list[Any] = []
monkeypatch.setattr(dl_module.login, "save_cookies", lambda *a: saved.append(a))
source = KeyedSource(arrival)
assert harness.run(monkeypatch, caplog, {1: {}}, service=source, to_end=True, skip_dl=True) is None
assert line in lines
assert (source.closed, saved) == (1, [])
class CipheredSource(KeyedSource):
"""A server-keyed source whose video and audio tracks carry the DRM of ``drm``."""
def __init__(self, drm: dict[str, Any], server_cdm_type: str) -> None:
super().__init__(KeyArrival.SERVER)
self.drm = drm
self.keys.server_cdm_type = server_cdm_type
def get_tracks(self, title: Any) -> Any:
tracks = super().get_tracks(title)
for track in tracks:
track.drm = self.drm.get(track.id)
return tracks
def ctr() -> ClearKeyCTR:
return ClearKeyCTR(licence=None, iv=bytes(16), magic=b"EX")
@pytest.mark.parametrize(
("drm", "server_cdm_type", "line"),
[
({"v": [ctr()], "a": [ctr()]}, "widevine", "Using keys from the server; no local CDM required"),
(
{"v": ["held-plugin"], "a": [ctr()]},
"playready",
"Using keys from the server; no local CDM required",
),
({"a": [ctr()]}, "widevine", "Using server CDM (Widevine); no local CDM required"),
(
{"v": [drm_stub("widevine", KIDS)], "a": [ctr()]},
"widevine",
"Using server CDM (Widevine); no local CDM required",
),
({"v": [drm_stub("playready", KIDS)]}, "playready", "Using server CDM (PlayReady); no local CDM required"),
({"a": [ctr()]}, "example", "Using server CDM (EXAMPLE); no local CDM required"),
],
ids=["whole-file", "whole-file-playready-server", "video-drm-not-loaded", "mixed", "playready", "plugin"],
)
def test_dl_names_the_server_cdm_only_for_a_title_that_needs_one(
monkeypatch: pytest.MonkeyPatch,
caplog: pytest.LogCaptureFixture,
example_plugins: None,
drm: dict[str, Any],
server_cdm_type: str,
line: str,
) -> None:
held = CustomDRM("other", data={"key": bytes(8).hex()})
drm = {kind: [held if d == "held-plugin" else d for d in drms] for kind, drms in drm.items()}
lines: list[str] = []
monkeypatch.setattr(logging.getLogger("test_kind_only"), "info", lambda msg, *a, **k: lines.append(msg))
monkeypatch.setattr(dl_module.login, "save_cookies", lambda *a: None)
source = CipheredSource(drm, server_cdm_type)
assert harness.run(monkeypatch, caplog, {1: {}}, service=source, to_end=True, skip_dl=True) is None
assert [msg for msg in lines if "no local CDM required" in msg] == [line]
def test_dl_saves_the_login_cookies_of_a_service(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, tmp_path: Path
) -> None: