from pathlib import Path import sys import numpy as np import pytest import soundfile as sf # Support running the suite before the project is installed. sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) from producer.config import resolve from producer.setup import ensure_ffmpeg @pytest.fixture(autouse=True) def producer_root(tmp_path, monkeypatch): """Isolated shared logs directory for every test: report logs always go under /logs.""" root = tmp_path / "producer-root" monkeypatch.setenv("PRODUCER_ROOT", str(root)) return root @pytest.fixture def logs(producer_root): return producer_root / "logs" @pytest.fixture def report_of(logs): """Locate the one published report for an audio destination; report names are timestamped, so tests glob by stem.""" def find(target): matches = sorted(logs.glob(f"{target.stem}.*.report.json")) assert len(matches) == 1, matches return matches[0] return find @pytest.fixture def progress(): return lambda *_: None @pytest.fixture def wav(tmp_path): def write(samples=None, *, rate=48000, name="input.wav"): if samples is None: time = np.arange(rate * 3) / rate samples = 0.15 * np.sin(2 * np.pi * 440 * time) path = tmp_path / name sf.write(path, np.asarray(samples), rate, format="WAV", subtype="FLOAT") return path return write @pytest.fixture def bypass(): return resolve(profile="cleanup-only", overrides={"denoiser": "none", "highpass": False}) @pytest.fixture def ffmpeg(): try: return ensure_ffmpeg() except RuntimeError as error: pytest.skip(str(error))