docforensics / tests /conftest.py
Suryakarthik-1
Deploy DocForensics to Hugging Face Spaces
70520f0
Raw
History Blame Contribute Delete
1.29 kB
import numpy as np
import pytest
from core.types import BBox, TextRegion
from detectors.base import Context
@pytest.fixture
def clean_image():
rng = np.random.default_rng(42)
img = rng.uniform(0.8, 1.0, (128, 128, 3)).astype(np.float32)
return img
@pytest.fixture
def tampered_image():
rng = np.random.default_rng(42)
img = rng.uniform(0.8, 1.0, (128, 128, 3)).astype(np.float32)
img[50:80, 50:80] = 0.1 # dark patch = simulated edit
return img
@pytest.fixture
def sample_regions():
return [
TextRegion(bbox=BBox(10, 10, 60, 20), text='Invoice', confidence=0.95),
TextRegion(bbox=BBox(10, 40, 60, 20), text='Total', confidence=0.92),
TextRegion(bbox=BBox(10, 70, 40, 20), text='1000', confidence=0.90),
]
@pytest.fixture
def base_context(clean_image):
return Context(file_path='test.jpg', text_regions=[], original_img=clean_image)
@pytest.fixture
def regions_context(clean_image, sample_regions):
return Context(file_path='test.jpg', text_regions=sample_regions, original_img=clean_image)
@pytest.fixture
def bgr_uint8():
"""A small 3-channel uint8 image suitable for cv2-based forgery functions."""
rng = np.random.default_rng(7)
return (rng.uniform(0, 255, (96, 96, 3))).astype(np.uint8)