mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 06:53:40 +08:00
Complete offline vehicle and evidence fixtures for current snapshots
Test-only fixture repair: real isolated Params and schema CarParams retain specified values, unavailable learning payloads retain missing freshness, and stock ExperimentalMode tests explicitly select STOCK. All assertions retained.340 related tests pass on reconciled814b795; baseline30fail/30pass. Ruff/ty pass. No production/native or receipt changes.
This commit is contained in:
@@ -141,7 +141,8 @@ class SharedDeviceStateTest(unittest.TestCase):
|
||||
# The shared collector includes the other physical-admission services;
|
||||
# this display adapter consumes only deviceState and pandaStates.
|
||||
self.messages.values.update(carState=SimpleNamespace(), selfdriveState=SimpleNamespace(), carParams=SimpleNamespace(),
|
||||
peripheralState=SimpleNamespace(pandaType=1, voltage=12640))
|
||||
peripheralState=SimpleNamespace(pandaType=1, voltage=12640),
|
||||
lateralDelay=SimpleNamespace(), lateralTorqueParameters=SimpleNamespace(), vehicleParameters=SimpleNamespace())
|
||||
self.shared = EvidenceSource(self.messages, mono=self.clock.mono, boot=self.clock.boot)
|
||||
self.addCleanup(self.shared.close)
|
||||
|
||||
@@ -149,7 +150,8 @@ class SharedDeviceStateTest(unittest.TestCase):
|
||||
self.clock.now += 100_000_000
|
||||
self.messages.publish(self.clock, **state)
|
||||
self.messages.values.update(carState=SimpleNamespace(), selfdriveState=SimpleNamespace(), carParams=SimpleNamespace(),
|
||||
peripheralState=SimpleNamespace(pandaType=1, voltage=12640))
|
||||
peripheralState=SimpleNamespace(pandaType=1, voltage=12640),
|
||||
lateralDelay=SimpleNamespace(), lateralTorqueParameters=SimpleNamespace(), vehicleParameters=SimpleNamespace())
|
||||
self.messages.alive = dict(self.messages.seen)
|
||||
self.shared.poll()
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from unittest.mock import Mock, patch
|
||||
|
||||
from openpilot.starpilot.ui.raylib import rl
|
||||
|
||||
from opendbc.car.structs import CarParams
|
||||
from openpilot.cereal import messaging
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.starpilot.conditional_mode.consumer import ConsumerResult
|
||||
@@ -98,7 +99,7 @@ class TestConditionalStatus(unittest.TestCase):
|
||||
for service in ui.sm.logMonoTime:
|
||||
ui.sm.logMonoTime[service] = NOW
|
||||
ui.params = params
|
||||
ui.CP = type('CP', (), {'openpilotLongitudinalControl': True, 'passive': False, 'pcmCruise': True, 'carFingerprint': 'OTHER'})()
|
||||
ui.CP = CarParams.new_message(openpilotLongitudinalControl=True, passive=False, pcmCruise=True, carFingerprint='OTHER')
|
||||
ui.sm['deviceState'].startedMonoTime = DRIVE
|
||||
ui.sm['carState'].canValid = True
|
||||
ui.sm['carState'].canTimeout = False
|
||||
|
||||
@@ -121,7 +121,7 @@ class TestGlobalFeaturePresentation(unittest.TestCase):
|
||||
with self.subTest(candidate=candidate):
|
||||
cp = params_for(candidate)
|
||||
ui = ui_fake()
|
||||
ui.CP = cp
|
||||
ui.CP, ui.params = cp, self.params
|
||||
ui.sm['deviceState'].startedMonoTime = DRIVE
|
||||
ui.sm['carState'].canValid, ui.sm['carState'].canTimeout = True, False
|
||||
event = messaging.new_message('slcState', valid=True, logMonoTime=NOW)
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
|
||||
from dataclasses import replace
|
||||
from datetime import datetime
|
||||
import json
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from types import SimpleNamespace as NS
|
||||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from openpilot.starpilot.ui.raylib import rl
|
||||
|
||||
from openpilot.starpilot.conditional_mode.policy import ModeChoice
|
||||
from openpilot.starpilot.conditional_mode.preferences import SavedPreferences, encode_preferences
|
||||
from openpilot.starpilot.ui import onroad
|
||||
from openpilot.starpilot.ui.onroad import axis_status_color, clock_text, driving_mode_description
|
||||
from openpilot.starpilot.ui.onroad_customization import MODE_WIDGET
|
||||
@@ -20,7 +24,7 @@ from openpilot.starpilot.ui.presentation import Profile
|
||||
from openpilot.starpilot.ui.preview_shell import reference_onroad
|
||||
from openpilot.starpilot.ui.runtime_snapshot import RuntimeSnapshotAdapter
|
||||
from openpilot.starpilot.ui.shell import ShellMode
|
||||
from openpilot.starpilot.ui.tests.test_runtime_snapshot import NOW, ui_fake
|
||||
from openpilot.starpilot.ui.tests.test_runtime_snapshot import NOW, vehicle_ui
|
||||
from openpilot.starpilot.ui.tests.test_onroad_torque_draw import record_gpu
|
||||
|
||||
|
||||
@@ -34,8 +38,8 @@ class TestOnroadAxes(unittest.TestCase):
|
||||
self.enterContext(patch('openpilot.starpilot.ui.speed_limit_widget.rl.' + name, new_callable=Mock))
|
||||
for name in ('circle', 'arrow', 'outline', 'button'):
|
||||
self.enterContext(patch('openpilot.starpilot.ui.speed_limit_shapes.SpeedLimitShapes.' + name, new_callable=Mock))
|
||||
self.ui = ui_fake()
|
||||
self.ui.CP = NS(carFingerprint='', openpilotLongitudinalControl=True, pcmCruise=False)
|
||||
self.ui = vehicle_ui(self.enterContext(TemporaryDirectory()),
|
||||
carFingerprint='', openpilotLongitudinalControl=True, pcmCruise=False)
|
||||
car = self.ui.sm["carState"]
|
||||
car.canValid = True
|
||||
car.canTimeout = False
|
||||
@@ -277,7 +281,6 @@ class TestOnroadAxes(unittest.TestCase):
|
||||
self.assertTrue(self.state(True, False).longitudinal_overridden)
|
||||
|
||||
def test_traffic_returns_after_conditional_stop_without_changing_intent(self):
|
||||
from openpilot.starpilot.conditional_mode.policy import ModeChoice
|
||||
from openpilot.starpilot.ui.conditional_status import ConditionalDisplay
|
||||
|
||||
traffic = replace(self.state(True, True), traffic_mode=True)
|
||||
@@ -291,6 +294,8 @@ class TestOnroadAxes(unittest.TestCase):
|
||||
self.assertEqual(rgba(axis_status_color(replace(stopping, longitudinal_overridden=True))), (145, 155, 149, 255))
|
||||
|
||||
def test_experimental_border_requires_active_combined_axes(self):
|
||||
# These manual ExperimentalMode projections use the explicitly selected stock family.
|
||||
self.ui.params.put('ConditionalModeConfig', json.loads(encode_preferences(SavedPreferences(mode=ModeChoice.STOCK))), block=True)
|
||||
combined = replace(self.state(True, True), experimental_enabled=True)
|
||||
self.assertEqual(rgba(axis_status_color(combined)), (218, 111, 37, 255))
|
||||
self.assertEqual(rgba(axis_status_color(replace(combined, longitudinal_active=False))), (10, 186, 181, 255))
|
||||
@@ -364,7 +369,8 @@ class TestOnroadAxes(unittest.TestCase):
|
||||
self.assertIn(driving_mode_description(state), [call.args[0] for call in view.fonts.draw.call_args_list])
|
||||
|
||||
def test_driving_mode_text_uses_active_axes_and_effective_mode(self):
|
||||
from openpilot.starpilot.conditional_mode.policy import ModeChoice
|
||||
# These manual ExperimentalMode projections use the explicitly selected stock family.
|
||||
self.ui.params.put('ConditionalModeConfig', json.loads(encode_preferences(SavedPreferences(mode=ModeChoice.STOCK))), block=True)
|
||||
from openpilot.starpilot.ui.conditional_status import ConditionalDisplay
|
||||
|
||||
base = self.state(True, True)
|
||||
@@ -405,7 +411,8 @@ class TestOnroadAxes(unittest.TestCase):
|
||||
view.fonts.draw.assert_not_called()
|
||||
|
||||
def test_stock_cruise_is_distinct_from_system_long_and_lateral(self):
|
||||
self.ui.CP = NS(carFingerprint='', openpilotLongitudinalControl=False, pcmCruise=True)
|
||||
self.ui.CP.openpilotLongitudinalControl = False
|
||||
self.ui.CP.pcmCruise = True
|
||||
self.ui.sm["carState"].cruiseState.enabled = True
|
||||
state = self.state(False, False)
|
||||
self.assertTrue(state.stock_cruise_active)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from dataclasses import replace
|
||||
from types import SimpleNamespace as NS
|
||||
from tempfile import TemporaryDirectory
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -12,7 +12,7 @@ from openpilot.starpilot.ui.runtime_snapshot import RuntimeSnapshotAdapter
|
||||
from openpilot.starpilot.ui.runtime_app import visual_border_state
|
||||
from openpilot.starpilot.ui.pip_sidecam import Signals
|
||||
from openpilot.starpilot.ui.shell import ShellMode
|
||||
from openpilot.starpilot.ui.tests.test_runtime_snapshot import NOW, ui_fake
|
||||
from openpilot.starpilot.ui.tests.test_runtime_snapshot import NOW, vehicle_ui
|
||||
|
||||
|
||||
def state(signals: BorderSignals | None, *, signal_enabled: bool = True, blindspot_enabled: bool = True):
|
||||
@@ -73,8 +73,8 @@ class TestOnroadBorder(unittest.TestCase):
|
||||
draw.assert_not_called()
|
||||
|
||||
def test_stale_or_invalid_car_clears_visual_signal(self):
|
||||
ui = ui_fake()
|
||||
ui.CP = NS(openpilotLongitudinalControl=True, carFingerprint="OTHER", pcmCruise=False)
|
||||
ui = vehicle_ui(self.enterContext(TemporaryDirectory()),
|
||||
openpilotLongitudinalControl=True, carFingerprint="OTHER", pcmCruise=False)
|
||||
car = ui.sm['carState']
|
||||
car.canValid = True
|
||||
car.canTimeout = False
|
||||
|
||||
@@ -8,6 +8,7 @@ from unittest import mock
|
||||
|
||||
from openpilot.starpilot.ui.raylib import rl
|
||||
|
||||
from opendbc.car.structs import CarParams
|
||||
from opendbc.car.car_helpers import interfaces
|
||||
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
||||
from openpilot.cereal import messaging
|
||||
@@ -66,7 +67,8 @@ class TestTrafficStatus(unittest.TestCase):
|
||||
|
||||
def test_no_traffic_wire_remains_absent_with_independent_vehicle_checks(self):
|
||||
ui = ui_fake()
|
||||
ui.CP = NS(carFingerprint="", openpilotLongitudinalControl=True, pcmCruise=False)
|
||||
ui.params = self.params
|
||||
ui.CP = CarParams.new_message(carFingerprint="", openpilotLongitudinalControl=True, pcmCruise=False)
|
||||
state = RuntimeSnapshotAdapter(ui).build(ShellMode.ONROAD, now_ns=NOW).onroad
|
||||
self.assertIsNone(state.traffic_display)
|
||||
self.assertFalse(state.traffic_mode)
|
||||
|
||||
Reference in New Issue
Block a user