import os import sys import numpy as np PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if PROJECT_ROOT not in sys.path: sys.path.insert(0, PROJECT_ROOT) from ui.pipeline import FaceMeshPipeline class _DummyDetector: def __init__(self, landmarks=None): self._landmarks = landmarks def process(self, bgr_frame): return self._landmarks def close(self): return None def test_face_mesh_pipeline_no_face_returns_expected_keys(): pipe = FaceMeshPipeline(detector=_DummyDetector(landmarks=None)) frame = np.zeros((480, 640, 3), dtype=np.uint8) out = pipe.process_frame(frame) assert isinstance(out, dict) for k in ("landmarks", "s_face", "s_eye", "raw_score", "is_focused", "yaw", "pitch", "roll", "mar", "is_yawning"): assert k in out assert out["landmarks"] is None assert 0.0 <= float(out["raw_score"]) <= 1.0 def test_face_mesh_pipeline_with_fake_landmarks_runs(): fake_lm = np.zeros((478, 2), dtype=np.float32) pipe = FaceMeshPipeline(detector=_DummyDetector(landmarks=fake_lm)) frame = np.zeros((480, 640, 3), dtype=np.uint8) out = pipe.process_frame(frame) assert out["landmarks"] is not None assert "is_focused" in out assert "raw_score" in out assert 0.0 <= float(out["raw_score"]) <= 1.0