1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
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 <PRODUCER_ROOT>/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))
|