Spaces:
Running
Running
| """tests/conftest.py — shared pytest fixtures""" | |
| from __future__ import annotations | |
| import io | |
| import sys | |
| from pathlib import Path | |
| import numpy as np | |
| import pytest | |
| from PIL import Image | |
| # Ensure repo root is on path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| def fake_image_bytes() -> bytes: | |
| """Returns JPEG bytes of a random 224×224 RGB image.""" | |
| arr = (np.random.rand(224, 224, 3) * 255).astype(np.uint8) | |
| img = Image.fromarray(arr) | |
| buf = io.BytesIO() | |
| img.save(buf, format="JPEG") | |
| return buf.getvalue() | |
| def fake_image_bytes_png() -> bytes: | |
| arr = (np.random.rand(224, 224, 3) * 255).astype(np.uint8) | |
| img = Image.fromarray(arr) | |
| buf = io.BytesIO() | |
| img.save(buf, format="PNG") | |
| return buf.getvalue() | |
| def fake_landmark_sequence() -> "np.ndarray": | |
| """Returns (64, 68, 3) float32 landmark array with random values in [0,1].""" | |
| return np.random.rand(64, 68, 3).astype(np.float32) | |
| def fake_lip_mfcc(): | |
| """Returns (lip_frames, mfcc) as numpy arrays.""" | |
| lip = np.random.rand(25, 64, 96, 3).astype(np.float32) | |
| mfcc = np.random.rand(40, 50).astype(np.float32) | |
| return lip, mfcc | |
| def engine_result_fake(): | |
| from src.types import EngineResult | |
| return EngineResult( | |
| engine="fingerprint", | |
| verdict="FAKE", | |
| confidence=0.92, | |
| explanation="Test explanation.", | |
| processing_time_ms=50.0, | |
| ) | |
| def engine_result_real(): | |
| from src.types import EngineResult | |
| return EngineResult( | |
| engine="fingerprint", | |
| verdict="REAL", | |
| confidence=0.85, | |
| explanation="No synthetic fingerprints found.", | |
| processing_time_ms=50.0, | |
| ) | |