mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-25 10:25:09 +00:00
refactor(dl): move track selection into core/tracks/selection.py
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
"""The kind-only flags: --audio-description-only and --forced-subs-only.
|
||||
|
||||
The filters in dl.result are not extractable without executing the whole download loop, so
|
||||
their wiring is pinned against the source, the same way test_required_langs_gate does it.
|
||||
Their filters are tested through TrackSelection in test_track_selection.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.lang_selection import test_kind_only_selection as harness
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core.api.handlers import validate_download_parameters
|
||||
from unshackle.core.utilities import kind_only_conflict
|
||||
@@ -68,23 +69,13 @@ def test_api_rejects_a_non_boolean_flag(key):
|
||||
assert validate_download_parameters({**BASE, key: None}) is None
|
||||
|
||||
|
||||
class TestFilterWiring:
|
||||
source = inspect.getsource(dl.result)
|
||||
|
||||
def test_ado_runs_when_the_title_has_no_separate_audio(self):
|
||||
# embedded audio is standard audio: the filter must sit before the `len(...) > 0` guard
|
||||
ado = self.source.index("if keep_audio and audio_description_only:")
|
||||
guard = self.source.index("if keep_audio and len(title.tracks.audio) > 0:")
|
||||
assert ado < guard
|
||||
|
||||
def test_ado_does_not_count_embedded_audio(self):
|
||||
# both the --require-audio gate and the missing-language check
|
||||
assert self.source.count("keep_videos and not audio_description_only") == 2
|
||||
|
||||
def test_only_filters_keep_one_kind(self):
|
||||
assert "title.tracks.select_audio(lambda x: x.descriptive)" in self.source
|
||||
assert "title.tracks.select_subtitles(lambda x: x.forced)" in self.source
|
||||
|
||||
def test_fso_implies_forced_subs(self):
|
||||
# services read forced_subs from the ctx params to fetch forced tracks at all
|
||||
assert "if forced_s_lang or fsl_excl or forced_subs_only:" in self.source
|
||||
@pytest.mark.parametrize("flags", [{"forced_subs_only": True}, {"forced_s_lang": ["en"]}, {"forced_s_lang": ["-en"]}])
|
||||
def test_a_forced_flag_turns_forced_subs_on_for_the_service(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, flags: dict[str, Any]
|
||||
) -> None:
|
||||
# services read forced_subs from the ctx params to fetch forced tracks at all
|
||||
service = harness.FakeService({1: {"forced": True}})
|
||||
params = {"forced_subs": False}
|
||||
service.ctx = SimpleNamespace(parent=SimpleNamespace(params=params)) # type: ignore[attr-defined]
|
||||
harness.run(monkeypatch, caplog, {}, service=service, **flags)
|
||||
assert params["forced_subs"] is True
|
||||
|
||||
Reference in New Issue
Block a user