mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-22 08:55:07 +00:00
refactor(core)!: drop leading underscores from internal definitions
Renames 314 defs and 41 module/class-level constants. Keeps 11 names underscored where the stripped form collides in scope, plus 5.5.0 shims for the three symbols external service repos call.
This commit is contained in:
+27
-27
@@ -6,8 +6,8 @@ import pytest
|
||||
|
||||
from unshackle.core import providers
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.providers.tvdb import TVDBProvider, _ids_from_remote, _pick_match
|
||||
from unshackle.core.utils.tags import _build_tags_from_ids
|
||||
from unshackle.core.providers.tvdb import TVDBProvider, ids_from_remote, pick_match
|
||||
from unshackle.core.utils.tags import build_tags_from_ids
|
||||
|
||||
REMOTE_IDS = [
|
||||
{"id": "tt0149460", "type": 2, "sourceName": "IMDB"},
|
||||
@@ -31,19 +31,19 @@ DVD = [
|
||||
|
||||
|
||||
def test_ids_from_remote() -> None:
|
||||
ext = _ids_from_remote(REMOTE_IDS, 73871)
|
||||
ext = ids_from_remote(REMOTE_IDS, 73871)
|
||||
assert ext.imdb_id == "tt0149460"
|
||||
assert ext.tmdb_id == 615
|
||||
assert ext.tvdb_id == 73871
|
||||
|
||||
|
||||
def _stub(p: TVDBProvider, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def stub(p: TVDBProvider, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(p, "get_episodes", lambda _id, order: {"official": AIRED, "dvd": DVD}.get(order, []))
|
||||
|
||||
|
||||
def test_order_map_joins_on_episode_id(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p = TVDBProvider()
|
||||
_stub(p, monkeypatch)
|
||||
stub(p, monkeypatch)
|
||||
|
||||
mapping = p.get_order_map(73871, "dvd")
|
||||
assert mapping[(1, 9)] == (1, 9, "Hell Is Other Robots")
|
||||
@@ -55,7 +55,7 @@ def test_order_map_joins_on_episode_id(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
def test_order_map_reverses_with_source_order(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p = TVDBProvider()
|
||||
_stub(p, monkeypatch)
|
||||
stub(p, monkeypatch)
|
||||
|
||||
mapping = p.get_order_map(73871, "official", source_order="dvd")
|
||||
assert mapping[(1, 10)] == (2, 1, "A Flight to Remember")
|
||||
@@ -67,13 +67,13 @@ def test_order_map_is_noop_when_orders_match() -> None:
|
||||
|
||||
def test_order_map_empty_when_order_missing(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p = TVDBProvider()
|
||||
_stub(p, monkeypatch)
|
||||
stub(p, monkeypatch)
|
||||
assert p.get_order_map(73871, "alternate") == {}
|
||||
|
||||
|
||||
def test_detect_order_picks_the_order_the_numbering_matches(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p = TVDBProvider()
|
||||
_stub(p, monkeypatch)
|
||||
stub(p, monkeypatch)
|
||||
# a service may number a series in a non-aired order, so detection must not assume aired
|
||||
assert p.detect_order(73871, [(1, 10), (1, 11)]) == "dvd"
|
||||
assert p.detect_order(73871, [(2, 1), (2, 2), (2, 3)]) == "official"
|
||||
@@ -94,27 +94,27 @@ BSG = [
|
||||
|
||||
def test_pick_match_prefers_the_right_era() -> None:
|
||||
# exact title match on the 1978 series must not beat the era the caller asked for
|
||||
best, _, _ = _pick_match(BSG, "Battlestar Galactica", 2004)
|
||||
best, _, _ = pick_match(BSG, "Battlestar Galactica", 2004)
|
||||
assert best["tvdb_id"] == "73545"
|
||||
best, _, _ = _pick_match(BSG, "Battlestar Galactica", 1978)
|
||||
best, _, _ = pick_match(BSG, "Battlestar Galactica", 1978)
|
||||
assert best["tvdb_id"] == "71173"
|
||||
|
||||
|
||||
def test_pick_match_without_a_year_scores_on_title_alone() -> None:
|
||||
best, _, _ = _pick_match(BSG, "Battlestar Galactica", None)
|
||||
best, _, _ = pick_match(BSG, "Battlestar Galactica", None)
|
||||
assert best["tvdb_id"] == "71173"
|
||||
|
||||
|
||||
def test_pick_match_returns_nothing_when_no_year_fits() -> None:
|
||||
assert _pick_match(BSG, "Battlestar Galactica", 1995)[0] is None
|
||||
assert pick_match(BSG, "Battlestar Galactica", 1995)[0] is None
|
||||
|
||||
|
||||
def test_tvdb2_tag_follows_the_matroska_spec() -> None:
|
||||
# TVDB2 IDs are prefixed by entity type: matroska.org/technical/tagging.html
|
||||
from unshackle.core.providers import ExternalIds
|
||||
|
||||
assert _build_tags_from_ids(ExternalIds(tvdb_id=73871), "tv")["TVDB2"] == "series/73871"
|
||||
assert _build_tags_from_ids(ExternalIds(tvdb_id=113), "movie")["TVDB2"] == "movies/113"
|
||||
assert build_tags_from_ids(ExternalIds(tvdb_id=73871), "tv")["TVDB2"] == "series/73871"
|
||||
assert build_tags_from_ids(ExternalIds(tvdb_id=113), "movie")["TVDB2"] == "movies/113"
|
||||
|
||||
|
||||
def test_provider_order_defaults(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
@@ -131,10 +131,10 @@ def test_provider_order_is_configurable(monkeypatch: pytest.MonkeyPatch) -> None
|
||||
def test_enrichment_authority_is_fixed(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
# search order must not demote TMDB below SIMKL for cross-validation tie-breaks
|
||||
monkeypatch.setattr(config, "metadata_providers", [])
|
||||
assert providers._enrichment_providers() == ["tmdb", "simkl", "tvdb"]
|
||||
assert providers.enrichment_providers() == ["tmdb", "simkl", "tvdb"]
|
||||
# `metadata_providers` filters the set but does not re-rank the trust order
|
||||
monkeypatch.setattr(config, "metadata_providers", ["tvdb", "simkl"])
|
||||
assert providers._enrichment_providers() == ["simkl", "tvdb"]
|
||||
assert providers.enrichment_providers() == ["simkl", "tvdb"]
|
||||
|
||||
|
||||
def test_cached_tvdb_result_keeps_enriched_ids() -> None:
|
||||
@@ -144,7 +144,7 @@ def test_cached_tvdb_result_keeps_enriched_ids() -> None:
|
||||
"year": "1999",
|
||||
"_enriched_ids": {"imdb_id": "tt0149460", "tmdb_id": 615},
|
||||
}
|
||||
result = providers._cached_to_result(cached, "tvdb", "tv")
|
||||
result = providers.cached_to_result(cached, "tvdb", "tv")
|
||||
assert result is not None
|
||||
assert result.external_ids.tvdb_id == 73871
|
||||
assert result.external_ids.imdb_id == "tt0149460"
|
||||
@@ -152,7 +152,7 @@ def test_cached_tvdb_result_keeps_enriched_ids() -> None:
|
||||
# remote_ids stay authoritative over the enriched copies
|
||||
cached["remote_ids"] = REMOTE_IDS
|
||||
cached["_enriched_ids"] = {"imdb_id": "tt9999999", "tmdb_id": 1}
|
||||
result = providers._cached_to_result(cached, "tvdb", "tv")
|
||||
result = providers.cached_to_result(cached, "tvdb", "tv")
|
||||
assert result.external_ids.imdb_id == "tt0149460"
|
||||
assert result.external_ids.tmdb_id == 615
|
||||
|
||||
@@ -171,7 +171,7 @@ def test_get_by_id_supplies_what_enrich_needs(monkeypatch: pytest.MonkeyPatch, k
|
||||
"remoteIds": [{"sourceName": "IMDB", "id": "tt0213338"}],
|
||||
}
|
||||
|
||||
monkeypatch.setattr(p, "_get", fake_get)
|
||||
monkeypatch.setattr(p, "api_get", fake_get)
|
||||
result = p.get_by_id(73871, kind)
|
||||
assert seen == [path]
|
||||
assert (result.title, result.year, result.original_language) == ("Cowboy Bebop", 1998, "jpn")
|
||||
@@ -181,7 +181,7 @@ def test_get_by_id_supplies_what_enrich_needs(monkeypatch: pytest.MonkeyPatch, k
|
||||
def test_get_episodes_fails_closed_on_a_truncated_listing(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p = TVDBProvider()
|
||||
pages: dict[int, object] = {0: {"episodes": [{"id": n} for n in range(500)]}, 1: None}
|
||||
monkeypatch.setattr(p, "_get", lambda _path, params: pages[params["page"]])
|
||||
monkeypatch.setattr(p, "api_get", lambda _path, params: pages[params["page"]])
|
||||
# page 1 fails mid-listing: a partial list would renumber wrongly
|
||||
assert p.get_episodes(73871, "official") == []
|
||||
assert p._episodes == {}
|
||||
@@ -189,7 +189,7 @@ def test_get_episodes_fails_closed_on_a_truncated_listing(monkeypatch: pytest.Mo
|
||||
|
||||
def test_get_episodes_does_not_cache_an_empty_listing(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
p = TVDBProvider()
|
||||
monkeypatch.setattr(p, "_get", lambda _path, params: None)
|
||||
monkeypatch.setattr(p, "api_get", lambda _path, params: None)
|
||||
assert p.get_episodes(73871, "official") == []
|
||||
assert p._episodes == {}
|
||||
|
||||
@@ -212,7 +212,7 @@ class _FakeProvider:
|
||||
return self.mapping
|
||||
|
||||
|
||||
def _renumber(monkeypatch: pytest.MonkeyPatch, episodes: list, mapping: dict):
|
||||
def renumber(monkeypatch: pytest.MonkeyPatch, episodes: list, mapping: dict):
|
||||
from types import SimpleNamespace
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
@@ -229,7 +229,7 @@ def _renumber(monkeypatch: pytest.MonkeyPatch, episodes: list, mapping: dict):
|
||||
return dl.apply_tvdb_order(stub, Series(episodes)), errors
|
||||
|
||||
|
||||
def _ep(season: int, number: int, part=None):
|
||||
def ep(season: int, number: int, part=None):
|
||||
from unshackle.core.titles.episode import Episode
|
||||
|
||||
return Episode(id_=f"{season}x{number}.{part}", service=_Svc, title="Show", season=season, number=number, part=part)
|
||||
@@ -237,17 +237,17 @@ def _ep(season: int, number: int, part=None):
|
||||
|
||||
def test_parts_of_one_episode_renumber_together(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Three parts share one (season, number) slot, so they must not read as a collision."""
|
||||
episodes = [_ep(1, 1, 1), _ep(1, 1, 2), _ep(1, 1, 3), _ep(1, 2)]
|
||||
episodes = [ep(1, 1, 1), ep(1, 1, 2), ep(1, 1, 3), ep(1, 2)]
|
||||
mapping = {(1, 1): (2, 1, "Part-ful"), (1, 2): (2, 2, "Whole")}
|
||||
titles, errors = _renumber(monkeypatch, episodes, mapping)
|
||||
titles, errors = renumber(monkeypatch, episodes, mapping)
|
||||
assert errors == []
|
||||
assert [(t.season, t.number, t.part) for t in titles] == [(2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 2, None)]
|
||||
|
||||
|
||||
def test_a_real_collision_still_bails(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Dedupe must not disable the guard: two distinct episodes on one slot still refuses."""
|
||||
episodes = [_ep(1, 1), _ep(1, 2)]
|
||||
episodes = [ep(1, 1), ep(1, 2)]
|
||||
mapping = {(1, 2): (1, 1, "Clash")} # (1, 1) is unmapped and keeps the slot (1, 2) moves onto
|
||||
titles, errors = _renumber(monkeypatch, episodes, mapping)
|
||||
titles, errors = renumber(monkeypatch, episodes, mapping)
|
||||
assert errors # refused, with the "two episodes each" error
|
||||
assert [(t.season, t.number) for t in titles] == [(1, 1), (1, 2)] # numbering untouched
|
||||
|
||||
Reference in New Issue
Block a user