From dc6c5868f4e743ad8f24f7dfcf52a85763ec2fc2 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 2 Nov 2026 01:05:32 -0600 Subject: [PATCH] Clean Up Upstream Integration Tests --- .../locationd/test/test_calibrationd.py | 2 +- .../ui/tests/test_camera_client_cache.py | 48 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/openpilot/selfdrive/locationd/test/test_calibrationd.py b/openpilot/selfdrive/locationd/test/test_calibrationd.py index 18e5aa3b38..603cde7a6e 100644 --- a/openpilot/selfdrive/locationd/test/test_calibrationd.py +++ b/openpilot/selfdrive/locationd/test/test_calibrationd.py @@ -162,7 +162,7 @@ class TestCalibrationIdentity(OpenpilotTestCase): put_cache(params, 'CarParamsPrevRoute', old, block=True) captured = [] - def capture(**kwargs): + def capture(captured=captured, **kwargs): captured.append(real_calibrator(**kwargs)) raise StartupCaptured diff --git a/openpilot/starpilot/ui/tests/test_camera_client_cache.py b/openpilot/starpilot/ui/tests/test_camera_client_cache.py index e15f110b8e..1f53c8f1e2 100644 --- a/openpilot/starpilot/ui/tests/test_camera_client_cache.py +++ b/openpilot/starpilot/ui/tests/test_camera_client_cache.py @@ -1,35 +1,43 @@ -from unittest.mock import Mock,patch +from unittest.mock import Mock, patch from openpilot.selfdrive.ui.onroad import cameraview as camera + class ViewWithoutResources(camera.CameraView): - def close(self):pass + def close(self): + pass def test_constructor_caches_once_across_repeated_switches(): - with patch.object(camera,'COMMA_HARDWARE',False), \ - patch.object(camera,'VisionIpcClient',side_effect=lambda *a,**k:Mock()) as factory, \ - patch.object(camera.rl,'load_shader_from_memory',return_value=Mock(id=0)), \ - patch.object(camera.rl,'get_shader_location',return_value=1), \ - patch.object(camera.ui_state,'add_offroad_transition_callback'): - view=ViewWithoutResources('camera-cache-test',camera.VisionStreamType.VISION_STREAM_NARROW_ROAD) - expected=len(list(camera.VisionStreamType)) - assert factory.call_count==expected - identities=dict(view._clients) - with patch.object(view,'_initialize_textures'): + with patch.object(camera, 'COMMA_HARDWARE', False), \ + patch.object(camera, 'VisionIpcClient', side_effect=lambda *a, **k: Mock()) as factory, \ + patch.object(camera.rl, 'load_shader_from_memory', return_value=Mock(id=0)), \ + patch.object(camera.rl, 'get_shader_location', return_value=1), \ + patch.object(camera.ui_state, 'add_offroad_transition_callback'): + view = ViewWithoutResources('camera-cache-test', camera.VisionStreamType.VISION_STREAM_NARROW_ROAD) + expected = len(list(camera.VisionStreamType)) + assert factory.call_count == expected + identities = dict(view._clients) + with patch.object(view, '_initialize_textures'): for _ in range(50): for stream in camera.VisionStreamType: view.switch_stream(stream) - if view._switching:view._complete_switch() + if view._switching: + view._complete_switch() assert view.client is identities[stream] - assert factory.call_count==expected + assert factory.call_count == expected def test_new_drive_drains_cached_clients_and_cancels_pending_switch(): - view=ViewWithoutResources.__new__(ViewWithoutResources) - view._clients={stream:Mock() for stream in camera.VisionStreamType} - view.client=view._clients[camera.VisionStreamType.VISION_STREAM_NARROW_ROAD] - view.frame=Mock();view._target_client=Mock();view._target_stream_type=Mock();view._switching=True - with patch.object(camera.ui_state,'is_onroad',return_value=True):view._offroad_transition() + view = ViewWithoutResources.__new__(ViewWithoutResources) + view._clients = {stream: Mock() for stream in camera.VisionStreamType} + view.client = view._clients[camera.VisionStreamType.VISION_STREAM_NARROW_ROAD] + view.frame = Mock() + view._target_client = Mock() + view._target_stream_type = Mock() + view._switching = True + with patch.object(camera.ui_state, 'is_onroad', return_value=True): + view._offroad_transition() assert view.frame is None and view._target_client is None assert view._target_stream_type is None and not view._switching - for client in view._clients.values():client.recv.assert_called_once_with(timeout_ms=0) + for client in view._clients.values(): + client.recv.assert_called_once_with(timeout_ms=0)