Files
unshackle/tests/lang_selection/test_original_audio_ids.py
imSp4rky 8bacb247ee fix(lang): surface orig in errors and flag the original audio track over the API
Error messages named the resolved language for a user who only ever defaulted to orig. Audio tracks now carry is_original, resolved through Tracks.by_language so it agrees with the downloader.
2026-07-26 18:22:46 -06:00

44 lines
1.5 KiB
Python

from __future__ import annotations
from typing import Optional
import pytest
from unshackle.core.api.handlers import original_audio_ids
class FakeTrack:
def __init__(self, language: str) -> None:
self.id = language
self.language = language
class FakeTitle:
def __init__(self, language: Optional[str]) -> None:
self.language = language
@pytest.mark.parametrize(
"title_language,track_languages,expected",
[
# paradigm collapse: CLDR calls these the same language, RFC 4647 picks the specific one
(["en"], ["en", "en-US"], ["en"]),
(["en"], ["en-US", "en-GB"], ["en-US"]),
(["pt"], ["pt-BR", "pt-PT"], ["pt-BR"]),
(["es"], ["es-ES", "es-419"], ["es-ES"]),
# non-paradigm regionals: exact mode drops them, so the fuzzy fallback catches
# them and the flag still matches what a default 'orig' download selects
(["es"], ["es-419"], ["es-419"]),
(["fr"], ["fr-CA"], ["fr-CA"]),
# alias
(["zh"], ["cmn"], ["cmn"]),
# nothing in the original language, and no language on the title at all
(["en"], ["ja", "de"], []),
([None], ["en"], []),
],
)
def test_original_audio_ids(title_language: list, track_languages: list[str], expected: list[str]) -> None:
tracks = [FakeTrack(t) for t in track_languages]
ids = original_audio_ids(tracks, FakeTitle(title_language[0]))
assert [t for t in track_languages if t in ids] == expected