ajakab's picture
feat: Phase 2 — all 7 FMS tests, judge, classifier, report agents
ea64ca0 verified
Raw
History Blame
1.63 kB
"""Tests for Pose2DAgent — model-dependent, skips if YOLO unavailable."""
import pytest
import numpy as np
from formscout.types import IngestResult, Pose2DResult
def _blank_ingest(n_frames=5, w=640, h=480):
frames = [np.zeros((h, w, 3), dtype=np.uint8) for _ in range(n_frames)]
return IngestResult(
frames=frames, fps=30.0, duration=n_frames / 30.0,
n_people=1, width=w, height=h,
)
@pytest.fixture
def pose2d_agent():
"""Create Pose2DAgent, skip if model unavailable."""
try:
from formscout.agents.pose2d import Pose2DAgent
agent = Pose2DAgent()
return agent
except Exception as e:
pytest.skip(f"Pose2D model unavailable: {e}")
class TestPose2DAgent:
def test_returns_typed_result(self, pose2d_agent):
result = pose2d_agent.run(_blank_ingest())
assert isinstance(result, Pose2DResult)
assert isinstance(result.keypoints, list)
assert result.fps == pytest.approx(30.0)
def test_keypoints_per_frame(self, pose2d_agent):
ingest = _blank_ingest(n_frames=3)
result = pose2d_agent.run(ingest)
assert len(result.keypoints) == 3
for frame_kps in result.keypoints:
assert isinstance(frame_kps, dict)
def test_graceful_on_empty_frames(self, pose2d_agent):
empty = IngestResult(
frames=[], fps=30.0, duration=0.0,
n_people=0, width=640, height=480,
)
result = pose2d_agent.run(empty)
assert result.confidence == 0.0
assert "no frames" in result.notes.lower()