mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -45,9 +45,3 @@ def test_original_flag_moves_to_the_enrich_language():
|
||||
t = title("es", audio=[track("es-419", original=True), track("it-IT")])
|
||||
apply_original_language(t, Language.get("it"))
|
||||
assert [a.is_original_lang for a in t.tracks.audio] == [False, True]
|
||||
|
||||
|
||||
def test_same_language_leaves_flags_alone():
|
||||
t = title("it", videos=[track(None, original=True)])
|
||||
apply_original_language(t, Language.get("it"))
|
||||
assert t.tracks.videos[0].is_original_lang is True
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.utilities import as_requested
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tokens,orig_token,expected",
|
||||
[
|
||||
# the user passed no -l, so orig resolved to en behind their back; report orig
|
||||
(["en"], "en", "orig"),
|
||||
(["en", "ja"], "en", "orig, ja"),
|
||||
# the user named en, so report en
|
||||
(["en"], None, "en"),
|
||||
(["ja"], "en", "ja"),
|
||||
(["en", "ja"], None, "en, ja"),
|
||||
([], "en", ""),
|
||||
],
|
||||
)
|
||||
def test_as_requested(tokens: list[str], orig_token: str | None, expected: str) -> None:
|
||||
assert as_requested(tokens, orig_token) == expected
|
||||
@@ -9,18 +9,6 @@ def video(**data):
|
||||
return SimpleNamespace(data=data)
|
||||
|
||||
|
||||
def test_no_videos():
|
||||
assert embedded_audio_langs([], True) == []
|
||||
|
||||
|
||||
def test_video_without_a_declaration():
|
||||
assert embedded_audio_langs([video(), video(audio_language="")], True) == []
|
||||
|
||||
|
||||
def test_declared_language_is_returned():
|
||||
assert embedded_audio_langs([video(audio_language="zh-CN")], True) == ["zh-CN"]
|
||||
|
||||
|
||||
def test_every_declaring_video_counts():
|
||||
videos = [video(audio_language="zh-CN"), video(), video(audio_language="th")]
|
||||
assert embedded_audio_langs(videos, True) == ["zh-CN", "th"]
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.utilities import find_missing_langs
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"requested,available,expected",
|
||||
[
|
||||
(["en"], ["en"], []),
|
||||
(["en", "ja"], ["en", "ja", "fr"], []),
|
||||
(["en", "fil"], ["en"], ["fil"]),
|
||||
(["en", "ko", "ja"], ["en"], ["ko", "ja"]),
|
||||
(["fil"], ["en", "ja"], ["fil"]),
|
||||
(["fil", "ko"], ["en"], ["fil", "ko"]),
|
||||
(["es"], ["es-419"], []),
|
||||
(["es-419"], ["es"], ["es-419"]),
|
||||
(["es-419"], ["es-MX", "es-ES"], ["es-419"]),
|
||||
(["en-US"], ["en-GB"], ["en-US"]),
|
||||
(["en"], ["en-US"], []),
|
||||
(["all"], [], []),
|
||||
(["best"], [], []),
|
||||
(["orig"], [], []),
|
||||
(["all", "en"], ["en"], []),
|
||||
(["best", "fil"], ["en"], ["fil"]),
|
||||
([], ["en"], []),
|
||||
(["en"], [], ["en"]),
|
||||
(["en"], [None, "en"], []),
|
||||
(["en"], [None], ["en"]),
|
||||
(["zh"], ["zh-Hans"], []),
|
||||
(["zh-CN"], ["zh-Hans"], []),
|
||||
(["zh-Hans"], ["zh-CN"], []),
|
||||
(["zh-TW"], ["zh-Hant"], []),
|
||||
(["zh-Hant"], ["zh-TW"], []),
|
||||
(["zh"], ["zh-Hant"], ["zh"]),
|
||||
(["zh-Hans"], ["zh-Hant"], ["zh-Hans"]),
|
||||
(["zh-CN"], ["zh-TW"], ["zh-CN"]),
|
||||
(["zh-HK"], ["zh-Hant"], ["zh-HK"]),
|
||||
(["zh"], ["cmn"], []),
|
||||
(["cmn"], ["zh"], []),
|
||||
(["zh"], ["yue"], ["zh"]),
|
||||
(["yue"], ["zh-HK"], ["yue"]),
|
||||
(["fil"], ["tl"], []),
|
||||
(["tl"], ["fil"], []),
|
||||
(["fil"], ["tgl"], []),
|
||||
(["tgl"], ["fil"], []),
|
||||
(["fil"], ["fil-PH"], []),
|
||||
(["tl"], ["fil-PH"], []),
|
||||
],
|
||||
)
|
||||
def test_close_match(requested, available, expected):
|
||||
assert find_missing_langs(requested, available, exact=False) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"requested,available,expected",
|
||||
[
|
||||
(["es"], ["es-419"], ["es"]),
|
||||
(["es-419"], ["es"], ["es-419"]),
|
||||
(["en"], ["en-US"], []),
|
||||
(["en-US"], ["en"], []),
|
||||
(["en"], ["en-GB"], ["en"]),
|
||||
(["en-US"], ["en-GB"], ["en-US"]),
|
||||
(["en-US"], ["en-US"], []),
|
||||
(["en-US", "en-GB"], ["en-US"], ["en-GB"]),
|
||||
(["en"], ["en"], []),
|
||||
(["all", "es-419"], ["es"], ["es-419"]),
|
||||
(["zh"], ["zh-Hans"], []),
|
||||
(["zh-CN"], ["zh-Hans"], []),
|
||||
(["zh-TW"], ["zh-Hant"], []),
|
||||
(["zh"], ["cmn"], []),
|
||||
(["zh-HK"], ["zh-Hant"], ["zh-HK"]),
|
||||
(["zh-Hans"], ["zh-Hant"], ["zh-Hans"]),
|
||||
(["zh-CN"], ["zh-TW"], ["zh-CN"]),
|
||||
(["fil"], ["tl"], []),
|
||||
(["tl"], ["fil"], []),
|
||||
(["fil"], ["tgl"], []),
|
||||
(["fil"], ["fil-PH"], []),
|
||||
(["tl"], ["fil-PH"], []),
|
||||
],
|
||||
)
|
||||
def test_exact_match(requested, available, expected):
|
||||
assert find_missing_langs(requested, available, exact=True) == expected
|
||||
|
||||
|
||||
def test_order_preserved():
|
||||
assert find_missing_langs(["ja", "ko", "fr"], ["en"], exact=False) == ["ja", "ko", "fr"]
|
||||
|
||||
|
||||
def test_duplicates_in_request():
|
||||
assert find_missing_langs(["fil", "fil", "en"], ["en"], exact=False) == ["fil", "fil"]
|
||||
|
||||
|
||||
def test_zh_catalogue_simplified_only_misses_traditional():
|
||||
assert find_missing_langs(["zh-Hant", "zh-TW"], ["en", "zh-Hans"], exact=False) == ["zh-Hant", "zh-TW"]
|
||||
|
||||
|
||||
def test_mixed_zh_fil_request():
|
||||
assert find_missing_langs(["en", "zh-Hans", "fil"], ["en", "tl"], exact=False) == ["zh-Hans"]
|
||||
|
||||
|
||||
def test_zh_cn_request_with_tw_catalogue():
|
||||
assert find_missing_langs(["zh-CN"], ["zh-TW"], exact=False) == ["zh-CN"]
|
||||
assert find_missing_langs(["zh-CN"], ["zh-TW"], exact=True) == ["zh-CN"]
|
||||
@@ -151,15 +151,6 @@ def test_a_single_title_with_no_such_track_exits(
|
||||
assert "Skipping" not in caplog.text
|
||||
|
||||
|
||||
def test_subs_only_with_no_matching_subtitle_exits_a_single_title_and_skips_in_a_season(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
assert run(monkeypatch, caplog, {1: {}}, subs_only=True, s_lang=["fr"]) == 1
|
||||
assert run(monkeypatch, caplog, {1: {}, 2: {}}, subs_only=True, s_lang=["fr"]) == 1
|
||||
assert caplog.text.count("Skipping Show S01E") == 2
|
||||
assert "Skipping Show S01E02: There's no track left for the selected options." in caplog.text
|
||||
|
||||
|
||||
def test_a_multi_title_run_skips_the_title_and_continues(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@@ -168,13 +159,6 @@ def test_a_multi_title_run_skips_the_title_and_continues(
|
||||
assert "Skipping Show S01E01" in caplog.text
|
||||
|
||||
|
||||
def test_a_multi_title_run_with_every_title_skipped_fails(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
assert run(monkeypatch, caplog, {1: {}, 2: {}}, forced_subs_only=True) == 1
|
||||
assert caplog.text.count("Skipping Show S01E") == 2
|
||||
|
||||
|
||||
def test_a_required_language_miss_stops_the_run_by_default(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@@ -206,14 +190,6 @@ def test_skip_missing_skips_the_title_and_reports_it(
|
||||
assert state.title == "Show"
|
||||
|
||||
|
||||
def test_skip_missing_skips_a_filter_miss_and_continues(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
ids = run(monkeypatch, caplog, {1: {}, 2: {"ko": True}}, a_lang=["ko"], skip_missing=True)
|
||||
assert ids == {"video": ["v"], "audio": ["ko"], "subs": ["s"]}
|
||||
assert "Skipping Show S01E01" in caplog.text
|
||||
|
||||
|
||||
def test_skip_missing_still_fails_a_run_that_skips_every_title(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@@ -222,72 +198,12 @@ def test_skip_missing_still_fails_a_run_that_skips_every_title(
|
||||
assert run(monkeypatch, caplog, {1: {}}, require_audio=["ko"], skip_missing=True) == 1
|
||||
|
||||
|
||||
class LangService(FakeService):
|
||||
"""Each episode names its original language and its audio languages; the video is in the original language."""
|
||||
|
||||
def get_titles_cached(self) -> Series:
|
||||
return Series(
|
||||
Episode(id_=f"show-s01-e{n:03}", service=FakeService, title="Show", season=1, number=n, language=ep["orig"])
|
||||
for n, ep in self.episodes.items()
|
||||
)
|
||||
|
||||
def get_tracks(self, title: Episode) -> Tracks:
|
||||
ep = self.episodes[title.number]
|
||||
tracks = Tracks()
|
||||
tracks.add(Video(id_="v", url="https://x/v", language=ep["orig"] or "en", codec=Video.Codec.AVC))
|
||||
for lang in ep["audio"]:
|
||||
tracks.add(Audio(id_=lang, url=f"https://x/{lang}", language=lang, codec=Audio.Codec.AAC, bitrate=128_000))
|
||||
return tracks
|
||||
|
||||
|
||||
JA_EN = {"orig": "ja", "audio": ["ja", "en"]}
|
||||
FR = {"orig": "ja", "audio": ["fr"]}
|
||||
EVERY = {"orig": "ja", "audio": ["ja", "ko", "en"]}
|
||||
ORIG_KO_EN = ["orig", "ko", "en"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"first,flags,outcome,logged",
|
||||
[
|
||||
(JA_EN, {}, 1, "Show S01E01: ko not found in audio tracks"),
|
||||
(JA_EN, {"skip_missing": True}, ["ja", "ko", "en"], "Skipping Show S01E01: ko not found in audio tracks"),
|
||||
({"orig": "ja", "audio": ["ko", "en"]}, {"skip_missing": True}, ["ja", "ko", "en"], "S01E01: orig not found"),
|
||||
(JA_EN, {"best_available": True}, ["ja", "en"], "ko not found in audio tracks, continuing with: orig, en"),
|
||||
(FR, {"best_available": True}, 1, "orig, ko, en not found in audio tracks and no fallback available"),
|
||||
(FR, {"best_available": True, "skip_missing": True}, ["ja", "ko", "en"], "Skipping Show S01E01: orig, ko, en"),
|
||||
(JA_EN, {"best_available": True, "require_audio": ["ko"]}, 1, "Required audio language(s) not found: ko"),
|
||||
(
|
||||
JA_EN,
|
||||
{"best_available": True, "require_audio": ["ko"], "skip_missing": True},
|
||||
["ja", "ko", "en"],
|
||||
"Skipping Show S01E01: Required audio language(s) not found: ko",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_several_audio_languages_skip_an_episode_that_misses_one(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
first: dict,
|
||||
flags: dict[str, Any],
|
||||
outcome: Any,
|
||||
logged: str,
|
||||
) -> None:
|
||||
"""-al orig,ko,en on a season where only the second episode has all three."""
|
||||
episodes = {1: first, 2: EVERY}
|
||||
result = run(monkeypatch, caplog, episodes, service=LangService(episodes), a_lang=ORIG_KO_EN, **flags)
|
||||
assert (result if outcome == 1 else result["audio"]) == outcome
|
||||
assert logged in caplog.text
|
||||
|
||||
|
||||
def test_several_audio_languages_fail_a_season_that_misses_one_everywhere(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
episodes = {1: JA_EN, 2: JA_EN}
|
||||
assert run(monkeypatch, caplog, episodes, service=LangService(episodes), a_lang=ORIG_KO_EN, skip_missing=True) == 1
|
||||
assert caplog.text.count("ko not found in audio tracks") == 2
|
||||
assert "Skipped all 2 titles" in caplog.text
|
||||
|
||||
|
||||
def test_a_partly_skipped_run_completes_and_lists_the_skips(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@@ -296,37 +212,6 @@ def test_a_partly_skipped_run_completes_and_lists_the_skips(
|
||||
assert "Skipped 1 of 2 titles: Show S01E01" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize("no_mux,settled", [(False, 2), (True, 1)])
|
||||
def test_a_skipped_title_settles_its_post_script_group(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, no_mux: bool, settled: int
|
||||
) -> None:
|
||||
"""The season event waits on every title of a group; a skipped title counts as settled, once at count time."""
|
||||
import unshackle.commands.dl as dl_module
|
||||
|
||||
seen: list[str] = []
|
||||
group = dl_module.post_script_group
|
||||
monkeypatch.setattr(dl_module, "post_script_group", lambda t: seen.append(str(t)) or group(t))
|
||||
run(monkeypatch, caplog, {1: {}, 2: {"ko": True}}, a_lang=["ko"], skip_missing=True, no_mux=no_mux)
|
||||
assert seen.count("Show S01E01") == settled
|
||||
|
||||
|
||||
class CaptionlessService(FakeService):
|
||||
"""A service that finds out in get_tracks that the title has no subtitles, and turns them off."""
|
||||
|
||||
def get_tracks(self, title: Episode) -> Tracks:
|
||||
tracks = super().get_tracks(title)
|
||||
tracks.subtitles = []
|
||||
self.NO_SUBTITLES = True
|
||||
return tracks
|
||||
|
||||
|
||||
def test_no_subtitles_set_in_get_tracks_turns_the_subtitle_requirement_off(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
ids = run(monkeypatch, caplog, {1: {}}, service=CaptionlessService({1: {}}), require_subs=["en"])
|
||||
assert ids == {"video": ["v"], "audio": ["a"], "subs": []}
|
||||
|
||||
|
||||
class Muxed(BaseException):
|
||||
"""Stops the run at the first mux."""
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import pytest
|
||||
|
||||
from unshackle.core.tracks import Audio
|
||||
from unshackle.core.tracks.tracks import Tracks
|
||||
from unshackle.core.utilities import is_exact_match
|
||||
|
||||
# Base language vs regional variant that CLDR rates at distance 0 (paradigm locales). These are
|
||||
# the pairs that collapse under naive exact matching.
|
||||
@@ -108,29 +107,12 @@ def select(tags, pool, exact=True):
|
||||
return [(t.id, str(t.language)) for t in Tracks.by_language(pool, tags, per_language=1, exact_match=exact)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base,reg", COLLAPSING_PAIRS)
|
||||
def test_collapsing_pairs_are_distance_zero(base, reg):
|
||||
# Root cause: the regional variant exact-matches the base request (CLDR paradigm data).
|
||||
assert is_exact_match(base, [reg]) is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base,reg", DISTINCT_PAIRS)
|
||||
def test_distinct_pairs_are_not_distance_zero(base, reg):
|
||||
# Contrast: these never collapse, which is why the bug was language-specific.
|
||||
assert is_exact_match(base, [reg]) is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base,reg", COLLAPSING_PAIRS)
|
||||
def test_exact_lang_selects_distinct_collapsing_variants(base, reg):
|
||||
# Both tracks present + both tags requested: each tag must route to its own track.
|
||||
assert select([base, reg], mk(base, reg)) == [(base, base), (reg, reg)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base,reg", DISTINCT_PAIRS)
|
||||
def test_exact_lang_distinct_regionals_still_work(base, reg):
|
||||
assert select([base, reg], mk(base, reg)) == [(base, base), (reg, reg)]
|
||||
|
||||
|
||||
def test_exact_lang_lenient_base_to_regional_fallback():
|
||||
# Only the regional present; a base request must still find it when CLDR rates them equal.
|
||||
assert select(["en"], mk("en-US")) == [("en-US", "en-US")]
|
||||
@@ -138,12 +120,6 @@ def test_exact_lang_lenient_base_to_regional_fallback():
|
||||
assert select(["zh"], mk("cmn")) == [("cmn", "cmn")]
|
||||
|
||||
|
||||
def test_exact_lang_stays_strict_for_nonzero_distance():
|
||||
# `es` does NOT accept `es-419` in exact mode (distance 5), but fuzzy mode does.
|
||||
assert select(["es"], mk("es-419")) == []
|
||||
assert select(["es"], mk("es-419"), exact=False) == [("es-419", "es-419")]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base,reg", COLLAPSING_PAIRS)
|
||||
def test_overlapping_tags_never_duplicate_in_fuzzy_mode(base, reg):
|
||||
# Non-exact still collapses base/regional, but must dedupe rather than return a track twice.
|
||||
@@ -163,14 +139,6 @@ def test_exact_lang_three_way_base_and_two_regionals():
|
||||
assert select(["fr", "fr-CA"], mk("fr-FR", "fr-CA")) == [("fr-FR", "fr-FR"), ("fr-CA", "fr-CA")]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tag", REAL_WORLD_AUDIO_LANGS)
|
||||
def test_full_language_set_each_tag_resolves_to_itself(tag):
|
||||
# Against a full real-world language pool, every exact request must return its own track, so
|
||||
# that no tag captures another's: ar-EG must resolve to ar-EG, never to ar.
|
||||
pool = mk(*REAL_WORLD_AUDIO_LANGS)
|
||||
assert select([tag], pool) == [(tag, tag)]
|
||||
|
||||
|
||||
def test_full_language_set_selects_every_track_once():
|
||||
pool = mk(*REAL_WORLD_AUDIO_LANGS)
|
||||
selected = Tracks.by_language(pool, REAL_WORLD_AUDIO_LANGS, per_language=1, exact_match=True)
|
||||
|
||||
@@ -69,20 +69,6 @@ def test_orig_takes_another_region_of_the_title_language(
|
||||
assert ids["video"] == ["v"]
|
||||
|
||||
|
||||
def test_orig_keeps_the_script_the_title_region_implies(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
ids = run(monkeypatch, caplog, RegionalService("zh-TW", ["zh-HK", "zh-CN"], []))
|
||||
assert ids["audio"] == ["zh-HK"]
|
||||
|
||||
|
||||
def test_a_regional_audio_request_misses_rather_than_take_a_sibling(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
assert run(monkeypatch, caplog, RegionalService("fr-FR", ["fr-CA"], []), a_lang=["fr-FR"]) == 1
|
||||
assert "fr-FR not found in audio tracks" in caplog.text
|
||||
|
||||
|
||||
def test_a_regional_sdh_track_is_stripped_when_only_a_sibling_is_plain(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@@ -98,26 +84,6 @@ def test_a_forced_track_does_not_hide_the_plain_track_a_region_means(
|
||||
assert run(monkeypatch, caplog, service, s_lang=["es-ES"])["subs"] == ["es"]
|
||||
|
||||
|
||||
def test_a_bare_sdh_track_is_stripped_when_only_another_variant_is_plain(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
service = RegionalService("en", ["en"], [("en", "sdh"), ("en-GB", "")])
|
||||
assert sorted(run(monkeypatch, caplog, service, s_lang=["en"])["subs"]) == ["en-sdh", "en-sdh_stripped"]
|
||||
|
||||
|
||||
def test_a_bare_audio_request_takes_the_variant_it_means(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
service = RegionalService("en", ["en", "pt-PT", "pt-BR"], [])
|
||||
assert run(monkeypatch, caplog, service, a_lang=["pt"])["audio"] == ["pt-BR"]
|
||||
|
||||
|
||||
def test_orig_takes_the_title_variant_over_the_one_a_bare_tag_means(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
assert run(monkeypatch, caplog, RegionalService("fr-CA", ["fr-FR", "fr-CA", "en"], []))["audio"] == ["fr-CA"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("subs", "flags", "expected"),
|
||||
[
|
||||
@@ -373,10 +339,3 @@ def test_a_standalone_range_beside_hybrid_does_not_add_a_hybrid_base(
|
||||
with pytest.raises(Planned) as planned:
|
||||
run_hdr(monkeypatch, caplog, videos, ["HYBRID", "HDR10"], to_end=True, video_only=True)
|
||||
assert planned.value.base_ids == expected
|
||||
|
||||
|
||||
def test_the_fallback_from_a_failed_hybrid_ranks_regional_tags_as_one_language(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
videos = [("sdr-au", "en-AU", "SDR", 3840, 2160, 3000), ("sdr-gb", "en-GB", "SDR", 3840, 2160, 9000)]
|
||||
assert run_hdr(monkeypatch, caplog, videos, ["HYBRID", "SDR"], best_available=True)["video"] == ["sdr-gb"]
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core.dl_options import DEFAULT_DOWNLOAD_PARAMS, cast_dl_params
|
||||
from unshackle.core.utilities import missing_required_langs
|
||||
|
||||
|
||||
@@ -32,12 +29,6 @@ def test_missing_required_langs(required, available, expected):
|
||||
assert missing_required_langs(required, available) == expected
|
||||
|
||||
|
||||
def test_exclusion_token_is_not_a_required_language():
|
||||
# '-fr' must not be read as a language named "-fr", which could never match
|
||||
assert missing_required_langs(["en", "-fr"], ["en", "ja"]) == []
|
||||
assert missing_required_langs(["en", "-fr"], ["ja"]) == ["en"]
|
||||
|
||||
|
||||
def test_orig_resolves_to_the_title_language():
|
||||
assert missing_required_langs(["orig"], ["ja"], "ja") == []
|
||||
assert missing_required_langs(["orig"], ["en"], "ja") == ["ja"]
|
||||
@@ -59,25 +50,6 @@ def test_all_and_best_tokens_require_nothing():
|
||||
assert missing_required_langs(["best"], []) == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("flag", ["--require-audio", "--require-video", "--best-available", "--warn-only"])
|
||||
def test_flag_is_registered_on_the_dl_command(flag):
|
||||
assert any(flag in param.opts for param in dl.cli.params)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"flag,expected_param",
|
||||
[
|
||||
("--require-audio", "require_audio"),
|
||||
("--require-video", "require_video"),
|
||||
("--warn-only", "best_available"),
|
||||
("--best-available", "best_available"),
|
||||
],
|
||||
)
|
||||
def test_flag_maps_to_its_param_name(flag, expected_param):
|
||||
param = next(p for p in dl.cli.params if flag in p.opts)
|
||||
assert param.name == expected_param
|
||||
|
||||
|
||||
@pytest.mark.parametrize("flag", ["--require-audio", "--require-video"])
|
||||
def test_require_flags_parse_a_comma_list(flag):
|
||||
param = next(p for p in dl.cli.params if flag in p.opts)
|
||||
@@ -85,13 +57,6 @@ def test_require_flags_parse_a_comma_list(flag):
|
||||
assert param.type.convert("en,ja", param, None) == ["en", "ja"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", ["require_audio", "require_video"])
|
||||
def test_api_passes_the_flags_through(key):
|
||||
# the REST API bypasses click, so the default and the dl.result param must both exist
|
||||
assert DEFAULT_DOWNLOAD_PARAMS[key] == []
|
||||
assert key in inspect.signature(dl.result).parameters
|
||||
|
||||
|
||||
def test_api_accepts_the_require_flags():
|
||||
from tests.admission import refusal
|
||||
|
||||
@@ -104,16 +69,6 @@ def test_api_accepts_the_require_flags():
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"key,default",
|
||||
[("require_audio", []), ("require_video", []), ("audio_description_only", False), ("forced_subs_only", False)],
|
||||
)
|
||||
def test_api_reaches_dl_result(key, default):
|
||||
assert DEFAULT_DOWNLOAD_PARAMS[key] == default
|
||||
assert key in inspect.signature(dl.result).parameters
|
||||
assert cast_dl_params(dl.cli, {})[key] == default
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
["en,fr", "en", {"lang": "en"}, [1], ["en", None]],
|
||||
|
||||
@@ -26,12 +26,6 @@ def test_language_objects_satisfy_a_requirement():
|
||||
assert missing_required_langs(["en"], [Language.get("fr")]) == ["en"]
|
||||
|
||||
|
||||
def test_orig_accepts_a_language_object_title_language():
|
||||
# title.language is a langcodes.Language at the call site, never a str
|
||||
assert missing_required_langs(["orig"], ["ja"], Language.get("ja")) == []
|
||||
assert missing_required_langs(["orig"], ["en"], Language.get("ja")) == ["ja"]
|
||||
|
||||
|
||||
def test_requirement_checks_the_catalogue_not_the_selection():
|
||||
# -l best,-fr --require-audio en: the gate answers "does en exist", so the
|
||||
# exclusion of fr from the *selection* must not make en count as missing
|
||||
@@ -55,17 +49,6 @@ def test_the_gate_counts_audio_embedded_in_a_kept_video() -> None:
|
||||
assert selection(require_audio=["ko"], audio_only=True).select(title(), False) == missing
|
||||
|
||||
|
||||
def test_ado_does_not_count_audio_embedded_in_the_video_at_the_gate() -> None:
|
||||
title = episode(video(data={"audio_language": "ko"}), audio("ad", bitrate=1, descriptive=True))
|
||||
sel = selection(require_audio=["ko"], audio_description=True, audio_description_only=True)
|
||||
assert sel.select(title, False) == Skip("Required audio language(s) not found: ko")
|
||||
|
||||
|
||||
def test_a_run_with_every_required_language_present_keeps_the_title() -> None:
|
||||
sel = selection(require_audio=["en"], require_video=["en"], require_subs=["en"])
|
||||
assert isinstance(sel.select(standard(), False), Kept)
|
||||
|
||||
|
||||
def test_the_gate_honours_exact_lang() -> None:
|
||||
def title() -> Any:
|
||||
return episode(video(), audio(language="en-GB"))
|
||||
|
||||
@@ -74,11 +74,6 @@ def test_ado_keeps_the_descriptive_track_and_the_other_types() -> None:
|
||||
assert kept(sel.select(standard(ad=True, forced=True), False)) == {"video": ["v"], "audio": ["ad"], "subs": ["s"]}
|
||||
|
||||
|
||||
def test_fso_keeps_the_forced_track_and_the_other_types() -> None:
|
||||
sel = selection(forced_subs=True, forced_subs_only=True)
|
||||
assert kept(sel.select(standard(ad=True, forced=True), False)) == {"video": ["v"], "audio": ["a"], "subs": ["sf"]}
|
||||
|
||||
|
||||
def test_only_flags_with_their_type_flags_give_a_single_kind() -> None:
|
||||
sel = selection(audio_description=True, audio_description_only=True, audio_only=True)
|
||||
assert kept(sel.select(standard(ad=True, forced=True), False)) == {"video": [], "audio": ["ad"], "subs": []}
|
||||
@@ -101,12 +96,6 @@ def test_a_kind_only_miss_is_a_kind_only_skip(flags: dict[str, Any], reason: str
|
||||
assert selection(**flags).select(standard(), False) == Skip(reason, kind_only=True)
|
||||
|
||||
|
||||
def test_ado_runs_when_the_title_has_no_separate_audio() -> None:
|
||||
title = episode(video(data={"audio_language": "en"}))
|
||||
sel = selection(audio_description=True, audio_description_only=True)
|
||||
assert sel.select(title, False) == Skip("There's no audio description track.", kind_only=True)
|
||||
|
||||
|
||||
def test_ado_does_not_count_audio_embedded_in_the_video() -> None:
|
||||
def title() -> Episode:
|
||||
return episode(video(data={"audio_language": "ko"}), audio("ad", bitrate=1, descriptive=True))
|
||||
|
||||
Reference in New Issue
Block a user