mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-21 16:35: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:
@@ -10,7 +10,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
|
||||
def _load_scenarios(config: pytest.Config) -> dict:
|
||||
def load_scenarios(config: pytest.Config) -> dict:
|
||||
cached = getattr(config, "_e2e_scenarios_cache", None)
|
||||
if cached is not None:
|
||||
return cached
|
||||
@@ -31,7 +31,7 @@ def _load_scenarios(config: pytest.Config) -> dict:
|
||||
|
||||
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
|
||||
if "service_case" in metafunc.fixturenames:
|
||||
scenarios = _load_scenarios(metafunc.config)
|
||||
scenarios = load_scenarios(metafunc.config)
|
||||
params = [pytest.param((tag, conf), id=tag) for tag, conf in (scenarios.get("services") or {}).items()]
|
||||
if not params:
|
||||
params = [
|
||||
|
||||
@@ -20,7 +20,7 @@ import pytest
|
||||
pytestmark = [pytest.mark.live, pytest.mark.slow]
|
||||
|
||||
|
||||
def _wait_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
def wait_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
r = http_session.get(f"{server_url}/api/session/{sid}/titles", timeout=30)
|
||||
@@ -38,14 +38,14 @@ def _wait_titles(http_session, server_url: str, sid: str, timeout: float = 120.0
|
||||
return None
|
||||
|
||||
|
||||
def _pick_target_title(titles, season: int = 1, episode: int = 1):
|
||||
def pick_target_title(titles, season: int = 1, episode: int = 1):
|
||||
for t in titles:
|
||||
if t.get("type") == "episode" and t.get("season") == season and t.get("number") == episode:
|
||||
return t
|
||||
return titles[0] if titles else None
|
||||
|
||||
|
||||
def _pick_track_at_height(video_tracks, target_height: int):
|
||||
def pick_track_at_height(video_tracks, target_height: int):
|
||||
same_height = [v for v in video_tracks if v.get("height") == target_height and v.get("range") == "SDR"]
|
||||
return sorted(same_height, key=lambda v: v.get("bitrate") or 0)[0] if same_height else None
|
||||
|
||||
@@ -77,10 +77,10 @@ def test_download_manifest_fetch(http_session, server_url: str, service_case) ->
|
||||
sid = r.json()["session_id"]
|
||||
|
||||
try:
|
||||
body = _wait_titles(http_session, server_url, sid)
|
||||
body = wait_titles(http_session, server_url, sid)
|
||||
if not body:
|
||||
pytest.skip(f"{service}: titles timeout")
|
||||
target = _pick_target_title(
|
||||
target = pick_target_title(
|
||||
body.get("titles") or [],
|
||||
season=conf.get("target_season", 1),
|
||||
episode=conf.get("target_episode", 1),
|
||||
@@ -94,7 +94,7 @@ def test_download_manifest_fetch(http_session, server_url: str, service_case) ->
|
||||
timeout=240,
|
||||
)
|
||||
assert tr.status_code == 200, tr.text
|
||||
track = _pick_track_at_height(tr.json().get("video") or [], target_height)
|
||||
track = pick_track_at_height(tr.json().get("video") or [], target_height)
|
||||
if not track:
|
||||
pytest.skip(f"{service}: no track at height={target_height}")
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import pytest
|
||||
pytestmark = [pytest.mark.live, pytest.mark.slow]
|
||||
|
||||
|
||||
def _wait_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
def wait_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
r = http_session.get(f"{server_url}/api/session/{sid}/titles", timeout=30)
|
||||
@@ -38,14 +38,14 @@ def _wait_titles(http_session, server_url: str, sid: str, timeout: float = 120.0
|
||||
return None
|
||||
|
||||
|
||||
def _pick_target_title(titles, season: int = 1, episode: int = 1):
|
||||
def pick_target_title(titles, season: int = 1, episode: int = 1):
|
||||
for t in titles:
|
||||
if t.get("type") == "episode" and t.get("season") == season and t.get("number") == episode:
|
||||
return t
|
||||
return titles[0] if titles else None
|
||||
|
||||
|
||||
def _pick_track_at_height(video_tracks, target_height: int):
|
||||
def pick_track_at_height(video_tracks, target_height: int):
|
||||
"""Prefer SDR + AVC at the requested height; smallest bitrate wins."""
|
||||
same_height = [v for v in video_tracks if v.get("height") == target_height]
|
||||
preferred = [v for v in same_height if v.get("codec") == "AVC" and v.get("range") == "SDR"]
|
||||
@@ -80,10 +80,10 @@ def test_license_server_cdm(http_session, server_url: str, service_case) -> None
|
||||
sid = r.json()["session_id"]
|
||||
|
||||
try:
|
||||
body = _wait_titles(http_session, server_url, sid)
|
||||
body = wait_titles(http_session, server_url, sid)
|
||||
if not body:
|
||||
pytest.skip(f"{service}: titles timeout")
|
||||
target = _pick_target_title(
|
||||
target = pick_target_title(
|
||||
body.get("titles") or [],
|
||||
season=conf.get("target_season", 1),
|
||||
episode=conf.get("target_episode", 1),
|
||||
@@ -97,7 +97,7 @@ def test_license_server_cdm(http_session, server_url: str, service_case) -> None
|
||||
timeout=240,
|
||||
)
|
||||
assert tr.status_code == 200, tr.text
|
||||
track = _pick_track_at_height(tr.json().get("video") or [], target_height)
|
||||
track = pick_track_at_height(tr.json().get("video") or [], target_height)
|
||||
if not track:
|
||||
pytest.skip(f"{service}: no track at height={target_height}")
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import pytest
|
||||
pytestmark = [pytest.mark.live, pytest.mark.slow]
|
||||
|
||||
|
||||
def _create_session(http_session, server_url: str, service: str, title_id: str) -> str:
|
||||
def create_session(http_session, server_url: str, service: str, title_id: str) -> str:
|
||||
payload = {
|
||||
"service": service,
|
||||
"title_id": title_id,
|
||||
@@ -33,7 +33,7 @@ def _create_session(http_session, server_url: str, service: str, title_id: str)
|
||||
return r.json()["session_id"]
|
||||
|
||||
|
||||
def _wait_for_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
def wait_for_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
r = http_session.get(f"{server_url}/api/session/{sid}/titles", timeout=30)
|
||||
@@ -51,7 +51,7 @@ def _wait_for_titles(http_session, server_url: str, sid: str, timeout: float = 1
|
||||
return 408, {"message": "auth timeout"}
|
||||
|
||||
|
||||
def _pick_target_title(titles: list[dict[str, Any]], season: int = 1, episode: int = 1) -> Optional[dict[str, Any]]:
|
||||
def pick_target_title(titles: list[dict[str, Any]], season: int = 1, episode: int = 1) -> Optional[dict[str, Any]]:
|
||||
"""Pick the configured target episode; fall back to the first title."""
|
||||
for t in titles:
|
||||
if t.get("type") == "episode" and t.get("season") == season and t.get("number") == episode:
|
||||
@@ -59,7 +59,7 @@ def _pick_target_title(titles: list[dict[str, Any]], season: int = 1, episode: i
|
||||
return titles[0] if titles else None
|
||||
|
||||
|
||||
def _summarize(video_tracks: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
def summarize(video_tracks: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
max_height = max((v.get("height") or 0 for v in video_tracks), default=0)
|
||||
max_width = max((v.get("width") or 0 for v in video_tracks), default=0)
|
||||
codecs = sorted({v.get("codec") for v in video_tracks if v.get("codec")})
|
||||
@@ -76,25 +76,25 @@ def _summarize(video_tracks: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _resolve_title_id(conf: dict) -> Optional[str]:
|
||||
def resolve_title_id(conf: dict) -> Optional[str]:
|
||||
"""Prefer series_url so S01E01 logic kicks in; fall back to movie title_url."""
|
||||
return conf.get("series_url") or conf.get("title_url")
|
||||
|
||||
|
||||
def test_track_quality_meets_expected(http_session, server_url: str, service_case, capsys) -> None:
|
||||
service, conf = service_case
|
||||
title_input = _resolve_title_id(conf)
|
||||
title_input = resolve_title_id(conf)
|
||||
if not title_input:
|
||||
pytest.skip(f"{service}: no title_url/series_url in fixture")
|
||||
|
||||
sid = _create_session(http_session, server_url, service, title_input)
|
||||
sid = create_session(http_session, server_url, service, title_input)
|
||||
try:
|
||||
code, body = _wait_for_titles(http_session, server_url, sid)
|
||||
code, body = wait_for_titles(http_session, server_url, sid)
|
||||
if code != 200:
|
||||
pytest.skip(f"{service}: titles fetch failed {code}: {str(body)[:200]}")
|
||||
|
||||
titles = body.get("titles") or []
|
||||
target = _pick_target_title(titles, season=conf.get("target_season", 1), episode=conf.get("target_episode", 1))
|
||||
target = pick_target_title(titles, season=conf.get("target_season", 1), episode=conf.get("target_episode", 1))
|
||||
if not target:
|
||||
pytest.skip(f"{service}: no titles returned")
|
||||
|
||||
@@ -114,7 +114,7 @@ def test_track_quality_meets_expected(http_session, server_url: str, service_cas
|
||||
|
||||
tracks = r.json()
|
||||
video = tracks.get("video") or []
|
||||
summary = _summarize(video)
|
||||
summary = summarize(video)
|
||||
# Print summary even when test passes — discovery aid.
|
||||
with capsys.disabled():
|
||||
print(f"\n[{service}] target={kind} '{target.get('name')}' -> {summary}")
|
||||
|
||||
@@ -9,7 +9,7 @@ import pytest
|
||||
pytestmark = [pytest.mark.live, pytest.mark.slow]
|
||||
|
||||
|
||||
def _create_session(http_session, server_url: str, service: str, conf: dict) -> str:
|
||||
def create_session(http_session, server_url: str, service: str, conf: dict) -> str:
|
||||
payload = {"service": service, "title_id": conf["title_url"]}
|
||||
r = http_session.post(f"{server_url}/api/session/create", json=payload, timeout=120)
|
||||
if r.status_code >= 400:
|
||||
@@ -20,7 +20,7 @@ def _create_session(http_session, server_url: str, service: str, conf: dict) ->
|
||||
return sid
|
||||
|
||||
|
||||
def _wait_for_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
def wait_for_titles(http_session, server_url: str, sid: str, timeout: float = 120.0):
|
||||
"""Poll /titles until auth completes. Returns (status_code, response_json).
|
||||
|
||||
Server returns 400 + auth_status=authenticating while auth is in-flight,
|
||||
@@ -44,20 +44,20 @@ def _wait_for_titles(http_session, server_url: str, sid: str, timeout: float = 1
|
||||
return 408, {"message": "timeout waiting for auth"}
|
||||
|
||||
|
||||
def _delete_session(http_session, server_url: str, sid: str) -> None:
|
||||
def delete_session(http_session, server_url: str, sid: str) -> None:
|
||||
http_session.delete(f"{server_url}/api/session/{sid}", timeout=30)
|
||||
|
||||
|
||||
def test_session_create_then_delete(http_session, server_url: str, service_case) -> None:
|
||||
service, conf = service_case
|
||||
sid = _create_session(http_session, server_url, service, conf)
|
||||
sid = create_session(http_session, server_url, service, conf)
|
||||
try:
|
||||
r = http_session.get(f"{server_url}/api/session/{sid}", timeout=30)
|
||||
assert r.status_code == 200
|
||||
info = r.json()
|
||||
assert info.get("session", {}).get("service_tag", service) == service or service in str(info)
|
||||
finally:
|
||||
_delete_session(http_session, server_url, sid)
|
||||
delete_session(http_session, server_url, sid)
|
||||
|
||||
# After delete, info should 404
|
||||
r2 = http_session.get(f"{server_url}/api/session/{sid}", timeout=30)
|
||||
@@ -66,9 +66,9 @@ def test_session_create_then_delete(http_session, server_url: str, service_case)
|
||||
|
||||
def test_session_titles_returns_list(http_session, server_url: str, service_case) -> None:
|
||||
service, conf = service_case
|
||||
sid = _create_session(http_session, server_url, service, conf)
|
||||
sid = create_session(http_session, server_url, service, conf)
|
||||
try:
|
||||
code, body = _wait_for_titles(http_session, server_url, sid)
|
||||
code, body = wait_for_titles(http_session, server_url, sid)
|
||||
if code != 200:
|
||||
pytest.skip(f"{service}: titles fetch failed {code}: {str(body)[:200]}")
|
||||
assert "titles" in body
|
||||
@@ -78,14 +78,14 @@ def test_session_titles_returns_list(http_session, server_url: str, service_case
|
||||
assert "id" in first
|
||||
assert "type" in first
|
||||
finally:
|
||||
_delete_session(http_session, server_url, sid)
|
||||
delete_session(http_session, server_url, sid)
|
||||
|
||||
|
||||
def test_session_tracks_for_first_title(http_session, server_url: str, service_case) -> None:
|
||||
service, conf = service_case
|
||||
sid = _create_session(http_session, server_url, service, conf)
|
||||
sid = create_session(http_session, server_url, service, conf)
|
||||
try:
|
||||
code, body = _wait_for_titles(http_session, server_url, sid)
|
||||
code, body = wait_for_titles(http_session, server_url, sid)
|
||||
if code != 200:
|
||||
pytest.skip(f"{service}: titles fetch failed {code}: {str(body)[:200]}")
|
||||
titles = body.get("titles") or []
|
||||
@@ -104,13 +104,13 @@ def test_session_tracks_for_first_title(http_session, server_url: str, service_c
|
||||
assert "video" in body or "audio" in body, body
|
||||
assert body.get("video") or body.get("audio"), body
|
||||
finally:
|
||||
_delete_session(http_session, server_url, sid)
|
||||
delete_session(http_session, server_url, sid)
|
||||
|
||||
|
||||
def test_session_delete_idempotent_returns_404_after(http_session, server_url: str, service_case) -> None:
|
||||
service, conf = service_case
|
||||
sid = _create_session(http_session, server_url, service, conf)
|
||||
_delete_session(http_session, server_url, sid)
|
||||
sid = create_session(http_session, server_url, service, conf)
|
||||
delete_session(http_session, server_url, sid)
|
||||
|
||||
r = http_session.delete(f"{server_url}/api/session/{sid}", timeout=30)
|
||||
assert r.status_code in (404, 200) # tolerate both depending on server semantics
|
||||
|
||||
Reference in New Issue
Block a user