You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

33 lines
1.3 KiB

from collections import deque
import pytest
from src.models import BoundingBox, TrackEvent, TrackPoint, TrackedPerson, TrackState
def point(frame: int, x: float) -> TrackPoint:
return TrackPoint(float(frame), f"2026-01-01T00:00:0{frame}", frame, x, 10.0, x, 20.0, BoundingBox(0, 0, 10, 20))
def test_tracked_person_and_track_point() -> None:
bbox = BoundingBox(1, 2, 11, 22)
person = TrackedPerson(3, bbox, 0.9, 0, "person", 6.0, 12.0, 6.0, 22.0, True, True, 4, 0)
assert person.track_id == 3
assert person.foot_y == 22.0
assert point(1, 5).frame_number == 1
def test_track_state_trajectory_is_bounded() -> None:
state = TrackState(1, "a", "a", 1, 1, trajectory=deque(maxlen=2))
state.trajectory.extend((point(1, 1), point(2, 2), point(3, 3)))
assert [item.frame_number for item in state.trajectory] == [2, 3]
assert not state.finalized
def test_track_event_and_invalid_values() -> None:
event = TrackEvent("track_created", 1, 1, "now", 0.0, 1.0, 2.0, metadata={"日本語": ""})
assert event.metadata["日本語"] == ""
with pytest.raises(ValueError):
TrackEvent("bad", 1, 1, "now", 0.0, 0.0, 0.0)
with pytest.raises(ValueError):
TrackedPerson(-1, BoundingBox(0, 0, 2, 2), 0.5, 0, "person", 1, 1, 1, 2, False, False, 0, 0)