File size: 1,530 Bytes
7dff04f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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)