OverviewFilesCommitsIssuesDocsReleasesPeers

stremio-vsembed / conftest.py

55 lines · python ref:
"""Suite-wide guards.

HdHub is consulted on the /mp4/ play path and in ingest, so without this any
test that exercises those paths without thinking about HdHub reaches the real
service -- on 2026-09-28 test_vidcore_prefetch did exactly that, found a real
Supergirl file and redirected to it. Unit tests must never reach the network.

A test that wants HdHub installs its own `_hdhub_query` (test_hdhub.py's
`hdhub` fixture), which replaces this one.
"""

import pytest

import addon


@pytest.fixture(autouse=True)
def no_production_history(tmp_path, monkeypatch):
    """2026-10-04: the deploy-time suite run appended seven fixture jobs to the
    REAL ingest_history.jsonl -- older test files redirect the queue but
    predate the history file. Every test gets its own; a test that wants to
    read one sets it explicitly (and lands in its own tmp_path anyway)."""
    monkeypatch.setattr(addon, "INGEST_HISTORY_FILE",
                        str(tmp_path / "ingest_history.jsonl"))
    # Subtitle sync: the record and the originals store sit beside addon.py,
    # and stortron's venv HAS ffsubsync -- so by default a test reaching
    # _fetch_subtitles_for would run it for real against production paths.
    monkeypatch.setattr(addon, "SUBTITLE_SYNC_FILE", str(tmp_path / "subtitle_sync.json"))
    monkeypatch.setattr(addon, "SUBS_ORIGINAL_DIR", str(tmp_path / "subs-original"))
    monkeypatch.setattr(addon, "_subsync_available", lambda: False)
    # Per-file source rejections (2026-10-14) sit beside addon.py too.
    monkeypatch.setattr(addon, "SOURCE_REJECTS_FILE", str(tmp_path / "source_rejects.json"))
    # Live-stream subtitle results (2026-10-18) sit beside addon.py too.
    monkeypatch.setattr(addon, "LIVE_SUBS_DIR", str(tmp_path / "live-subs"))
    yield


@pytest.fixture(autouse=True)
def no_hdhub_network(monkeypatch):
    def refuse(*a, **k):
        raise RuntimeError("HdHub reached from a test without a stub")
    monkeypatch.setattr(addon, "_hdhub_query", refuse)
    monkeypatch.setattr(addon, "_hdhub_cache", {})
    monkeypatch.setattr(addon, "_hdhub_pick_cache", {})
    # The OpenSubtitles fallback (2026-10-18) runs whenever a copy ends up with
    # no English sidecar -- which every ingest test with a fake sidecar writer
    # does, and it reached real TMDB + OpenSubtitles on its first run.
    monkeypatch.setattr(addon, "_opensubs_for", refuse)
    # On stortron the real jellyfin.json sits beside addon.py; without this any
    # test reaching an ingest or a delete would report temp paths to the
    # production Jellyfin. test_jellyfin_notify points it at its own file.
    monkeypatch.setattr(addon, "JELLYFIN_CONFIG", "/nonexistent/jellyfin.json")
    monkeypatch.setattr(addon, "_jellyfin_cfg", None)
    yield