Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ select = [
"PT012",
"PT014",
"PT016",
"PT017",
"PT028",
"PT030",
"PT031",
Expand Down
46 changes: 31 additions & 15 deletions tests/test_video_streaming.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bounded remux consumption and cleanup at the subprocess boundary."""

import re
import subprocess
import sys
import time
Expand Down Expand Up @@ -168,19 +169,34 @@ def test_process_start_failure_removes_temporary_output(


@pytest.mark.parametrize(
"timestamps", [[], [1], [1, 1], [3, 2, 1], [0, 10], [0, 10, 30], [0, 10, 10, 90, 95]]
("timestamps", "expected_fps"),
[
pytest.param([0, 10], 100_000_000.0, id="single-interval"),
pytest.param([0, 10, 30], 1e9 / 15, id="even-interval-count"),
pytest.param([0, 10, 30, 60], 50_000_000.0, id="odd-interval-count"),
pytest.param([0, 10, 10, 90, 95], 1e9 / 7.5, id="duplicate-with-positive-median"),
],
)
def test_streaming_fps_preserves_exact_median_and_errors(timestamps: list[int]) -> None:
try:
expected = video.estimate_fps_from_log_times(timestamps, topic="/camera")
except ValueError as error:
with pytest.raises(
ValueError, match=r"camera topic '/camera'.*frame rate"
) as streaming_error:
video.estimate_fps_from_streaming_log_times(iter(timestamps), topic="/camera")
assert str(streaming_error.value) == str(error)
else:
assert (
video.estimate_fps_from_streaming_log_times(iter(timestamps), topic="/camera")
== expected
)
def test_streaming_fps_preserves_exact_median(timestamps: list[int], expected_fps: float) -> None:
assert video.estimate_fps_from_log_times(timestamps, topic="/camera") == expected_fps
assert (
video.estimate_fps_from_streaming_log_times(iter(timestamps), topic="/camera")
== expected_fps
)


@pytest.mark.parametrize(
("timestamps", "message"),
[
pytest.param([], "has 0 timestamps; at least 2 are needed", id="empty"),
pytest.param([1], "has 1 timestamps; at least 2 are needed", id="single-timestamp"),
pytest.param([1, 1], "has a non-positive median inter-frame interval", id="repeated"),
pytest.param([3, 2, 1], "has a non-positive median inter-frame interval", id="decreasing"),
],
)
def test_streaming_fps_rejects_invalid_timestamps(timestamps: list[int], message: str) -> None:
match = re.escape(f"camera topic '/camera' {message}")
with pytest.raises(ValueError, match=match):
video.estimate_fps_from_log_times(timestamps, topic="/camera")
with pytest.raises(ValueError, match=match):
video.estimate_fps_from_streaming_log_times(iter(timestamps), topic="/camera")