Update UI tests for the plain sign and accepted-limit display

This commit is contained in:
firestarsdog
2026-11-15 02:30:59 -05:00
parent c866e100d1
commit 4e8166ac1f
9 changed files with 152 additions and 262 deletions
@@ -125,7 +125,7 @@ def test_only_the_displayed_ranges_configured_offset_expands_the_sign(profile, m
offset_mps=target - posted_mps, presentation_adjusted_limit_mps=target, accepted_speed_limit_mps=15.))
shown = resolve_unified_speed(current)
assert shown.offset_configured == (configured_offset != 0)
assert shown.limit_text == str(round(target * factor))
assert int(shown.posted_text) + int(shown.offset_text or 0) == round(target * factor)
if configured_offset == 0 and posted_mps in (1 / 3.6, 160 / 3.6):
assert shown.offset_text is not None # The effective adjustment is clamping, not a configured offset.
widget = SpeedLimitWidget(fonts(profile), profile)
+32 -115
View File
@@ -86,22 +86,25 @@ def test_large_set_and_limit_share_typography_at_the_saved_position():
document['layouts']['large']['cruise_limits'].update(x=188, y=95)
current = sample_state('engaged', document)
factor = 3.6 if metric else 2.2369362921
observation = replace(current.speed_limit, speed_limit_mps=120 / factor,
presentation_adjusted_limit_mps=130 / factor, effective_cluster_target_mps=130 / factor)
# SLC follows this DASH 120 +10 reading, so it is the sign.
observation = replace(current.speed_limit, speed_limit_mps=120 / factor, accepted_speed_limit_mps=120 / factor,
accepted_adjusted_limit_mps=130 / factor, presentation_adjusted_limit_mps=130 / factor,
effective_cluster_target_mps=130 / factor)
current = replace(current, metric=metric, cruise_kph=value / factor * 3.6 if value else None,
speed_limit=observation)
calls = []
with patch.object(fonts, 'draw', lambda *args, calls=calls: calls.append(args)), patch.object(rl, 'draw_line_ex') as lines:
UnifiedSpeedWidget(fonts).render(rl.Rectangle(30, 30, 1800, 1020), current)
calls = [call for call in calls if call[-1].a == 255]
posted = next(call for call in calls if call[0] == '130' and call[1] == FontRole.SET_SPEED and call[3] > 388)
posted = next(call for call in calls if call[0] == '120' and call[1] == FontRole.SET_SPEED and call[3] > 388)
left, right = fonts.horizontal_ink(posted[0], posted[1], posted[2])
assert right-left <= 108*LARGE_SIGN_SCALE
assert abs(posted[3] + (left + right) / 2 - (418 + SIGN_WIDTH/2*LARGE_SIGN_SCALE)) <= .5
a, b = fonts.vertical_ink('130', FontRole.SET_SPEED, posted[2])
a, b = fonts.vertical_ink('120', FontRole.SET_SPEED, posted[2])
assert 60 <= b - a <= 70
assert abs(posted[4]+(a+b)/2-(95+61*LARGE_SIGN_SCALE)) <= .5
assert {'LIMIT', '120 +10'} <= {call[0] for call in calls}
# The posted sign keeps its own rows; with an offset its number is centered on row 76.
assert abs(posted[4]+(a+b)/2-(95+76*LARGE_SIGN_SCALE)) <= .5
assert {'DASH', '+10'} <= {call[0] for call in calls} and 'LIMIT' not in {call[0] for call in calls}
set_calls = [call for call in calls if call[1] == FontRole.SET_SPEED and call[3] < 388]
assert bool(set_calls) == (show_set and value is not None)
if set_calls:
@@ -111,12 +114,10 @@ def test_large_set_and_limit_share_typography_at_the_saved_position():
assert x + (left + right) / 2 == pytest.approx(280)
assert x + right + 20 <= 418
top, bottom = fonts.vertical_ink(text, role, size)
assert (role, size, y) == (posted[1], posted[2], posted[4])
assert (role, size) == (posted[1], posted[2])
heading = next(call for call in calls if call[0] == 'SET')
limit = next(call for call in calls if call[0] == 'LIMIT')
assert heading[1:3] == limit[1:3]
assert heading[4] + sum(fonts.vertical_ink(*heading[:3])) / 2 == pytest.approx(
limit[4] + sum(fonts.vertical_ink(*limit[:3])) / 2)
source = next(call for call in calls if call[0] == 'DASH')
assert heading[1:3] == source[1:3]
assert not any('mph' in call[0] or 'km/h' in call[0] for call in calls)
if show_set and value is None:
start, end, stroke, color = lines.call_args.args
@@ -148,7 +149,9 @@ def test_set_and_slc_keep_their_profile_specific_typography(pending):
try:
for value in (9, 65, 128):
current = state(cruise_kph=140)
# SLC follows this OSM reading, so it is the sign when nothing is pending.
current = replace(current, speed_limit=replace(current.speed_limit, speed_limit_mps=value / 3.6,
accepted_source='map', accepted_speed_limit_mps=value / 3.6, accepted_adjusted_limit_mps=value / 3.6,
pending_speed_limit_mps=value / 3.6 if pending else None,
pending_adjusted_limit_mps=value / 3.6 if pending else None,
presentation_adjusted_limit_mps=value / 3.6,
@@ -170,12 +173,15 @@ def test_set_and_slc_keep_their_profile_specific_typography(pending):
assert rows['140'][1] == FontRole.SET_SPEED
assert rows['140'][3:5] == (17, -4)
assert fonts.measure(*rows['140'][:3]).width <= 128
assert str(value) in rows and ('OSM' if pending else 'LIMIT') in rows
assert str(value) in rows and 'OSM' in rows and 'LIMIT' not in rows
assert not any('mph' in text or 'km/h' in text for text in rows)
continue
for a, b in (('SET', 'OSM' if pending else 'LIMIT'), ('140', str(value))):
for a, b in (('SET', 'OSM'), ('140', str(value))):
assert rows[a][1] == rows[b][1]
assert rows[a][2] == pytest.approx(rows[b][2])
# Only the confirmation notice shares SET's rows; the posted sign keeps its own.
if not pending:
continue
if rows[a][1] == FontRole.SET_SPEED:
assert rows[a][4] == pytest.approx(rows[b][4])
else:
@@ -223,13 +229,12 @@ def test_status_below_set_has_real_ink_clearance_and_fits_its_widget():
if owns_context:
rl.init_window(128, 128, 'SET status clearance')
try:
for profile, status, set_speed in product(Profile, ('PEDAL', 'LIMIT 45', 'OVERRIDE 100'), (70, 100, 199)):
status = 'OVERRIDE 100'
for profile, set_speed in product(Profile, (70, 100, 199)):
with BitmapFonts(profile, default_font_directory()) as fonts:
current = state(cruise_kph=set_speed, longitudinal_overridden=status == 'PEDAL', slc_prompt_open=True)
current = replace(current, speed_limit=replace(current.speed_limit,
pending_speed_limit_mps=None if status == 'PEDAL' else 50/3.6,
limiting_max_set=status == 'LIMIT 45', driver_override_active=status == 'OVERRIDE 100',
override_basis='persistent', effective_cluster_target_mps=(100 if status == 'OVERRIDE 100' else 45)/3.6))
current = state(cruise_kph=set_speed, slc_prompt_open=True)
current = replace(current, speed_limit=replace(current.speed_limit, pending_speed_limit_mps=50/3.6,
driver_override_active=True, override_basis='persistent', effective_cluster_target_mps=100/3.6))
widget = UnifiedSpeedWidget(fonts) if profile == Profile.LARGE else CompactHudRenderer(fonts, Path('/unused'))
if isinstance(widget, CompactHudRenderer):
widget._set_speed_alpha.x = 1
@@ -269,121 +274,33 @@ def test_status_below_set_has_real_ink_clearance_and_fits_its_widget():
rl.close_window()
def test_sign_status_rows_keep_balanced_insets_with_real_fonts():
def test_every_slc_state_draws_the_plain_sign_with_real_fonts():
from unittest.mock import patch
from openpilot.starpilot.ui.speed_limit_widget import SpeedLimitWidget
from openpilot.starpilot.ui.tests.test_unified_speed_native import state
owns_context = not rl.is_window_ready()
if owns_context:
rl.init_window(128, 128, 'Sign status margins')
rl.init_window(128, 128, 'Plain sign for every SLC state')
try:
for profile in Profile:
with BitmapFonts(profile, default_font_directory()) as fonts:
widget = SpeedLimitWidget(fonts, profile)
for variant in ('in_use', 'offset', 'override', 'pedal', 'retained'):
current = state(cruise_kph=140, longitudinal_overridden=variant == 'pedal')
target = 128 if variant == 'override' else 110 if variant == 'offset' else 100
adjusted = 110 if variant == 'offset' else 100
current = replace(current, speed_limit=replace(current.speed_limit,
source='vision', speed_limit_mps=100/3.6, pending_speed_limit_mps=None,
accepted_source='vision', accepted_speed_limit_mps=100/3.6, accepted_adjusted_limit_mps=target/3.6,
presentation_adjusted_limit_mps=target/3.6, effective_cluster_target_mps=target/3.6,
accepted_source='vision', accepted_speed_limit_mps=100/3.6, accepted_adjusted_limit_mps=adjusted/3.6,
presentation_adjusted_limit_mps=adjusted/3.6, effective_cluster_target_mps=(128 if variant == 'override' else adjusted)/3.6,
limiting_max_set=True, driver_override_active=variant == 'override', override_basis='persistent'))
if variant == 'pedal':
current.customization['showMaxSpeed'] = False
current.customization['layouts']['compact']['max_speed']['enabled'] = False
if variant == 'retained':
current = replace(current, speed_limit=replace(current.speed_limit, kind=ObservationKind.STALE,
speed_limit_mps=None, last_received_speed_limit_mps=100/3.6, last_received_source='vision'))
calls = []
with patch.object(fonts, 'draw', lambda *args, sink=calls: sink.append(args)):
widget.render(current)
if variant == 'retained':
assert [call[0] for call in calls if call[-1].a == 255] == ['LIMIT', '100', 'LAST VISION' if profile == Profile.LARGE else 'VISION']
bounds = speed_limit_bounds(profile, current)
assert bounds is not None
x, y = bounds[0] + 12, bounds[1] + 12
scale = widget.scale
boxes = []
for text, role, size, left, top, color in calls:
if color.a != 255:
continue
a, b = fonts.horizontal_ink(text, role, size)
c, d = fonts.vertical_ink(text, role, size)
box = left+a, top+c, left+b, top+d
# Keep real glyph ink clear of the portrait outline, including both footer rows.
assert x+9.5*scale <= box[0] < box[2] <= x+118.5*scale, (profile, variant, text)
assert y+3.5*scale <= box[1] < box[3] <= y+126.5*scale, (profile, variant, text)
assert (box[0]+box[2])/2 == pytest.approx(x+SIGN_WIDTH/2*scale, abs=.5)
boxes.append(box)
assert len(boxes) >= 2
assert all(second[1] - first[3] >= 4*scale for first, second in zip(boxes, boxes[1:], strict=False))
widget.close()
finally:
if owns_context:
rl.close_window()
def test_set_limited_sign_matches_approved_spacing_and_existing_touch_area():
from unittest.mock import patch
from openpilot.starpilot.ui.speed_limit_widget import SpeedLimitWidget, draw_set_speed, IN_USE
from openpilot.starpilot.ui.tests.test_unified_speed_native import state
from openpilot.starpilot.ui.unified_speed_presentation import resolve_unified_speed
owns_context = not rl.is_window_ready()
if owns_context:
rl.init_window(128, 128, 'SET-limited sign margins')
try:
for profile in Profile:
with BitmapFonts(profile, default_font_directory()) as fonts:
widget = SpeedLimitWidget(fonts, profile)
widget.shapes = Mock()
scale = widget.scale
for metric, limited, vienna in product((False, True), (False, True), (False, True)):
if vienna and not limited:
continue # Regulatory Vienna geometry has its own existing checks.
factor = 3.6 if metric else 2.2369362921
target, selected = (120, 100 if limited else 130) if metric else (55, 45 if limited else 70)
current = state(metric=metric, cruise_kph=selected / factor * 3.6)
current = replace(current, appearance=replace(current.appearance, use_vienna_sign=vienna),
speed_limit=replace(current.speed_limit, source='dashboard', speed_limit_mps=target / factor,
accepted_source='dashboard', accepted_speed_limit_mps=target / factor,
accepted_adjusted_limit_mps=target / factor, presentation_adjusted_limit_mps=target / factor,
effective_cluster_target_mps=target / factor, effective_cap_mps=target / factor,
pending_speed_limit_mps=None, limiting_max_set=not limited))
shown = resolve_unified_speed(current)
bounds = speed_limit_bounds(profile, current)
assert bounds is not None
x, y = bounds[0] + 12, bounds[1] + 12
cx = x + SIGN_WIDTH / 2 * scale
outline_scale, cy = (13 / 12, 70) if limited else (1, 65)
calls = []
with patch.object(fonts, 'draw', lambda *args, sink=calls: sink.append(args)):
draw_set_speed(fonts, shown, cx - 200 * scale, y, rl.WHITE)
widget.render(current)
rows = [row for row in calls if row[-1].a == 255]
assert [row[0] for row in rows] == ['SET', str(selected), 'LIMIT', str(target), *(
['SET IS LOW', 'RAISE SET'] if limited else ['DASH'])]
boxes = []
for text, role, size, left, top, _ in rows:
a, b = fonts.horizontal_ink(text, role, size)
c, d = fonts.vertical_ink(text, role, size)
boxes.append((left+a, top+c, left+b, top+d))
assert rows[1][1:3] == rows[3][1:3]
for first, second in ((0, 2), (1, 3)):
assert sum(boxes[first][1::2]) == pytest.approx(sum(boxes[second][1::2]), abs=.01)
half_width, half_height = (SIGN_WIDTH / 2 - 5) * outline_scale * scale, (SIGN_HEIGHT / 2 - 5) * outline_scale * scale
radius = 1.15 if profile == Profile.LARGE else 1.
for left, top, right, bottom in boxes[2:]:
assert (left+right)/2 == pytest.approx(cx, abs=.5)
assert min(left-(cx-half_width), cx+half_width-right,
top-(y+cy*scale-half_height), y+cy*scale+half_height-bottom)-radius >= (8 if limited else 7.5)*scale
assert boxes[-2][3] + 5*scale <= boxes[-1][1]
assert abs((boxes[2][1]-(y+cy*scale-half_height)) - (y+cy*scale+half_height-boxes[-1][3])) <= scale
# The painted stroke plus its contour remains inside the existing tap target.
outer_width, outer_height = (SIGN_WIDTH/2-1)*outline_scale*scale, (SIGN_HEIGHT/2-1)*outline_scale*scale
assert bounds[0] <= cx-outer_width < cx+outer_width <= bounds[2]
assert bounds[1] <= y+cy*scale-outer_height < y+cy*scale+outer_height <= bounds[3]
accent = widget.shapes.outline.call_args.args[2]
assert (accent.r == IN_USE.r) == (not limited)
# SLC keeps following its accepted VISION limit through a gap, so no LAST.
assert [call[0] for call in calls if call[-1].a == 255] == ['VISION', '100'] + (['+10'] if variant == 'offset' else [])
widget.close()
finally:
if owns_context:
@@ -509,7 +426,7 @@ def test_native_signs_offsets_and_captions_fit_their_touch_targets():
@pytest.mark.parametrize('profile', list(Profile))
def test_preview_sprite_keeps_the_full_confirmation_override_and_set_limited_sign(profile):
def test_preview_sprite_keeps_the_full_confirmation_and_sign_scenes(profile):
import json
from unittest.mock import patch
from openpilot.starpilot.ui.layout_preview_renderer import _Canvas, _straight_rgba, sample_state
@@ -147,7 +147,7 @@ def test_unknown_gap_preserves_large_slc_number_offset_and_source(metric, target
adapter = RuntimeSnapshotAdapter(ui)
before_state = adapter.build(ShellMode.ONROAD, now_ns=NOW).onroad
before = resolve_unified_speed(before_state)
assert before.limit_text != '–'
assert before.posted_text != '–'
assert before.offset_text is not None
assert not before.posted_retained
ui.sm.messages['slcState'] = unknown_slc()
@@ -155,8 +155,8 @@ def test_unknown_gap_preserves_large_slc_number_offset_and_source(metric, target
ui.sm.logMonoTime['slcState'] = NOW + age
held_state = adapter.build(ShellMode.ONROAD, now_ns=NOW + age).onroad
held = resolve_unified_speed(held_state)
assert (held.mode, held.posted_text, held.limit_text, held.offset_text, held.source) == (
before.mode, before.posted_text, before.limit_text, before.offset_text, before.source)
assert (held.mode, held.posted_text, held.offset_text, held.source) == (
before.mode, before.posted_text, before.offset_text, before.source)
assert (held.active_side, held.status, held.pending) == ('none', 'Unavailable', False)
assert held.posted_retained
obs = held_state.speed_limit
@@ -167,7 +167,7 @@ def test_unknown_gap_preserves_large_slc_number_offset_and_source(metric, target
# Repeated unavailable messages do not extend the hold.
ui.sm.logMonoTime['slcState'] = NOW + 150_000_001
expired = resolve_unified_speed(adapter.build(ShellMode.ONROAD, now_ns=NOW + 150_000_001).onroad)
assert (expired.limit_text, expired.posted_text) == ('–', '–')
assert expired.posted_text == '–'
ui.sm.messages['slcState'] = slc
ui.sm.logMonoTime['slcState'] = NOW + 160_000_000
recovered = resolve_unified_speed(adapter.build(ShellMode.ONROAD, now_ns=NOW + 160_000_000).onroad)
@@ -274,7 +274,6 @@ class TestRuntimeSnapshot(unittest.TestCase):
self.assertIsNone(observation.decision_id)
presentation = resolve_unified_speed(state)
self.assertEqual(presentation.posted_text, '30')
self.assertEqual(presentation.limit_text, '35')
self.assertEqual(presentation.offset_text, '+5')
self.assertEqual(presentation.active_side, 'none')
ui.params.values['SpeedLimitController'] = '1'
@@ -26,7 +26,7 @@ from openpilot.starpilot.ui.unified_speed_presentation import resolve_unified_sp
@pytest.mark.parametrize('metric', [False, True])
@pytest.mark.parametrize('offset', [0, 5])
@pytest.mark.parametrize('cluster_delta', [0, 2])
def test_set_limited_tracks_controller_target_without_changing_set(metric, offset, cluster_delta):
def test_followed_limit_tracks_the_controller_while_set_stays_the_drivers(metric, offset, cluster_delta):
fixture = replay.RuntimeReplayTests()
fixture.setUp()
sm, cp = fixture.sm, fixture.cp
@@ -42,8 +42,9 @@ def test_set_limited_tracks_controller_target_without_changing_set(metric, offse
current = OnroadState(True, False, 40 / factor, float(sm['carState'].vCruiseCluster),
speed_limit_from_message(message), metric=metric, longitudinal_active=True)
shown = resolve_unified_speed(current)
assert shown.set_limited == (selected == 45)
assert shown.limit_text == str(55 + offset)
# SET at the limit plus offset counts as following it, whatever the speedometer gap.
assert shown.limit_in_use == (selected != 45)
assert (shown.source, shown.posted_text, shown.offset_text) == ('dashboard', '55', f'+{offset}' if offset else None)
assert shown.max_text == str(selected)
assert sm['carState'].vCruise == pytest.approx((selected - cluster_delta) / factor * 3.6)
@@ -68,8 +69,8 @@ def test_controller_messages_keep_set_stable_through_pedal_release_stop_and_resu
sm['carState'].gasPressed = True
pressed, shown = display(1)
assert shown.override_text is None and not shown.limit_in_use
assert speed_status(pressed, Profile.COMPACT, shown) == 'PEDAL'
assert set_speed_status(pressed, Profile.COMPACT, shown) is None
# Pressing the gas is not a status; only a held override is.
assert speed_status(shown) is None and set_speed_status(pressed, Profile.COMPACT, shown) is None
sm['carState'].gasPressed = False
_, released = display(2)
assert released.override_text == ('95' if mode is settings.PedalOverride.SPEED_REACHED else '100')
@@ -104,7 +105,7 @@ def test_hidden_set_keeps_control_context_inside_moved_confirmation(profile, mod
assert not foreground_calls(font.draw)
SpeedLimitWidget(font, profile).render_confirmation(current)
rows = [call.args for call in foreground_calls(font.draw)]
expected = {'limit': 'Now: LIMIT 128', 'override': 'Now: OVERRIDE 128', 'pedal': 'Now: PEDAL'}[mode]
expected = {'limit': 'NEW LIMIT', 'override': 'Now: OVERRIDE 128', 'pedal': 'NEW LIMIT'}[mode]
assert [row[0] for row in rows] == [expected, 'ACCEPT', '120', 'REJECT', 'NEW LIMIT']
status, accept = rows[:2]
assert status[4] + font.vertical_ink(*status[:3])[1] < accept[4]
@@ -502,7 +502,8 @@ def test_retention_respects_lower_max_and_reset(tmp_path, offset):
shown = resolve_unified_speed(view)
assert view.speed_limit.kind != ObservationKind.VALID and shown.posted_retained
assert shown.status == 'Using set speed'
assert shown.set_limited and not shown.show_last
# SLC still follows its accepted limit through the gap; SET below it is ordinary cruising.
assert not shown.limit_in_use and not shown.show_last
assert replace(shown, posted_retained=False) == resolve_unified_speed(before)
_, recovered, target = drive.step(400)
assert recovered.speed_limit.sign_recovering
@@ -13,7 +13,7 @@ from openpilot.starpilot.ui.onroad_large_widgets import UnifiedSpeedWidget
from openpilot.starpilot.ui.onroad import OnroadView
from openpilot.starpilot.ui.onroad_state import ObservationKind, OnroadState, SpeedLimitObservation, slc_controls, speed_limit_bounds
from openpilot.starpilot.ui.presentation import FontRole, Profile
from openpilot.starpilot.ui.speed_limit_widget import INK, IN_USE, MUTED, REJECT, SpeedLimitWidget, draw_text
from openpilot.starpilot.ui.speed_limit_widget import INK, IN_USE, MUTED, REJECT, SpeedLimitWidget, draw_text, set_speed_status
from openpilot.starpilot.ui.speed_limit_shapes import SpeedLimitShapes
from openpilot.starpilot.ui.unified_speed_presentation import displayed_limit_mps, resolve_unified_speed
@@ -25,7 +25,7 @@ def drawing(monkeypatch):
'draw_ring', 'draw_circle_gradient', 'draw_rectangle_rec', 'draw_circle_v', 'draw_rectangle_gradient_ex'):
calls[name] = Mock()
monkeypatch.setattr(rl, name, calls[name])
for name in ('circle', 'arrow', 'outline', 'wheel_key', 'button'):
for name in ('circle', 'arrow', 'outline', 'thick_outline', 'wheel_key', 'button'):
calls[name] = Mock()
monkeypatch.setattr(SpeedLimitShapes, name, calls[name])
monkeypatch.setattr('openpilot.starpilot.ui.onroad_large_widgets.draw_control_card', Mock())
@@ -81,7 +81,7 @@ def test_latest_limit_and_offset_replace_accepted_sign_while_waiting():
@pytest.mark.parametrize('profile', list(Profile))
@pytest.mark.parametrize('vienna', [False, True])
def test_sign_keeps_distinct_slc_target_when_set_widget_is_hidden(profile, vienna, drawing):
def test_sign_shows_the_followed_limit_when_set_widget_is_hidden(profile, vienna, drawing):
current = state()
customization = default_document()
customization['showMaxSpeed'] = False
@@ -91,9 +91,10 @@ def test_sign_keeps_distinct_slc_target_when_set_widget_is_hidden(profile, vienn
effective_cluster_target_mps=45 / 3.6))
font = fonts(profile)
render_sign(SpeedLimitWidget(font, profile), current)
assert [call.args[0] for call in foreground_calls(font.draw)] == ['LIMIT', '45', 'OSM 50 +5']
drawing['outline'].assert_called_once()
drawing['circle'].assert_not_called()
# The live OSM 50 was not adopted; SLC follows its accepted DASH 40 +5, highlighted as in use.
assert [call.args[0] for call in foreground_calls(font.draw)] == ['DASH', '40', '+5']
drawing['circle' if vienna else 'thick_outline'].assert_called_once()
drawing['outline'].assert_not_called()
@pytest.mark.parametrize('profile', list(Profile))
@@ -124,11 +125,10 @@ def test_set_and_binding_slc_stay_visible_beside_sign_or_prompt(profile, stage):
view._slc_actions(current)
texts = [call.args[0] for call in foreground_calls(font.draw)]
assert ('SET' if profile == Profile.LARGE else 'MAX') in texts and '35' in texts and not any(text.startswith('SLC ') for text in texts)
assert ('LIMIT 30' in texts) == (stage == 'prompt' and profile == Profile.LARGE)
if stage == 'prompt' and profile == Profile.COMPACT:
# SET never reports a LIMIT status; the prompt's own context is NEW LIMIT.
assert not any(text in ('LIMIT', 'LIMIT 30', 'Now: LIMIT 30') for text in texts)
if stage == 'prompt':
assert 'NEW LIMIT' in texts
assert ('Now: LIMIT 30' in texts) == (stage == 'expanded')
assert ('LIMIT' in texts) == (stage in ('live', 'retained'))
if pending:
assert '25' in texts and not any(text.startswith('LAST') for text in texts)
assert ('OSM' in texts) == (stage != 'expanded')
@@ -137,7 +137,7 @@ def test_set_and_binding_slc_stay_visible_beside_sign_or_prompt(profile, stage):
@pytest.mark.parametrize('gap', [False, True])
def test_compact_max_fades_while_the_restricted_limit_keeps_its_warning(gap, drawing):
def test_compact_max_fades_while_set_below_the_limit_leaves_a_plain_sign(gap, drawing):
current = state(cruise_kph=45, drive_frame=1)
current = replace(current, speed_limit=replace(current.speed_limit, source='dashboard', speed_limit_mps=55 / 3.6,
accepted_source='dashboard', accepted_speed_limit_mps=55 / 3.6, accepted_adjusted_limit_mps=55 / 3.6,
@@ -154,7 +154,8 @@ def test_compact_max_fades_while_the_restricted_limit_keeps_its_warning(gap, dra
assert {call.args[0] for call in foreground_calls(font.draw)} == {'MAX', '45'}
font.draw.reset_mock()
hud._speed_limit_sign(current)
assert [call.args[0] for call in foreground_calls(font.draw)] == ['LIMIT', '55', 'SET IS LOW', 'RAISE SET']
# SET below the limit is ordinary cruising: the sign stays the plain, unhighlighted limit.
assert [call.args[0] for call in foreground_calls(font.draw)] == ['DASH', '55']
@pytest.mark.parametrize('profile', list(Profile))
@@ -176,18 +177,16 @@ def test_accepted_sign_keeps_text_geometry_and_styling_through_source_gaps(profi
rendered = []
for observation in (obs, gap, replace(obs, sign_recovering=True)):
font.draw.reset_mock()
for shape in ('outline', 'circle'):
for shape in ('outline', 'thick_outline', 'circle', 'draw_ring'):
drawing[shape].reset_mock()
render_sign(sign, replace(current, speed_limit=observation))
text = [(*call.args[:-1], rgba_tuple(call.args[-1])) for call in foreground_calls(font.draw)]
shapes = [(shape, *call.args[:2], rgba_tuple(call.args[2]), call.kwargs)
for shape in ('outline', 'circle') for call in drawing[shape].call_args_list]
for shape in ('outline', 'thick_outline', 'circle') for call in drawing[shape].call_args_list]
rendered.append((text, shapes))
assert rendered[0] == rendered[1] == rendered[2]
texts = [row[0] for row in rendered[0][0]]
assert not any(text.startswith('LAST') for text in texts)
assert ('SET IS LOW' in texts) == (selected == 'below')
assert ('RAISE SET' in texts) == (selected == 'below')
assert not any(text.startswith('LAST') or text in ('SET IS LOW', 'RAISE SET', 'LIMIT') for text in texts)
@pytest.mark.parametrize('profile', list(Profile))
@@ -233,8 +232,9 @@ def test_both_renderers_show_small_latest_sign_and_offset(profile):
def test_sign_heading_identifies_the_displayed_source(profile, pending, vienna, offset, source, heading):
current = state(show_slc_offset=offset)
current = replace(current, appearance=replace(current.appearance, use_vienna_sign=vienna))
current = replace(current, speed_limit=replace(current.speed_limit, source=source,
accepted_source='vision' if source == 'dashboard' else 'dashboard',
# SLC follows the displayed source itself, so its own heading is what the sign shows.
current = replace(current, speed_limit=replace(current.speed_limit, source=source, accepted_source=source,
accepted_speed_limit_mps=50 / 3.6, accepted_adjusted_limit_mps=55 / 3.6,
pending_speed_limit_mps=current.speed_limit.pending_speed_limit_mps if pending else None))
font = fonts(profile)
render_sign(SpeedLimitWidget(font, profile), current)
@@ -354,26 +354,19 @@ def test_override_sign_uses_cluster_target_and_restores_normal_sign(profile, vie
current = state(cruise_kph=140)
current = replace(current, appearance=replace(current.appearance, use_vienna_sign=vienna),
speed_limit=replace(current.speed_limit, speed_limit_mps=100 / 3.6,
accepted_source='map', accepted_speed_limit_mps=100 / 3.6, accepted_adjusted_limit_mps=100 / 3.6,
presentation_adjusted_limit_mps=100 / 3.6, pending_speed_limit_mps=None,
effective_cluster_target_mps=128 / 3.6))
if retained:
current = replace(current, speed_limit=replace(current.speed_limit, kind=ObservationKind.ABSENT, source='none',
speed_limit_mps=None, last_received_speed_limit_mps=100 / 3.6, last_received_source='map'))
overridden = replace(current, speed_limit=replace(current.speed_limit, driver_override_active=True))
sign.render(replace(overridden, longitudinal_overridden=True))
assert 'Override' not in [call.args[0] for call in foreground_calls(font.draw)]
assert 'Pedal' in [call.args[0] for call in foreground_calls(font.draw)]
font.draw.reset_mock()
sign.render(overridden)
rows = [call.args for call in foreground_calls(font.draw)]
assert [row[0] for row in rows] == (['Override', '128', 'LAST OSM', '100'] if retained and profile == Profile.LARGE else ['Override', '128', 'OSM 100'])
assert rows[1][2] > rows[-1][2]
for first, second in zip(rows, rows[1:], strict=False):
assert first[4] + font.vertical_ink(*first[:3])[1] <= second[4] + font.vertical_ink(*second[:3])[0] + 1
drawing['outline'].assert_called()
font.draw.reset_mock()
sign.render(current)
assert foreground_calls(font.draw)[0].args[0] == ('LAST OSM' if retained and profile == Profile.LARGE else 'OSM')
# The override belongs to SET; the sign stays the followed OSM limit throughout.
for driver, status in ((replace(overridden, longitudinal_overridden=True), None), (overridden, 'OVERRIDE 128'), (current, None)):
font.draw.reset_mock()
sign.render(driver)
assert [call.args[0] for call in foreground_calls(font.draw)] == ['OSM', '100']
assert set_speed_status(driver, profile, resolve_unified_speed(driver)) == status
drawing['circle' if vienna else 'outline'].assert_called()
@@ -384,7 +377,8 @@ def test_override_sign_uses_cluster_target_and_restores_normal_sign(profile, vie
@pytest.mark.parametrize('source,heading', [('map', 'LAST OSM'), ('vision', 'LAST VISION'), ('dashboard', 'LAST DASH'),
('mapbox', 'LAST NAV'), ('online', 'LAST'), ('unknown', 'LAST')])
def test_retained_limits_keep_original_source_and_have_no_actions(profile, vienna, latest_received, offset, source, heading, drawing):
current = state(show_slc_offset=offset)
# LAST history is what the sign shows while SLC is not using an accepted limit.
current = state(show_slc_offset=offset, longitudinal_active=False)
observation = replace(current.speed_limit, kind=ObservationKind.STALE, source='none', speed_limit_mps=None,
pending_speed_limit_mps=None, last_received_speed_limit_mps=50/3.6 if latest_received else None,
last_received_source=source, accepted_source=('vision' if source == 'dashboard' else 'dashboard') if latest_received else source,
@@ -439,7 +433,7 @@ def test_compact_set_speed_stays_visible_during_confirmation_then_fades():
assert alpha < .01
def test_compact_max_fades_while_pedal_status_remains_in_the_sign():
def test_compact_max_fades_and_the_sign_stays_the_limit_while_on_the_gas():
font = fonts(Profile.COMPACT)
renderer = CompactHudRenderer(font, Mock())
current = state(drive_frame=1, longitudinal_overridden=True)
@@ -452,7 +446,7 @@ def test_compact_max_fades_while_pedal_status_remains_in_the_sign():
assert 'PEDAL' not in [call.args[0] for call in foreground_calls(font.draw)]
font.draw.reset_mock()
renderer._speed_limit_sign(current)
assert 'Pedal' in [call.args[0] for call in foreground_calls(font.draw)]
assert [call.args[0] for call in foreground_calls(font.draw)] == ['DASH', '40', '+5']
def test_compact_max_restores_dinish_number_label_position_and_gradient(drawing):
@@ -613,3 +607,30 @@ def test_purple_sign_renders_three_full_cycles_across_retention(profile, automat
font.draw.reset_mock()
sign.render(replace(current, observed_ns=14_900_000_000))
assert all(rgba_tuple(call.args[-1]) != (188, 132, 255, 255) for call in foreground_calls(font.draw))
@pytest.mark.parametrize('profile', list(Profile))
@pytest.mark.parametrize('vienna', [False, True])
@pytest.mark.parametrize('limiting', [False, True])
def test_followed_limit_keeps_the_source_sign_and_only_turns_its_outline_green(profile, vienna, limiting, drawing):
# OSM 65 +10 being followed reads as the OSM sign with a green outline, never a LIMIT 75 readout.
current = state(metric=False, cruise_kph=80 * CV.MPH_TO_KPH)
current = replace(current, appearance=replace(current.appearance, use_vienna_sign=vienna),
speed_limit=replace(current.speed_limit, source='map', speed_limit_mps=65 * CV.MPH_TO_MS,
accepted_source='map', accepted_speed_limit_mps=65 * CV.MPH_TO_MS, accepted_adjusted_limit_mps=75 * CV.MPH_TO_MS,
presentation_adjusted_limit_mps=75 * CV.MPH_TO_MS, effective_cluster_target_mps=75 * CV.MPH_TO_MS,
effective_cap_mps=75 * CV.MPH_TO_MS, pending_speed_limit_mps=None, limiting_max_set=limiting))
assert resolve_unified_speed(current).limit_in_use == limiting
font = fonts(profile)
render_sign(SpeedLimitWidget(font, profile), current)
assert [call.args[0] for call in foreground_calls(font.draw)] == ['OSM', '65', '+10']
if vienna:
drawing['circle'].assert_called_once()
assert [rgba_tuple(call.args[-1]) for call in drawing['draw_ring'].call_args_list][-1:] == (
[rgba_tuple(IN_USE)] if limiting else [])
drawing['thick_outline'].assert_not_called()
else:
(drawing['thick_outline'] if limiting else drawing['outline']).assert_called_once()
(drawing['outline'] if limiting else drawing['thick_outline']).assert_not_called()
if limiting:
assert rgba_tuple(drawing['thick_outline'].call_args.args[2]) == rgba_tuple(IN_USE)
@@ -1,4 +1,4 @@
"""Presentation follows selected set speed and the latest source observation."""
"""The sign shows the limit SLC uses while it is on, otherwise the latest source observation."""
from dataclasses import replace
import pytest
@@ -14,16 +14,30 @@ def state(**changes):
return replace(OnroadState(True, False, 20., 100., obs, metric=True, longitudinal_active=True), **changes)
@pytest.mark.parametrize('metric,posted,offset', [(True, '108', '+7'), (False, '67', '+5')])
def test_latest_received_source_and_offset_are_independent_of_accepted_history(metric, posted, offset):
@pytest.mark.parametrize('metric,live,accepted', [(True, ('108', '+7'), ('72', '+7')), (False, ('67', '+5'), ('45', '+4'))])
def test_sign_shows_the_accepted_limit_while_slc_is_on_and_the_latest_reading_otherwise(metric, live, accepted):
# The fixture's VISION reading differs from the accepted DASH limit without being pending: it was rejected.
current = state(metric=metric)
shown = resolve_unified_speed(replace(current, speed_limit=replace(current.speed_limit,
last_received_source='dashboard', last_received_speed_limit_mps=20.)))
assert (shown.posted_text, shown.source, shown.offset_text) == (posted, 'vision', offset)
assert not shown.posted_retained
assert shown.active_side == 'max'
for on in (True, False):
shown = resolve_unified_speed(replace(current, longitudinal_active=on))
assert (shown.posted_text, shown.offset_text) == (accepted if on else live)
assert shown.source == ('dashboard' if on else 'vision')
assert not shown.posted_retained and not shown.show_last
pedal = resolve_unified_speed(replace(current, longitudinal_active=False, longitudinal_overridden=True))
assert (pedal.posted_text, pedal.source) == (accepted[0], 'dashboard')
@pytest.mark.parametrize('metric', [False, True])
def test_rejected_reading_keeps_the_followed_limit_source_speed_and_offset(metric):
factor = 3.6 if metric else 2.2369362921
current = state(metric=metric, cruise_kph=80 / factor * 3.6)
followed = replace(current.speed_limit, source='vision', speed_limit_mps=55 / factor, presentation_adjusted_limit_mps=60 / factor,
accepted_source='map', accepted_speed_limit_mps=45 / factor, accepted_adjusted_limit_mps=50 / factor,
effective_cluster_target_mps=50 / factor, effective_cap_mps=50 / factor, limiting_max_set=True)
shown = resolve_unified_speed(replace(current, speed_limit=followed))
assert (shown.source, shown.posted_text, shown.offset_text, shown.limit_in_use) == ('map', '45', '+5', True)
offered = resolve_unified_speed(replace(current, speed_limit=replace(followed, pending_speed_limit_mps=55 / factor)))
assert (offered.source, offered.posted_text, offered.pending) == ('vision', '55', True)
def test_set_speed_is_the_only_active_speed_role_even_below_or_above_the_input_limit():
for selected in (50., 79.2, 120.):
shown = resolve_unified_speed(state(cruise_kph=selected))
@@ -36,35 +50,11 @@ def test_slc_limiting_role_keeps_driver_set_and_source_sign_independent():
current = state()
limited = replace(current, speed_limit=replace(current.speed_limit, limiting_max_set=True, effective_cap_mps=22.))
shown = resolve_unified_speed(limited)
assert (shown.max_text, shown.posted_text, shown.active_side, shown.status) == ('100', '108', 'limit', 'Using speed limit')
assert (shown.max_text, shown.posted_text, shown.active_side, shown.status) == ('100', '72', 'limit', 'Using speed limit')
pedal = resolve_unified_speed(replace(limited, longitudinal_overridden=True))
assert (pedal.active_side, pedal.status) == ('max', 'Using accelerator')
@pytest.mark.parametrize('retained', [False, True])
def test_slc_target_is_independent_of_the_road_sign(retained):
current = state()
obs = replace(current.speed_limit, limiting_max_set=True, effective_cluster_target_mps=22.)
if retained:
obs = replace(obs, kind=ObservationKind.STALE, speed_limit_mps=None,
last_received_speed_limit_mps=30., last_received_adjusted_limit_mps=32.)
shown = resolve_unified_speed(replace(current, speed_limit=obs))
assert (shown.max_text, shown.posted_text, shown.offset_text, shown.slc_target_text) == ('100', '108', '+7', '79')
assert shown.posted_retained == retained
matching = replace(obs, effective_cluster_target_mps=32.)
assert resolve_unified_speed(replace(current, speed_limit=matching)).slc_target_text == '115'
@pytest.mark.parametrize('change', ['no-limit', 'pedal', 'override', 'disengaged', 'display-only'])
def test_slc_target_only_shows_a_binding_system_ceiling(change):
current = state()
observation = replace(current.speed_limit, effective_cluster_target_mps=22., limiting_max_set=change != 'no-limit',
driver_override_active=change == 'override', action_enabled=change != 'display-only')
current = replace(current, speed_limit=observation, longitudinal_active=change != 'disengaged',
longitudinal_overridden=change == 'pedal')
assert resolve_unified_speed(current).slc_target_text is None
@pytest.mark.parametrize('automatic,status', [(False, 'Confirm speed limit'), (True, 'Adopting limit')])
def test_pending_limit_is_shown_immediately_with_its_own_offset(automatic, status):
current = state()
@@ -81,7 +71,7 @@ def test_manual_override_and_pedal_status_preserve_the_set_speed_and_sign():
assert manual.status == 'Set-speed override'
assert pedal.status == 'Using accelerator'
assert manual.max_text == pedal.max_text == '100'
assert manual.posted_text == pedal.posted_text == '108'
assert manual.posted_text == pedal.posted_text == '72'
def test_retained_limit_is_information_only_without_a_separate_ceiling():
@@ -102,24 +92,22 @@ def test_display_only_and_unset_speed_remain_explicit():
def test_hidden_max_and_offset_preferences_keep_the_latest_sign():
current = state()
shown = resolve_unified_speed(replace(current, customization={**current.customization, 'showMaxSpeed': False}, show_slc_offset=False))
assert (shown.mode, shown.posted_text, shown.offset_text) == ('limit_only', '108', None)
assert (shown.mode, shown.posted_text, shown.offset_text) == ('limit_only', '72', None)
@pytest.mark.parametrize('stage,expected', [('live', True), ('confirmation', False), ('retained', False), ('last_received', True)])
@pytest.mark.parametrize('stage,expected', [('live', True), ('confirmation', False), ('accepted', False), ('last_received', True)])
def test_configured_offset_follows_the_resolved_posted_limit(stage, expected):
from openpilot.starpilot.speed_limits.speed_domain import OffsetBand, OffsetSchedule
current = state(slc_offset_schedule=OffsetSchedule((OffsetBand(0., 25., 0.), OffsetBand(25., None, 2.))))
current = state(slc_offset_schedule=OffsetSchedule((OffsetBand(0., 25., 0.), OffsetBand(25., None, 2.))),
longitudinal_active=stage in ('confirmation', 'accepted'))
if stage == 'confirmation':
current = replace(current, speed_limit=replace(current.speed_limit, pending_speed_limit_mps=20., pending_adjusted_limit_mps=20.))
elif stage in ('retained', 'last_received'):
elif stage == 'last_received':
current = replace(current, speed_limit=replace(current.speed_limit, kind=ObservationKind.STALE, speed_limit_mps=None,
accepted_adjusted_limit_mps=20., last_received_speed_limit_mps=30., last_received_adjusted_limit_mps=32.,
effective_cluster_target_mps=20. if stage == 'retained' else None, effective_cap_mps=20.))
last_received_speed_limit_mps=30., last_received_adjusted_limit_mps=32.))
shown = resolve_unified_speed(current, confirmation=stage == 'confirmation')
assert shown.posted_text == ('108' if expected else '72')
assert shown.offset_configured == expected
@pytest.mark.parametrize('pending,adjusted,presentation,offset,expected', [
(30., 33., 32., 2., '119'),
(30., None, 32., 2., '115'),
@@ -150,7 +138,8 @@ def test_in_use_requires_accepted_target_and_actual_control(change):
}
current = replace(current, speed_limit=replace(obs, **changes.get(change, {})),
longitudinal_overridden=change == 'pedal', longitudinal_active=change != 'disengaged')
assert resolve_unified_speed(current).limit_in_use == (change in ('none', 'retained', 'recovering'))
# The accepted limit is the one in use, whichever source or reading the latest observation shows.
assert resolve_unified_speed(current).limit_in_use == (change in ('none', 'retained', 'recovering', 'source', 'rounded-posted'))
def test_pedal_basis_cannot_be_presented_as_a_held_override_between_message_updates():
@@ -162,43 +151,6 @@ def test_pedal_basis_cannot_be_presented_as_a_held_override_between_message_upda
assert resolve_unified_speed(released).override_text == '94'
@pytest.mark.parametrize('metric', [False, True])
@pytest.mark.parametrize('selected,limited', [(45, True), (55, True), (59.6, False), (60, False), (70, False)])
def test_set_limited_uses_the_adjusted_cluster_target_and_visible_units(metric, selected, limited):
factor = 3.6 if metric else 2.2369362921
current = state(metric=metric, cruise_kph=selected / factor * 3.6)
obs = replace(current.speed_limit, source='dashboard', speed_limit_mps=55 / factor,
accepted_speed_limit_mps=55 / factor, accepted_adjusted_limit_mps=60 / factor,
presentation_adjusted_limit_mps=60 / factor, effective_cluster_target_mps=60 / factor,
effective_cap_mps=48 / factor)
shown = resolve_unified_speed(replace(current, speed_limit=obs))
assert shown.set_limited == limited
assert (shown.posted_text, shown.limit_text, shown.active_side) == ('55', '60', 'max')
assert not shown.limit_in_use and shown.slc_target_text is None
@pytest.mark.parametrize('change', ['none', 'retained', 'hold', 'recovering', 'pending', 'automatic', 'source',
'posted', 'target', 'pedal', 'override', 'display-only', 'binding', 'disengaged',
'no-cap', 'no-target', 'no-set'])
def test_set_limited_only_instructs_for_a_qualified_accepted_target(change):
current = state(cruise_kph=60., longitudinal_active=change != 'disengaged', longitudinal_overridden=change == 'pedal')
obs = replace(current.speed_limit, source='dashboard', speed_limit_mps=20.,
presentation_adjusted_limit_mps=22., effective_cluster_target_mps=22., effective_cap_mps=21.)
changes = {
'retained': {'kind': ObservationKind.STALE, 'speed_limit_mps': None, 'last_received_speed_limit_mps': 20.},
'hold': {'status': 'display_hold'}, 'recovering': {'sign_recovering': True},
'pending': {'pending_speed_limit_mps': 25.},
'automatic': {'pending_speed_limit_mps': 25., 'automatic_adoption_pending': True},
'source': {'accepted_source': 'vision'}, 'posted': {'accepted_speed_limit_mps': 20.01},
'target': {'effective_cluster_target_mps': 22.01}, 'override': {'driver_override_active': True},
'display-only': {'action_enabled': False}, 'binding': {'limiting_max_set': True},
'no-cap': {'effective_cap_mps': None}, 'no-target': {'effective_cluster_target_mps': None},
}
current = replace(current, speed_limit=replace(obs, **changes.get(change, {})),
cruise_kph=None if change == 'no-set' else current.cruise_kph)
assert resolve_unified_speed(current).set_limited == (change in ('none', 'retained', 'recovering'))
@pytest.mark.parametrize('metric', [False, True])
@pytest.mark.parametrize('selected', [45, 60, 70])
@pytest.mark.parametrize('kind', [ObservationKind.ABSENT, ObservationKind.UNKNOWN, ObservationKind.STALE])
@@ -216,28 +168,29 @@ def test_accepted_target_survives_source_gaps_without_presenting_rejected_histor
held = resolve_unified_speed(replace(current, speed_limit=gap))
assert held.posted_retained
assert not held.show_last
assert (held.posted_text, held.limit_text, held.source, held.offset_text) == ('55', '60', 'dashboard', '+5')
assert (held.limit_in_use, held.set_limited, held.active_side, held.status) == (
before.limit_in_use, before.set_limited, before.active_side, before.status)
assert (held.posted_text, held.source, held.offset_text) == ('55', 'dashboard', '+5')
assert (held.limit_in_use, held.active_side, held.status) == (before.limit_in_use, before.active_side, before.status)
recovered = resolve_unified_speed(replace(current, speed_limit=replace(obs, sign_recovering=True)))
assert recovered == before
@pytest.mark.parametrize('change', ['no-cap', 'zero-cap', 'no-target', 'different-target', 'no-accepted', 'no-adjusted',
'no-session', 'no-source', 'off', 'pedal', 'override', 'display-only', 'display-hold', 'pending'])
def test_source_history_stays_last_without_a_usable_accepted_controller_target(change):
@pytest.mark.parametrize('change,accepted', [
('none', True), ('no-cap', True), ('different-target', True), ('no-session', True), ('pedal', True), ('override', True),
('no-accepted', False), ('no-adjusted', False), ('no-source', False), ('off', False), ('display-only', False),
('display-hold', False), ('pending', False)])
def test_source_history_stays_last_only_without_an_accepted_limit_in_use(change, accepted):
current = state(cruise_kph=60., longitudinal_active=change != 'off', longitudinal_overridden=change == 'pedal')
obs = replace(current.speed_limit, kind=ObservationKind.STALE, speed_limit_mps=None, source='none',
last_received_speed_limit_mps=20., last_received_source='dashboard',
last_received_adjusted_limit_mps=22., effective_cluster_target_mps=22., effective_cap_mps=21.)
last_received_speed_limit_mps=30., last_received_source='vision',
last_received_adjusted_limit_mps=32., effective_cluster_target_mps=22., effective_cap_mps=21.)
changes = {
'no-cap': {'effective_cap_mps': None}, 'zero-cap': {'effective_cap_mps': 0.},
'no-target': {'effective_cluster_target_mps': None}, 'different-target': {'effective_cluster_target_mps': 23.},
'no-cap': {'effective_cap_mps': None}, 'different-target': {'effective_cluster_target_mps': 23.},
'no-accepted': {'accepted_speed_limit_mps': None}, 'no-adjusted': {'accepted_adjusted_limit_mps': None},
'no-session': {'session_id': None}, 'no-source': {'accepted_source': 'none'},
'override': {'driver_override_active': True}, 'display-only': {'action_enabled': False},
'display-hold': {'status': 'display_hold'}, 'pending': {'pending_speed_limit_mps': 25.},
}
shown = resolve_unified_speed(replace(current, speed_limit=replace(obs, **changes.get(change, {}))))
assert shown.show_last and shown.posted_retained
assert not shown.limit_in_use and not shown.set_limited
assert shown.posted_retained
assert shown.show_last != accepted
assert (shown.source, shown.posted_text) == (('dashboard', '72') if accepted else ('vision', '108'))
@@ -70,10 +70,9 @@ def test_vision_sign_and_slc_cap_use_configured_units_without_rewriting_set(prof
return [call.args[0] for call in foreground_calls(font.draw)]
texts = render(output.message.slcState, 90.)
set_is_low = expected_mps > 90. * CV.KPH_TO_MS
assert str(number) in texts
assert ('VISION' in texts) == (confirmation or not set_is_low)
assert ('SET IS LOW' in texts) == (set_is_low and not confirmation)
# The sign is always the VISION limit, whether or not SET is below it.
assert str(number) in texts and 'VISION' in texts
assert not any(text in ('SET IS LOW', 'RAISE SET', 'LIMIT') for text in texts)
if confirmation:
assert output.message.slcState.hasPending
state = output.message.slcState
@@ -87,5 +86,4 @@ def test_vision_sign_and_slc_cap_use_configured_units_without_rewriting_set(prof
assert str(number) in texts
assert str(round(90. if metric else 90. * CV.KPH_TO_MPH)) in texts
assert ('SET' if profile == Profile.LARGE else 'MAX') in texts
assert ('SET IS LOW' in texts) == set_is_low
assert ('RAISE SET' in texts) == set_is_low
assert 'VISION' in texts and not any(text in ('SET IS LOW', 'RAISE SET', 'LIMIT') for text in texts)