CI / gates (push) Successful in 1m17s
Run #1 (6302e0b) failed at the tests gate for two reasons local runs
masked:
- The act image lacks OpenCV's runtime libs, so every
scenedetect-importing media test died on `ImportError: libGL.so.1`.
The workflow now installs libgl1/libglib2.0-0 with ffmpeg, and the
README documents the headless-Linux runtime libs for users.
- Rich rendered `va transcribe --help` at 80 columns and wrapped
`openai-transcriptions` mid-token: GITHUB_ACTIONS makes typer force a
terminal, and TERM=dumb then picks rich's 80-column fallback. Tests
now pin COLUMNS=120 before any Console is constructed and keep typer
in auto-detect mode, so help and doctor output are width-independent
of the runner.
Gates 4/4: 449 passed, 2 skipped; also green under
GITHUB_ACTIONS=true COLUMNS=80.
80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
"""Shared pytest fixtures for the video-analyse test suite."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
# Keep pydantic-ai's one-off banner out of test output.
|
|
os.environ.setdefault("PYDANTIC_AI_NO_BANNER", "1")
|
|
|
|
# Pin rich's render width before any Console is constructed (rich 15 snapshots COLUMNS
|
|
# at construction) and keep typer in auto-detect mode: under GITHUB_ACTIONS (Gitea
|
|
# Actions sets it) typer forces a terminal, and TERM=dumb then renders help at 80
|
|
# columns mid-token. CLI tests assert help text, so width must not depend on the runner.
|
|
os.environ["COLUMNS"] = "120"
|
|
os.environ["_TYPER_FORCE_DISABLE_TERMINAL"] = "1"
|
|
|
|
FFMPEG = shutil.which("ffmpeg")
|
|
|
|
# Exact generator command (synthetic 640x360 @ 12 fps, 10 s, 440 Hz tone).
|
|
FFMPEG_ARGS = [
|
|
"-y",
|
|
"-f",
|
|
"lavfi",
|
|
"-i",
|
|
"testsrc2=duration=10:size=640x360:rate=12",
|
|
"-f",
|
|
"lavfi",
|
|
"-i",
|
|
"sine=frequency=440:duration=10",
|
|
"-c:v",
|
|
"libx264",
|
|
"-preset",
|
|
"veryfast",
|
|
"-c:a",
|
|
"aac",
|
|
"-shortest",
|
|
]
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _hermetic_settings_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
"""Keep every test independent of the developer's real config and API keys.
|
|
|
|
The suite must behave identically with and without a live
|
|
``~/.config/video-analyse/config.toml`` or provider keys in the shell, so point
|
|
``XDG_CONFIG_HOME`` at an empty directory and scrub ``VA_*`` / provider-key
|
|
environment variables; tests that need values set them themselves.
|
|
"""
|
|
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "xdg-config"))
|
|
for name in list(os.environ):
|
|
if name.startswith("VA_"):
|
|
monkeypatch.delenv(name, raising=False)
|
|
for name in (
|
|
"OLLAMA_BASE_URL",
|
|
"OLLAMA_API_KEY",
|
|
"DEEPSEEK_API_KEY",
|
|
"OPENROUTER_API_KEY",
|
|
"GROQ_API_KEY",
|
|
"OPENAI_API_KEY",
|
|
"HF_TOKEN",
|
|
):
|
|
monkeypatch.delenv(name, raising=False)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def sample_video(tmp_path_factory: pytest.TempPathFactory) -> Path:
|
|
"""Generate a 10 s test video (video + audio) once per test session."""
|
|
if FFMPEG is None:
|
|
pytest.skip("ffmpeg not found on PATH; cannot generate sample_video")
|
|
|
|
out = tmp_path_factory.mktemp("media") / "sample.mp4"
|
|
subprocess.run([FFMPEG, *FFMPEG_ARGS, str(out)], check=True, capture_output=True)
|
|
assert out.is_file() and out.stat().st_size > 0, "ffmpeg produced no output"
|
|
return out
|