From 6ae1edf30eb27c0038933c8caac9f31a345470a4 Mon Sep 17 00:00:00 2001 From: Mithesh Date: Wed, 18 Nov 2026 01:00:54 +0530 Subject: [PATCH 1/2] test: enable assertions-in-except lint rule --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index e46793f1..2fcb4887 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -139,6 +139,7 @@ select = [ "PT012", "PT014", "PT016", + "PT017", "PT028", "PT030", "PT031", From 8b03fe513841fdcd9a2f7ce12914e66cbe5c0618 Mon Sep 17 00:00:00 2001 From: Mithesh Date: Wed, 18 Nov 2026 01:01:59 +0530 Subject: [PATCH 2/2] test: state streaming FPS outcomes explicitly --- tests/test_video_streaming.py | 46 +++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/test_video_streaming.py b/tests/test_video_streaming.py index 3e84d487..1c078d4b 100644 --- a/tests/test_video_streaming.py +++ b/tests/test_video_streaming.py @@ -1,5 +1,6 @@ """Bounded remux consumption and cleanup at the subprocess boundary.""" +import re import subprocess import sys import time @@ -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")