import numpy as np from edge.models import BBox from edge.snapshot import RingBuffer, FaceBlurrer, Snapshotter def _frame(val=128): return np.full((64, 64, 3), val, dtype=np.uint8) def test_ringbuffer_keeps_recent(): rb = RingBuffer(maxlen=3) for i in range(5): rb.push(float(i), _frame(i)) assert len(rb.frames) == 3 assert rb.frames[-1][0] == 4.0 def test_face_blur_changes_region(): fb = FaceBlurrer() f = _frame(0) f[0:10, 0:10] = 255 out = fb.blur(f.copy(), [BBox(0, 0, 10, 10)]) assert out is not None assert out.shape == f.shape def test_snapshotter_returns_jpeg_bytes(): snap = Snapshotter(FaceBlurrer()) imgs = snap.capture([_frame(100), _frame(120)], [[], []]) assert 1 <= len(imgs) <= 3 assert imgs[0][:2] == b"\xff\xd8" # JPEG magic