import types from typing import List import numpy as np import pytest class _FakeVideoCapture: def __init__(self, frames_bgr: List[np.ndarray]): self._frames = list(frames_bgr) self._idx = 0 def isOpened(self) -> bool: return True def read(self): if self._idx >= len(self._frames): return False, None f = self._frames[self._idx] self._idx += 1 return True, f def release(self): return None def install_fake_cv2(monkeypatch: pytest.MonkeyPatch, frames_rgb: List[np.ndarray]) -> None: # Minimal cv2 shim for our pipelines frames_bgr = [f[..., ::-1].copy() for f in frames_rgb] cv2 = types.SimpleNamespace() def VideoCapture(path: str): return _FakeVideoCapture(frames_bgr) def cvtColor(img, code): # BGR <-> RGB by channel flip return img[..., ::-1].copy() cv2.VideoCapture = VideoCapture cv2.cvtColor = cvtColor cv2.COLOR_BGR2RGB = 0 cv2.COLOR_RGB2BGR = 1 monkeypatch.setitem(__import__("sys").modules, "cv2", cv2) @pytest.fixture def fake_frames_rgb() -> List[np.ndarray]: # 6 frames of 8x8 RGB (enough for temporal_window=5 tests) rng = np.random.default_rng(0) return [rng.integers(0, 255, size=(8, 8, 3), dtype=np.uint8) for _ in range(6)]