refactor: Spur-Fehlermeldung und yt-dlp-Fake gemeinsam nutzen
- yt_untertitel.no_track_message() für yt_untertitel.py und extract_text.py - tests/conftest.py: Fixtures fake_yt_dlp und yt_dlp_installed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ba61434798
commit
0413455ea5
1 changed files with 74 additions and 79 deletions
42
tests/conftest.py
Normal file
42
tests/conftest.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""Shared fixtures: yt-dlp is always replaced by fakes (no network)."""
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_yt_dlp():
|
||||
"""Factory for a subprocess.run stand-in.
|
||||
|
||||
It answers the info request with `info` and writes `vtt` where yt-dlp would
|
||||
write the subtitle file. `run.calls` records every command.
|
||||
"""
|
||||
def make(info, vtt="WEBVTT\n", write=True, fail_download=False):
|
||||
calls = []
|
||||
|
||||
def run(command, capture_output, text):
|
||||
calls.append(command)
|
||||
if "--dump-single-json" in command:
|
||||
return subprocess.CompletedProcess(command, 0, json.dumps(info), "")
|
||||
if fail_download:
|
||||
return subprocess.CompletedProcess(command, 1, "", "HTTP Error 429")
|
||||
track = command[command.index("--sub-langs") + 1]
|
||||
template = command[command.index("-o") + 1]
|
||||
if write:
|
||||
Path(template.replace("%(ext)s", f"{track}.vtt")).write_text(
|
||||
vtt, encoding="utf-8"
|
||||
)
|
||||
return subprocess.CompletedProcess(command, 0, "", "")
|
||||
|
||||
run.calls = calls
|
||||
return run
|
||||
|
||||
return make
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def yt_dlp_installed(monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda name: f"/usr/bin/{name}")
|
||||
Loading…
Reference in a new issue