Files
StarPilot/openpilot/starpilot/tests/test_vehicle_cache_contract.py
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

53 lines
2.0 KiB
Python

import unittest
from dataclasses import replace
from unittest.mock import patch
from openpilot.cereal import log
from opendbc.car import structs
from openpilot.starpilot import schema_cache
class MemoryParams:
def __init__(self):
self.values = {}
def get(self, key):
return self.values.get(key)
def put(self, key, value, block=False):
self.values[key] = value
class TestVehicleCacheContract(unittest.TestCase):
def test_previous_vehicle_flags_require_fresh_identification(self):
for key in ('CarParamsCache', 'CarParamsPersistent', 'CarParamsPrevRoute'):
with self.subTest(key=key):
params = MemoryParams()
cp = structs.CarParams(carFingerprint='CHRYSLER_PACIFICA_2020', flags=2)
current = schema_cache.CONTRACTS[key]
previous = replace(current, producer='identified-car-params-v1')
with patch.dict(schema_cache.CONTRACTS, {key: previous}):
schema_cache.put_cache(params, key, cp, block=True)
self.assertIsNotNone(schema_cache.get_cache(params, key))
original = params.values.copy()
self.assertIsNone(schema_cache.get_cache(params, key))
self.assertEqual(schema_cache.inspect_cache(key, params.get(key)).status, 'incompatible')
self.assertEqual(params.values, original)
schema_cache.put_cache(params, key, cp, block=True)
self.assertIsNotNone(schema_cache.get_cache(params, key))
def test_vehicle_epoch_does_not_invalidate_calibration_or_learned_values(self):
params = MemoryParams()
params.put('CustomPreference', b'user-choice')
for key, contract in schema_cache.CONTRACTS.items():
if contract.service is None:
continue
event = log.Event.new_message()
event.init(contract.service)
schema_cache.put_cache(params, key, event, block=True)
original = params.values.copy()
for key, contract in schema_cache.CONTRACTS.items():
if contract.service is not None:
self.assertIsNotNone(schema_cache.get_cache(params, key), key)
self.assertEqual(params.values, original)