76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""Tests for the YAML config loader.
|
|
|
|
Focuses on the ``languages`` and ``prefer_manual`` fields, including the
|
|
legacy/compat behaviour. Network-free, DB-free.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
from yt_scraper.config import load_config, parse_languages
|
|
|
|
|
|
def _write_config(tmp_path, body: str) -> str:
|
|
p = tmp_path / "config.yaml"
|
|
p.write_text(textwrap.dedent(body), encoding="utf-8")
|
|
return str(p)
|
|
|
|
|
|
def test_load_legacy_languages_list(tmp_path) -> None:
|
|
p = _write_config(tmp_path, """
|
|
channel_url: "https://example.com/@x/videos"
|
|
languages: ["es", "en"]
|
|
prefer_manual: true
|
|
""")
|
|
cfg = load_config(p)
|
|
assert cfg.languages == {"es": "manual", "en": "manual"}
|
|
|
|
|
|
def test_load_legacy_languages_list_with_prefer_manual_false(tmp_path) -> None:
|
|
p = _write_config(tmp_path, """
|
|
languages: ["es", "en"]
|
|
prefer_manual: false
|
|
""")
|
|
cfg = load_config(p)
|
|
assert cfg.languages == {"es": "auto", "en": "auto"}
|
|
|
|
|
|
def test_load_new_dict_languages(tmp_path) -> None:
|
|
p = _write_config(tmp_path, """
|
|
languages:
|
|
en: manual
|
|
es: auto
|
|
pt: any
|
|
prefer_manual: false
|
|
""")
|
|
cfg = load_config(p)
|
|
assert cfg.languages == {"en": "manual", "es": "auto", "pt": "any"}
|
|
# prefer_manual remains accessible for fallback on `"any"` entries
|
|
assert cfg.prefer_manual is False
|
|
|
|
|
|
def test_load_unknown_mode_normalises_to_any(tmp_path) -> None:
|
|
p = _write_config(tmp_path, """
|
|
languages:
|
|
en: garbage
|
|
""")
|
|
cfg = load_config(p)
|
|
assert cfg.languages == {"en": "any"}
|
|
|
|
|
|
def test_load_missing_languages_defaults_to_any_not_manual_only(tmp_path) -> None:
|
|
"""The default must fall back to auto captions.
|
|
|
|
A manual-only default silently produces zero transcripts on the many
|
|
channels that publish only auto-generated captions, and records them as
|
|
`no_subtitles` — a terminal status that hides a purely configural failure.
|
|
"""
|
|
p = _write_config(tmp_path, """
|
|
channel_url: "https://example.com/@x/videos"
|
|
""")
|
|
cfg = load_config(p)
|
|
assert "es" in cfg.languages and "en" in cfg.languages
|
|
assert cfg.languages["es"] == "any"
|