forked from kenzuya/unshackle
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -6,8 +6,6 @@ import inspect
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -18,7 +16,6 @@ import pytest
|
||||
from pywidevine.pssh import PSSH as WidevinePSSH
|
||||
|
||||
from tests.core.test_zero_kid_fallback import _playready_pssh
|
||||
from unshackle.core import wire
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.drm import ClearKeyCENC, ClearKeyCTR, CustomDRM, PlayReady, Widevine
|
||||
from unshackle.core.import_service import ImportService
|
||||
@@ -31,7 +28,6 @@ from unshackle.core.tracks.track import Track
|
||||
from unshackle.core.wire import (
|
||||
apply_title_fields,
|
||||
apply_tracks_reply,
|
||||
attachment_to_dict,
|
||||
build_attachment,
|
||||
build_chapters,
|
||||
build_title,
|
||||
@@ -700,23 +696,6 @@ def test_rest_episode() -> None:
|
||||
assert serialize_title(full_episode(), None) == REST_EPISODE
|
||||
|
||||
|
||||
def test_rest_episode_without_a_name_gets_a_placeholder_and_no_optional_keys() -> None:
|
||||
assert serialize_title(episode(name=None), None) == {
|
||||
"type": "episode",
|
||||
"name": "Episode 05",
|
||||
"id": "ep-0001",
|
||||
"language": "en",
|
||||
"description": "An example episode.",
|
||||
"date": "2024-03-09",
|
||||
"cover_url": "https://img.example/ep.jpg",
|
||||
"year": 2024,
|
||||
"series_title": "Example Show",
|
||||
"season": 2,
|
||||
"number": 5,
|
||||
"air_date": "2024-03-09",
|
||||
}
|
||||
|
||||
|
||||
def test_rest_movie() -> None:
|
||||
assert serialize_title(movie(), None) == REST_MOVIE
|
||||
|
||||
@@ -725,23 +704,6 @@ def test_rest_song() -> None:
|
||||
assert serialize_title(song(), None) == REST_SONG
|
||||
|
||||
|
||||
def test_rest_title_of_no_known_kind() -> None:
|
||||
assert serialize_title(OtherTitle(), None) == {
|
||||
"type": "other",
|
||||
"name": "Other Thing",
|
||||
"id": "other-0001",
|
||||
"language": None,
|
||||
"description": None,
|
||||
"date": None,
|
||||
"cover_url": None,
|
||||
}
|
||||
|
||||
|
||||
def test_rest_title_key_order_is_stable() -> None:
|
||||
assert list(serialize_title(full_episode(), None)) == list(REST_EPISODE)
|
||||
assert list(serialize_title(song(), None)) == list(REST_SONG)
|
||||
|
||||
|
||||
def test_export_episode_meta() -> None:
|
||||
meta = title_to_meta(full_episode())
|
||||
assert meta == META_EPISODE
|
||||
@@ -758,15 +720,6 @@ def test_export_movie_meta() -> None:
|
||||
}
|
||||
|
||||
|
||||
def test_export_meta_of_another_title_is_a_movie_named_by_str() -> None:
|
||||
assert title_to_meta(OtherTitle()) == {
|
||||
"id": "other-0001",
|
||||
"language": None,
|
||||
"type": "movie",
|
||||
"name": "Other Thing",
|
||||
}
|
||||
|
||||
|
||||
def test_export_song_meta_rebuilds_the_song_the_rest_form_rebuilds() -> None:
|
||||
rebuilt = title_fields(build_title(json_copy(title_to_meta(song())), "EXAMPLE", "fallback-id"))
|
||||
assert rebuilt == title_fields(build_title(json_copy(REST_SONG), "EXAMPLE", "fallback-id"))
|
||||
@@ -789,20 +742,6 @@ def test_build_title_drops_the_placeholder_name() -> None:
|
||||
}
|
||||
|
||||
|
||||
def test_build_title_from_rest_movie() -> None:
|
||||
assert title_fields(build_title(json_copy(REST_MOVIE), "EXAMPLE", "fallback-id")) == {
|
||||
"class": "Movie",
|
||||
"service": "EXAMPLE",
|
||||
"id": "movie-0001",
|
||||
"language": "fr",
|
||||
"year": 2023,
|
||||
"data": {"cover_url": "https://img.example/film.jpg"},
|
||||
"name": "Example Film",
|
||||
"description": "An example film.",
|
||||
"anime": None,
|
||||
}
|
||||
|
||||
|
||||
def test_build_title_from_rest_song() -> None:
|
||||
fields = title_fields(build_title(json_copy(REST_SONG), "EXAMPLE", "fallback-id"))
|
||||
assert fields == {
|
||||
@@ -844,28 +783,6 @@ def test_build_title_from_export_meta() -> None:
|
||||
assert title_fields(title) == {**EPISODE_FIELDS, "data": None, "description": None}
|
||||
|
||||
|
||||
def test_build_title_from_a_bare_episode_uses_the_fallbacks() -> None:
|
||||
assert title_fields(build_title({"type": "episode"}, "EXAMPLE", "fallback-id")) == {
|
||||
"class": "Episode",
|
||||
"service": "EXAMPLE",
|
||||
"id": "fallback-id",
|
||||
"language": None,
|
||||
"year": None,
|
||||
"data": None,
|
||||
"title": "Unknown",
|
||||
"season": 0,
|
||||
"number": 0,
|
||||
"name": None,
|
||||
"part": None,
|
||||
"description": None,
|
||||
"air_date": None,
|
||||
"absolute": None,
|
||||
"sport": False,
|
||||
"anime": None,
|
||||
"daily": None,
|
||||
}
|
||||
|
||||
|
||||
def test_build_title_refuses_an_unknown_kind() -> None:
|
||||
with pytest.raises(click.ClickException, match="unknown title type 'other'"):
|
||||
build_title(json_copy(serialize_title(OtherTitle(), None)), "EXAMPLE", "fallback-id")
|
||||
@@ -1156,12 +1073,6 @@ def test_reconstruct_rest_drm_skips_what_it_cannot_parse(caplog: pytest.LogCaptu
|
||||
assert caplog.messages[0].startswith("Skipping unparseable playready DRM entry from server: InvalidPssh(")
|
||||
|
||||
|
||||
def test_export_drm_decode() -> None:
|
||||
rebuilt = [drm_from_dict(json_copy(d.to_dict())) for d in (widevine(VIDEO_KID), playready(VIDEO_KID, AUDIO_KID))]
|
||||
rebuilt.append(drm_from_dict(json_copy(clearkey().to_dict())))
|
||||
assert [drm_fields(d) for d in rebuilt] == [WIDEVINE_FIELDS, PLAYREADY_FIELDS, CLEARKEY_FIELDS]
|
||||
|
||||
|
||||
def test_export_drm_decode_takes_the_stored_keys() -> None:
|
||||
data = {
|
||||
"system": "Widevine",
|
||||
@@ -1224,11 +1135,6 @@ def test_reconstruct_rest_drm_refuses_a_bad_plugin_kid_with_one_line(example_plu
|
||||
assert e.value.error_code is APIErrorCode.DRM_ERROR # type: ignore[attr-defined]
|
||||
|
||||
|
||||
def test_a_track_with_an_unknown_drm_type_stops_the_title() -> None:
|
||||
with pytest.raises(click.ClickException, match="futuredrm"):
|
||||
build_tracks({"video": [{**REST_VIDEO, "drm": [{"type": "futuredrm", "kids": [str(VIDEO_KID)]}]}]})
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data", [{"system": "FutureDRM", "kids": [VIDEO_KID.hex]}, {"system": "FutureDRM", "pssh_b64": "x"}]
|
||||
)
|
||||
@@ -1289,54 +1195,6 @@ def test_build_attachment_by_url_and_with_nothing() -> None:
|
||||
assert build_attachment({"name": "x"}) is None
|
||||
|
||||
|
||||
def test_rest_titles_round_trip() -> None:
|
||||
for title in (full_episode(), movie()):
|
||||
assert title_fields(
|
||||
build_title(json_copy(serialize_title(title, None)), "EXAMPLE", "fallback-id")
|
||||
) == title_fields(title)
|
||||
rebuilt = title_fields(build_title(json_copy(serialize_title(song(), None)), "EXAMPLE", "fallback-id"))
|
||||
assert {**rebuilt, "data": None} == {**title_fields(song()), "data": None}
|
||||
|
||||
|
||||
def test_export_meta_round_trips_the_fields_it_carries() -> None:
|
||||
episode_meta = title_fields(build_title(json_copy(title_to_meta(full_episode())), "EXAMPLE", "fallback-id"))
|
||||
assert episode_meta == {**title_fields(full_episode()), "data": None, "description": None}
|
||||
movie_meta = title_fields(build_title(json_copy(title_to_meta(movie())), "EXAMPLE", "fallback-id"))
|
||||
assert movie_meta == {**title_fields(movie()), "data": None, "description": None}
|
||||
|
||||
|
||||
def test_rest_tracks_round_trip_with_their_drm() -> None:
|
||||
track = video()
|
||||
track.drm = [widevine(VIDEO_KID), playready(VIDEO_KID, AUDIO_KID)]
|
||||
track.drm_preference = "pr"
|
||||
lists = serialize_tracks(Tracks([track, audio(), subtitle()]), movie(), include_url=True)
|
||||
rebuilt = build_tracks(json_copy(lists))
|
||||
assert [track_fields(t) for t in (*rebuilt.videos, *rebuilt.audio, *rebuilt.subtitles)] == [
|
||||
track_fields(t) for t in (track, audio(), subtitle())
|
||||
]
|
||||
|
||||
|
||||
def test_export_tracks_round_trip_without_closed_captions() -> None:
|
||||
for track in (video(), audio(), subtitle()):
|
||||
expected = track_fields(track)
|
||||
if isinstance(track, Video):
|
||||
expected["closed_captions"] = []
|
||||
assert track_fields(track_from_dict(json_copy(track_to_dict(track)))) == expected
|
||||
|
||||
|
||||
def test_both_track_forms_decode_the_shared_fields_the_same_way() -> None:
|
||||
shared = ("id", "url", "language", "is_original_lang", "descriptor", "needs_repack", "name", "edition", "note")
|
||||
forms: list[tuple[Any, Any, Any]] = [
|
||||
(video(), serialize_video_track, deserialize_video),
|
||||
(audio(), serialize_audio_track, deserialize_audio),
|
||||
(subtitle(), serialize_subtitle_track, deserialize_subtitle),
|
||||
]
|
||||
for track, encode, decode in forms:
|
||||
rest = track_fields(decode(json_copy(encode(track, include_url=True))))
|
||||
export = track_fields(track_from_dict(json_copy(track_to_dict(track))))
|
||||
assert {key: rest[key] for key in shared} == {key: export[key] for key in shared}
|
||||
|
||||
|
||||
URL_SUBTITLE = {
|
||||
"type": "Subtitle",
|
||||
"id": "good",
|
||||
@@ -1390,38 +1248,6 @@ def test_drm_round_trips_in_both_forms() -> None:
|
||||
assert drm_fields(drm_from_dict(json_copy(drm_to_dict(one)))) == drm_fields(one)
|
||||
|
||||
|
||||
def test_attachments_round_trip_in_both_forms(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def fields(attachment: Attachment) -> tuple[Any, ...]:
|
||||
return attachment.url, attachment.name, attachment.mime_type, attachment.description
|
||||
|
||||
by_url = Attachment(
|
||||
url="https://img.example/poster.jpg", name="Poster", mime_type="image/jpeg", description="Cover"
|
||||
)
|
||||
for data in (serialize_attachment(by_url), attachment_to_dict(by_url)):
|
||||
rebuilt = build_attachment(json_copy(data))
|
||||
assert rebuilt is not None
|
||||
assert fields(rebuilt) == fields(by_url)
|
||||
monkeypatch.setattr(config.directories, "temp", tmp_path / "temp")
|
||||
poster = tmp_path / "poster.jpg"
|
||||
poster.write_bytes(b"jpeg-bytes")
|
||||
by_path = Attachment(path=poster, name="Poster", description="Cover")
|
||||
rebuilt = build_attachment(json_copy(serialize_attachment(by_path)))
|
||||
assert rebuilt is not None and rebuilt.path is not None
|
||||
assert (fields(rebuilt), rebuilt.path.read_bytes()) == (fields(by_path), b"jpeg-bytes")
|
||||
|
||||
|
||||
def test_an_attachment_over_the_inline_limit_is_skipped(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(wire, "ATTACHMENT_INLINE_LIMIT", 4)
|
||||
poster = tmp_path / "poster.jpg"
|
||||
poster.write_bytes(b"jpeg-bytes")
|
||||
assert serialize_attachment(Attachment(path=poster, name="Poster")) is None
|
||||
|
||||
|
||||
def test_an_export_track_of_an_unhashable_type_is_refused_as_before() -> None:
|
||||
with pytest.raises(TypeError, match="unhashable type|as a dict key"):
|
||||
track_from_dict({**EXPORT_VIDEO, "type": {"a": 1}})
|
||||
|
||||
|
||||
RENAMED = {"range_": "range", "id_": "id", "title": "series_title"}
|
||||
NOT_SENT = {"session", "downloader", "downloader_args", "from_file", "extra", "service", "data"}
|
||||
NOT_EXPORTED = NOT_SENT | {"closed_captions", "drm", "description"}
|
||||
@@ -1459,17 +1285,6 @@ def test_every_constructor_field_crosses_the_edge(item: Any, rest: Any, export:
|
||||
assert fields - NOT_EXPORTED - set(export(obj)) == set()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
["unshackle.core.wire", "unshackle.core.api", "unshackle.core.tracks", "unshackle.core.drm"],
|
||||
)
|
||||
def test_each_module_imports_first_in_a_new_interpreter(module: str) -> None:
|
||||
"""wire imports tracks, drm and titles, and they import wire inside their to_dict, so no order may cycle."""
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
result = subprocess.run([sys.executable, "-c", f"import {module}"], cwd=root, capture_output=True, check=False)
|
||||
assert result.returncode == 0, result.stderr.decode("utf-8", errors="replace")
|
||||
|
||||
|
||||
class FLAGGED:
|
||||
ANIME = True
|
||||
METADATA_PROVIDER = "tmdb"
|
||||
|
||||
Reference in New Issue
Block a user