double-exposure / tests /conftest.py
Eddie Faillace
double-exposure app deploy snapshot 2026-07-21 (WP-24 calibration pass)
7dff04f
Raw
History Blame Contribute Delete
1.53 kB
"""Shared pytest fixtures for WP-0 and WP-1 tests."""
from __future__ import annotations
import os
import pytest as _pytest
@_pytest.fixture(autouse=True)
def _hermetic_api_env(monkeypatch):
"""The suite must NEVER see operator API credentials.
app.main calls load_dotenv() at import, so a real .env (present since the
WP-14 key setup) leaks REPLICATE_API_TOKEN / ANTHROPIC_API_KEY into every
test after the first app.main import — demo-mode assertions then take the
live-API branch and pytest attempts PAID network calls (observed live
2026-07-14: 4 failures + real 402s from Replicate). Strip the keys for
every test; API-path tests mock at the client boundary and never need them.
"""
for var in ("REPLICATE_API_TOKEN", "ANTHROPIC_API_KEY", "REPLICATE_INPAINT_MODEL"):
monkeypatch.delenv(var, raising=False)
import numpy as np
import pytest
import torch
from film_physics import get_film_curve, PiecewiseFilmCurve
@pytest.fixture(scope="session")
def generic_curve() -> PiecewiseFilmCurve:
return get_film_curve("Generic")
@pytest.fixture(scope="session")
def small_rgb() -> np.ndarray:
"""64×64 random float32 RGB in (0.1, 0.9) — mid-range to avoid gradient clamps."""
rng = np.random.default_rng(0)
return rng.uniform(0.1, 0.9, (64, 64, 3)).astype(np.float32)
@pytest.fixture(scope="session")
def small_log_exposure() -> torch.Tensor:
"""(1, 1, 64, 64) log-exposure tensor at a mid-curve value."""
return torch.full((1, 1, 64, 64), -0.3)