Das Programm verarbeitet beliebige gesprochene Beiträge (Reden, Vorträge, Interviews, Videos). Prompts und Texte sprechen von „Beitrag“ statt „Rede“; README-Titel passend zum Projektverzeichnis youtube_abschrift_korrigieren. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""Shared fixtures: yt-dlp and Ollama are always replaced by fakes (no network)."""
|
|
import json
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def ollama_available(request, monkeypatch):
|
|
"""Skip the Ollama server check; tests marked real_ollama_check test it."""
|
|
if "real_ollama_check" in request.keywords:
|
|
return
|
|
import glossar_vorschlag
|
|
import abschrift_korrigieren
|
|
for module in (abschrift_korrigieren, glossar_vorschlag):
|
|
monkeypatch.setattr(module, "check_ollama", lambda model: None)
|
|
|
|
|
|
@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, `run.cwds` the
|
|
working directories.
|
|
"""
|
|
def make(info, vtt="WEBVTT\n", write=True, fail_download=False):
|
|
calls, cwds = [], []
|
|
|
|
def run(command, capture_output, text, cwd=None):
|
|
calls.append(command)
|
|
cwds.append(cwd)
|
|
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
|
|
run.cwds = cwds
|
|
return run
|
|
|
|
return make
|
|
|
|
|
|
@pytest.fixture
|
|
def yt_dlp_installed(monkeypatch):
|
|
monkeypatch.setattr(shutil, "which", lambda name: f"/usr/bin/{name}")
|