Files
rowing_stats/tests/test_display.py
T
adamfandClaude Opus 5.5 3017cac31b Add tests for parsing, image loading, display detection and CLI
Tesseract is stubbed out except in one end-to-end smoke test on a sample
photo, which is skipped when the binary is not installed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-09 11:46:19 +01:00

44 lines
1.5 KiB
Python

import numpy as np
import pytest
from rowing_stats.display import WARPED_SIZE, crop_display, order_points
from rowing_stats.errors import DisplayNotFoundError
def test_order_points_returns_tl_tr_br_bl():
shuffled = np.array([[90, 80], [10, 15], [12, 85], [95, 12]], dtype="float32")
assert order_points(shuffled).tolist() == [[10, 15], [95, 12], [90, 80], [12, 85]]
def test_crop_display_warps_square_region(monitor_photo):
warped = crop_display(monitor_photo)
assert warped.shape == (WARPED_SIZE, WARPED_SIZE, 3)
# The crop should be the light display, not the dark background
assert warped[50:350, 50:350].mean() > 150
def test_crop_display_blank_image_raises():
blank = np.zeros((600, 800, 3), dtype=np.uint8)
with pytest.raises(DisplayNotFoundError):
crop_display(blank)
def test_crop_display_ignores_non_square_region():
arr = np.full((600, 800, 3), 30, dtype=np.uint8)
arr[250:350, 100:700] = 200 # wide banner, 6:1
with pytest.raises(DisplayNotFoundError):
crop_display(arr)
def test_crop_display_ignores_tiny_square():
arr = np.full((600, 800, 3), 30, dtype=np.uint8)
arr[300:320, 400:420] = 200 # well under 1% of the frame
with pytest.raises(DisplayNotFoundError):
crop_display(arr)
def test_crop_display_writes_debug_images(monitor_photo, tmp_path):
crop_display(monitor_photo, debug_prefix=tmp_path / "shot")
assert (tmp_path / "shot_contours.png").is_file()
assert (tmp_path / "shot_warped.png").is_file()