From 8e8d0f2d8e62709ba47edce246f515be8073379f Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sat, 28 Nov 2026 16:00:44 -0600 Subject: [PATCH] Share Typed AOL and Galaxy Test Fixtures --- .../tests/test_feedback_intent_boundary.py | 5 +---- .../aol/tests/test_ioniq_availability.py | 20 +++++++++++++++---- .../aol/tests/test_lkas_retention_recovery.py | 5 +---- openpilot/starpilot/aol/tests/test_runtime.py | 17 ++++++++-------- .../aol/tests/test_steering_companion.py | 7 +++---- .../tests/test_defaults_recovery_http.py | 12 +++-------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/openpilot/starpilot/aol/tests/test_feedback_intent_boundary.py b/openpilot/starpilot/aol/tests/test_feedback_intent_boundary.py index 1a7940bf90..398a2d2adf 100644 --- a/openpilot/starpilot/aol/tests/test_feedback_intent_boundary.py +++ b/openpilot/starpilot/aol/tests/test_feedback_intent_boundary.py @@ -1,4 +1,3 @@ -import unittest from unittest import mock from openpilot.cereal import log, messaging @@ -9,9 +8,7 @@ from openpilot.starpilot.aol.tests import test_ioniq_availability as availabilit from openpilot.starpilot.car.gm.aol import intent_disarming_fault -class TestFeedbackIntentBoundary(unittest.TestCase): - _authority_callers = availability.IoniqAvailabilityTests._authority_callers - _ioniq_availability_callers = availability.IoniqAvailabilityTests._ioniq_availability_callers +class TestFeedbackIntentBoundary(availability.IoniqAuthorityFixture): def accepted_long_output(self): sd, controls, step, card, receive = self._ioniq_availability_callers() diff --git a/openpilot/starpilot/aol/tests/test_ioniq_availability.py b/openpilot/starpilot/aol/tests/test_ioniq_availability.py index 42109321bf..4704d8c3f1 100644 --- a/openpilot/starpilot/aol/tests/test_ioniq_availability.py +++ b/openpilot/starpilot/aol/tests/test_ioniq_availability.py @@ -51,7 +51,7 @@ def assert_fresh_ordinary_recovery(sd, axis, command, source): assert not sd.aol_authority_lost and not getattr(sd, 'aol_availability_long_inhibit', False) -class IoniqAvailabilityTests(unittest.TestCase): +class IoniqAuthorityFixture(unittest.TestCase): def _authority_callers(self, full_op, *, cp=None, intent_companion=None, genuine_events=False, initial_panda_config=None): self.enterContext(mock.patch('openpilot.selfdrive.selfdrived.selfdrived.REPLAY', False)) from opendbc.car.gm.tests.test_bolt_volt_configurations import ordinary_params @@ -115,7 +115,8 @@ class IoniqAvailabilityTests(unittest.TestCase): steering_receipts = [] def optional_receive(sock): - if getattr(sd, 'steering_companion', None) is not None and sock is sd.steering_companion.sock: + companion = getattr(sd, 'steering_companion', None) + if companion is not None and sock is companion.sock: return steering_receipts.pop(0) if steering_receipts else None return None if sock is sd.car_state_sock else original_optional_receive(sock) @@ -268,6 +269,7 @@ class IoniqAvailabilityTests(unittest.TestCase): intent_ns + 200_000_000, latched, pause, pause_long, True, latched)) if intent_message is not None: intent = intent_message + assert cp is not None native = messaging.new_message('aolSafetyWire', 0, valid=native_valid, logMonoTime=now) native.aolSafetyWire = encode_safety(SafetyState(1, True, now, now + 200_000_000, int(cp.safetyConfigs[-1].safetyModel.raw), cp.safetyConfigs[-1].safetyParam, @@ -362,20 +364,25 @@ class IoniqAvailabilityTests(unittest.TestCase): elif not supplied_profile: _, cp = candidate(True) cp.safetyConfigs[-1].safetyParam |= 0x0800 + assert cp is not None sd, controls, step = self._authority_callers(full_op, cp=cp, genuine_events=True) card_cp = cp.as_reader().as_builder() if startup_owner is None else startup_owner.owner.cp card = Car(CI=CarInterface(card_cp), RI=RadarInterface(card_cp), startup_owner=startup_owner) self.assertEqual(card.CP.to_dict(), sd.CP.to_dict()) self.assertEqual(card.CP.safetyConfigs[-1].safetyParam, cp.safetyConfigs[-1].safetyParam if stock_angle or supplied_profile else 0x8895) + assert card.aol_card_intent is not None self.assertTrue(card.aol_card_intent.explicit_latch) card.slc_producer_session = 'authority-card' cs = car_state() cs.cruiseState.available = True + assert card.aol_card_intent is not None card.aol_card_intent.update(cs, now_ns=9_980_000_000) if initially_armed: cs.buttonEvents = [car.CarState.ButtonEvent(type=car.CarState.ButtonEvent.Type.lkas, pressed=True)] + assert card.aol_card_intent is not None card.aol_card_intent.update(cs, now_ns=9_990_000_000) cs.buttonEvents = [] + assert card.aol_card_intent is not None self.assertEqual(card.aol_card_intent.allowed_latch, initially_armed) def receive(now, *, axis=None, event=None, state=None, preserve_cruise_state=False, can_packets=()): @@ -403,9 +410,11 @@ class IoniqAvailabilityTests(unittest.TestCase): mock.patch.object(card.RI, 'update', return_value=None), mock.patch.object(card.sm, 'update'): actual, _ = card.state_update() self.assertIs(actual, observed) + assert card.aol_card_intent is not None return card.aol_card_intent.allowed_latch def drive(tick, **kwargs): + assert card.aol_card_intent is not None kwargs.setdefault('latched', card.aol_card_intent.allowed_latch) if stock_angle and 'observed_state' not in kwargs: state = car_state(brake=kwargs.get('brake', False)) @@ -424,6 +433,9 @@ class IoniqAvailabilityTests(unittest.TestCase): axis=sd.pm.messages['aolAxisState'], event=sd.pm.messages['onroadEvents']), initially_armed) return sd, controls, drive, card, receive + + +class IoniqAvailabilityTests(IoniqAuthorityFixture): def test_full_set_engagement_arms_aol_and_brake_keeps_lateral_without_lkas(self): from opendbc.car.hyundai.values import Buttons @@ -590,7 +602,7 @@ class IoniqAvailabilityTests(unittest.TestCase): combined, _, command = step(316, native_request_long=True) native = current_native(sd.sm, sd.CP, now_ns=13_160_000_000, axis_session_id=sd.aol_session_id) - self.assertIsNotNone(native) + assert native is not None self.assertTrue(native.requestedLongitudinal and native.longitudinalAllowed) self.assertEqual(native.observedMonoTime, 13_160_000_000) self.assertTrue(combined.lateralActive and combined.longitudinalActive and command.latActive and command.longActive) @@ -715,7 +727,7 @@ class IoniqAvailabilityTests(unittest.TestCase): self.assertFalse(axis.lateralActive or axis.longitudinalActive or command.latActive or command.longActive) if fault == 'native_denied': native = current_native(sd.sm, sd.CP, now_ns=10_030_000_000, axis_session_id=sd.aol_session_id) - self.assertIsNotNone(native) + assert native is not None self.assertTrue(native.requestedLateral) self.assertFalse(native.lateralAllowed) self.assertEqual(str(axis.faultReason), 'availabilityPause') diff --git a/openpilot/starpilot/aol/tests/test_lkas_retention_recovery.py b/openpilot/starpilot/aol/tests/test_lkas_retention_recovery.py index e33ee2bb42..9a9fa8c6d0 100644 --- a/openpilot/starpilot/aol/tests/test_lkas_retention_recovery.py +++ b/openpilot/starpilot/aol/tests/test_lkas_retention_recovery.py @@ -4,7 +4,6 @@ Factory CI/RI, actual SD/Controls and v2 native inventory use the existing controlled IPC fixture. CAN parsing and receive transport are synthetic; feedback validation and physical-button intent processing are unpatched. """ -import unittest from unittest import mock from openpilot.cereal import log, messaging @@ -13,9 +12,7 @@ from opendbc.car.structs import car from openpilot.starpilot.aol.tests import test_ioniq_availability as helpers -class LkasRetentionRecoveryTests(unittest.TestCase): - _authority_callers = helpers.IoniqAvailabilityTests._authority_callers - _ioniq_availability_callers = helpers.IoniqAvailabilityTests._ioniq_availability_callers +class LkasRetentionRecoveryTests(helpers.IoniqAuthorityFixture): def _terminal_episode(self): sd, controls, step, card, receive = self._ioniq_availability_callers() diff --git a/openpilot/starpilot/aol/tests/test_runtime.py b/openpilot/starpilot/aol/tests/test_runtime.py index d34dcf2b02..7cb1898cb0 100644 --- a/openpilot/starpilot/aol/tests/test_runtime.py +++ b/openpilot/starpilot/aol/tests/test_runtime.py @@ -672,10 +672,8 @@ class CardIntentTests(unittest.TestCase): (held_ticks != CRUISE_LONG_PRESS, held_ticks == CRUISE_LONG_PRESS)) -class IpcAxisContractTests(unittest.TestCase): - _authority_callers = availability_fixture.IoniqAvailabilityTests._authority_callers +class IpcAxisContractTests(availability_fixture.IoniqAuthorityFixture): - _ioniq_availability_callers = availability_fixture.IoniqAvailabilityTests._ioniq_availability_callers def test_fresh_ioniq_input_gets_full_publication_lease(self): from openpilot.starpilot.aol.runtime import current_axis @@ -776,7 +774,7 @@ class IpcAxisContractTests(unittest.TestCase): 0x1BA: 24, 0x1E5: 16, 0x36A: 16}) stock = CarInterface.get_params(CAR.HYUNDAI_IONIQ_6, fp, [], False, False, False) cp = build_ioniq6_hda2_long_candidate(stock, fp) - self.assertIsNotNone(cp) + assert cp is not None # Mirror Card's saved-AOL marker before publishing the LONG candidate. cp.safetyConfigs[-1].safetyParam |= 0x0800 pm = messaging.PubMaster(['aolIntentWire']) @@ -860,6 +858,7 @@ class IpcAxisContractTests(unittest.TestCase): card.sm.update_msgs(now / 1e9, frames) fault = card.aol_disarming_fault(cs if state is None else state, int(card.sm.logMonoTime['onroadEvents']), now) + assert card.aol_card_intent is not None card.aol_card_intent.update(cs if state is None else state, fault_active=fault, now_ns=now, standard_enabled=sd.enabled) return fault @@ -1686,13 +1685,15 @@ class IpcAxisContractTests(unittest.TestCase): sm.alive = dict(sm.valid) sm.logMonoTime, sm.recv_time = {'pandaStates': 0}, {'pandaStates': 0.0} + bootstrap_sm = sm + def refresh(): # IPC receipt follows production by 1us; float seconds need not round-trip ns. - sm.logMonoTime.update(carControl=now[0] - 1_000, deviceState=now[0] - 1_000) - sm.recv_time.update(carControl=now[0] / 1e9, deviceState=now[0] / 1e9) + bootstrap_sm.logMonoTime.update(carControl=now[0] - 1_000, deviceState=now[0] - 1_000) + bootstrap_sm.recv_time.update(carControl=now[0] / 1e9, deviceState=now[0] / 1e9) for service in ('carControl', 'deviceState'): - self.assertLessEqual(sm.logMonoTime[service], int(sm.recv_time[service] * 1e9)) - self.assertLessEqual(int(sm.recv_time[service] * 1e9), now[0]) + self.assertLessEqual(bootstrap_sm.logMonoTime[service], int(bootstrap_sm.recv_time[service] * 1e9)) + self.assertLessEqual(int(bootstrap_sm.recv_time[service] * 1e9), now[0]) def parse_state(selected): stamp = now[0] + offset diff --git a/openpilot/starpilot/aol/tests/test_steering_companion.py b/openpilot/starpilot/aol/tests/test_steering_companion.py index 554a2702a1..6f0c70ec1a 100644 --- a/openpilot/starpilot/aol/tests/test_steering_companion.py +++ b/openpilot/starpilot/aol/tests/test_steering_companion.py @@ -1,5 +1,4 @@ import time -import unittest from unittest import mock from openpilot.cereal import log, messaging @@ -12,8 +11,7 @@ from openpilot.starpilot.car.gm.steering_companion import MAX_COMPANIONS, MAX_DR from opendbc.car.structs import car -class SteeringCompanionContractTests(unittest.TestCase): - _authority_callers = runtime_fixture.IpcAxisContractTests._authority_callers +class SteeringCompanionContractTests(runtime_fixture.availability_fixture.IoniqAuthorityFixture): def test_card_socket_first_seen_companion_overrun_reaches_controls(self): from openpilot.selfdrive.car.card import Car @@ -68,6 +66,7 @@ class SteeringCompanionContractTests(unittest.TestCase): pm=pm, consumer_clock=consumer_clock): publish(source_ns, fault=case == 'old_fault', enabled=case != 'missing_exact') first_seen = real_recv(sock) + assert first_seen is not None self.assertEqual(first_seen.logMonoTime, source_ns) publish(now_ns + 1 if case == 'future_latest' else later_ns, fault=case in ('new_fault', 'sm_fault_before_raw'), valid=case != 'invalid_latest') @@ -81,7 +80,7 @@ class SteeringCompanionContractTests(unittest.TestCase): def update_latest(_timeout, *, latest_sock=latest_sock, source_ns=source_ns, sd=sd, now_ns=now_ns): latest = real_recv(latest_sock) - self.assertIsNotNone(latest) + assert latest is not None self.assertGreater(latest.logMonoTime, source_ns) sd.sm.update_msgs(now_ns / 1e9, [latest]) diff --git a/openpilot/starpilot/galaxy/tests/test_defaults_recovery_http.py b/openpilot/starpilot/galaxy/tests/test_defaults_recovery_http.py index d97ed756f7..5f5c70590a 100644 --- a/openpilot/starpilot/galaxy/tests/test_defaults_recovery_http.py +++ b/openpilot/starpilot/galaxy/tests/test_defaults_recovery_http.py @@ -1,13 +1,11 @@ -from typing import cast from dataclasses import replace -from unittest import TestCase -from openpilot.starpilot.galaxy.tests import test_settings as fixtures +from openpilot.starpilot.galaxy.tests.settings_http_fixture import SettingsHttpFixture -class TestRecoveryHttp(TestCase): +class TestRecoveryHttp(SettingsHttpFixture): def setUp(self): - fixtures.SettingsHttpTest.setUp(cast(fixtures.SettingsHttpTest, self)) + super().setUp() from opendbc.car.car_helpers import interfaces from opendbc.car.toyota.values import CAR cp = interfaces[CAR.TOYOTA_COROLLA_TSS2].get_non_essential_params(CAR.TOYOTA_COROLLA_TSS2) @@ -15,10 +13,6 @@ class TestRecoveryHttp(TestCase): cp.pcmCruise = False self.context.value = replace(self.context.value, cp=cp) - stop = fixtures.SettingsHttpTest.stop - request = fixtures.SettingsHttpTest.request - login = fixtures.SettingsHttpTest.login - def selection(self, cookie, labels): status, value, _ = self.request('/api/settings/non-defaults', cookie=cookie) self.assertEqual(status, 200)