Files
StarPilot/selfdrive/ui/tests/test_slc_sources_bubble.py
T
2026-08-18 01:57:20 -04:00

85 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from openpilot.selfdrive.ui.onroad.starpilot.source_bubble_layout import (
enabled_source_titles,
fit_source_label,
source_abbreviated_value_text,
source_content_metrics,
source_value_text,
visible_source_rows,
)
def test_source_content_metrics_scale_with_visible_row_count():
assert source_content_metrics(3) == (30, 34, 7)
assert source_content_metrics(4) == (30, 32, 7)
assert source_content_metrics(5) == (28, 30, 6)
def test_fit_source_label_preserves_a_safe_value_column_gap():
def width(text: str) -> int:
return len(text) * 10
assert fit_source_label("Dashboard", "Dash", 80, width) == "Dash"
assert fit_source_label("Vision", "Vision", 70, width) == "Vision"
assert fit_source_label("Dashboard", "Dash", 20, width) == "D…"
def test_source_value_text_keeps_missing_values_as_a_dash():
assert source_value_text(0) == ""
assert source_value_text(0.1) == ""
assert source_value_text(55) == "55"
assert source_value_text(float("nan")) == ""
assert source_value_text(float("inf")) == ""
assert source_abbreviated_value_text(0) == "X"
assert source_abbreviated_value_text(55) == "55"
def test_enabled_source_titles_follow_priority_and_fallback_settings():
assert enabled_source_titles(
"Map Data", "Vision", vision_enabled=True, mapbox_enabled=False,
) == ("Map Data", "Vision", "Upcoming")
assert enabled_source_titles(
"Dashboard", "None", vision_enabled=False, mapbox_enabled=True,
) == ("Dashboard", "Mapbox")
assert enabled_source_titles(
"Highest", "None", vision_enabled=True, mapbox_enabled=True,
) == ("Dashboard", "Map Data", "Mapbox", "Upcoming")
assert enabled_source_titles(
"Dashboard", "Map Data", vision_enabled=False, mapbox_enabled=False,
dashboard_available=False,
) == ("Map Data", "Upcoming")
def test_visible_source_rows_honor_active_only_and_source_order():
source_defs = [
("Dashboard", "Dash", "dashboard", "Dashboard", "dashboard"),
("Map Data", "MapD", "map", "Map Data", "map"),
("Vision", "Vision", "vision", "Vision", "camera"),
("Mapbox", "MapB", "mapbox", "Mapbox", "map"),
("Upcoming", "Next", "next", "Next", "next"),
]
values = {"dashboard": 45.0, "map": 0.0, "vision": 50.0, "mapbox": 30.0, "next": 20.0}
# Map Data has value 0.0, so it is omitted; Dashboard (45.0) is active
assert visible_source_rows(
source_defs, values, "Dashboard", ("Dashboard", "Map Data"),
) == [
("Dashboard", "dashboard", 45.0, True),
]
# When Map Data is the active target but has 0.0 reading, Dashboard is inactive (available standby)
assert visible_source_rows(
source_defs, values, "Map Data", ("Dashboard", "Map Data"),
) == [
("Dashboard", "dashboard", 45.0, False),
]
# Multiple available sources with readings appear in canonical order
assert visible_source_rows(
source_defs, values, "Vision", ("Dashboard", "Map Data", "Vision"),
) == [
("Dashboard", "dashboard", 45.0, False),
("Vision", "camera", 50.0, True),
]
# When no sources have a valid speed reading (> 0), returns empty list (triggers empty state)
assert visible_source_rows(
source_defs, {key: 0.0 for key in values}, "Map Data", ("Map Data",),
) == []