Test canonical CEM gauge rendering after shared UI cleanup

This commit is contained in:
Dom
2026-10-17 22:15:38 -05:00
parent e127fd9803
commit be35d9b557
2 changed files with 19 additions and 8 deletions
@@ -7,6 +7,7 @@ import pyray as rl
from openpilot.starpilot.conditional_mode.policy import ModeChoice
from openpilot.starpilot.ui.conditional_status import ConditionalDisplay
from openpilot.starpilot.ui.onroad import OnroadView, axis_status_color
from openpilot.starpilot.ui.onroad_cem_gauge import AetherGauge, IndicatorType
from openpilot.starpilot.ui.onroad_compact_widgets import MiciSidebarWidgets
from openpilot.starpilot.ui.onroad_conditional import stop_active
from openpilot.starpilot.ui.onroad_state import OnroadState, SpeedLimitObservation
@@ -35,6 +36,7 @@ def test_large_aol_light_uses_same_perception_without_control_authority():
view = OnroadView.__new__(OnroadView)
view.fonts = Mock(profile=Profile.LARGE)
view.fonts.measure.return_value = NS(width=100, height=30)
view.cem_gauge = AetherGauge(view.fonts)
view.navigation_favorites = onroad.NavigationFavorites(view.fonts)
view.camera_layer = view.background_layer = view.extra_overlays = None
view.projection_viewport = None
@@ -51,6 +53,10 @@ def test_large_aol_light_uses_same_perception_without_control_authority():
stack.enter_context(patch.object(onroad.clip, 'end_scissor_mode'))
stack.enter_context(patch.object(onroad, 'render_corner_hint'))
stack.enter_context(patch.object(onroad, 'render_glow'))
light = stack.enter_context(patch.object(onroad, 'draw_stop_light_icon'))
view._large(aol_light())
light = stack.enter_context(patch.object(view.cem_gauge, '_render_unified_road'))
state = aol_light()
view._large(state)
light.assert_called_once()
assert light.call_args.args[3].indicator_type is IndicatorType.STOP_LIGHT
assert not state.longitudinal_active and not stop_active(state)
assert (axis_status_color(state).r, axis_status_color(state).g, axis_status_color(state).b) == (10, 186, 181)
@@ -10,6 +10,7 @@ import pyray as rl
from openpilot.starpilot.ui.developer_preview import OnroadVisualPreview
from openpilot.starpilot.ui.onroad import CornerHintCache, OnroadView
from openpilot.starpilot.ui.onroad_cem_gauge import AetherGauge, IndicatorType
from openpilot.starpilot.ui.onroad_navigation_favorites import NavigationFavorites
from openpilot.starpilot.ui.onroad_compact_widgets import MiciSidebarWidgets
from openpilot.starpilot.ui.onroad_conditional import status as conditional_status
@@ -108,11 +109,12 @@ class DeveloperPreviewRenderTests(unittest.TestCase):
self.assertTrue(any('SYNTHETIC REPLAY PREVIEW' in text for text in drawn))
self.assertFalse(any('CEM PREVIEW' in text or 'CURVE PREVIEW' in text for text in drawn))
def test_large_nonalert_draws_both_preview_labels_without_real_curve(self):
def test_large_nonalert_draws_canonical_gauge_and_preview_labels_without_real_curve(self):
view = OnroadView.__new__(OnroadView)
fonts = Mock()
fonts.profile = Profile.LARGE
view.fonts = fonts
view.cem_gauge = AetherGauge(fonts)
view.navigation_favorites = NavigationFavorites(fonts)
view.camera_layer = None
view.background_layer = None
@@ -135,16 +137,19 @@ class DeveloperPreviewRenderTests(unittest.TestCase):
patch('openpilot.starpilot.ui.onroad.rl.draw_rectangle_rounded'), \
patch('openpilot.starpilot.ui.onroad.rl.draw_rectangle_rounded_lines_ex'), \
patch('openpilot.starpilot.ui.onroad.render_corner_hint'), \
patch('openpilot.starpilot.ui.onroad.draw_curve_road_icon') as curve_icon, \
patch('openpilot.starpilot.ui.onroad.draw_stop_light_icon') as stop_icon, \
patch.object(view.cem_gauge, '_render_unified_road') as road, \
patch.object(view, '_slc_actions'):
view.render(state())
road.assert_called_once()
self.assertEqual(road.call_args.args[3].indicator_type, IndicatorType.ROAD_CURVE)
self.assertEqual(road.call_args.args[3].indicator_value, .0115)
road.reset_mock()
view.render(replace(state(), visual_preview=OnroadVisualPreview('STOP LIGHT', None)))
curve_icon.assert_called_once()
stop_icon.assert_called_once()
road.assert_called_once()
self.assertEqual(road.call_args.args[3].indicator_type, IndicatorType.STOP_LIGHT)
drawn = [call.args[0] for call in fonts.draw.call_args_list]
self.assertIn('CURVE PREVIEW', drawn)
self.assertIn('CEM PREVIEW CURVE', drawn)
self.assertFalse(any(text.startswith(('CEM PREVIEW', 'CCM PREVIEW')) for text in drawn))
self.assertIn('SYNTHETIC REPLAY PREVIEW', drawn)
self.assertIn('CEM + CSC', drawn)