Files
StarPilot/openpilot/starpilot/ui/tests/test_planner_selection_settings.py
T
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

74 lines
3.2 KiB
Python

"""Fleet-wide saved planner preference independent of longitudinal capability."""
from pathlib import Path
import tempfile
import unittest
from openpilot.common.params import Params
from openpilot.starpilot.longitudinal.planner_selection import KEY, read_selection
from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner
from openpilot.starpilot.ui.feature_settings_state import FeatureSettingsRequest
class TestPlannerSelectionSettings(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory()
self.addCleanup(temporary.cleanup)
registered = Params(temporary.name)
root = Path(registered.get_param_path('CustomPersonalities')).parent
class Files:
def get_param_path(self, key):
return str(root / key)
def get_default_value(self, key):
return True if key == KEY else registered.get_default_value(key)
self.params = Files()
self.parked = True
self.preferences = True
self.groups = []
def authority(group):
self.groups.append(group)
return self.preferences if group == 'preferences' else self.parked if group == 'parked_preferences' else False
self.owner = FeatureSettingsOwner(self.params, authority, vehicle_fingerprint=lambda: None)
def row(self, *, system_long=False):
state = self.owner.snapshot('profiles', parked=self.parked, system_long=system_long,
lateral_context=False, metric=False)
return next(row for row in state.rows if row.key == KEY)
def test_default_row_available_without_vehicle_or_long_enable(self):
row = self.row()
self.assertEqual(row.label, 'Use StarPilot Longitudinal Planner')
self.assertEqual(row.value, 'On')
self.assertTrue(row.available)
self.assertIsNone(row.vehicle_fingerprint)
self.assertIn('next drive', row.reason)
self.assertIn('upstream', row.reason)
self.assertTrue(self.row(system_long=True).available)
def test_saved_switch_uses_preferences_authority_and_exact_source_only(self):
row = self.row()
request = FeatureSettingsRequest(KEY, row.source, 'Off')
self.assertTrue(self.owner.apply(request))
self.assertEqual(Path(self.params.get_param_path(KEY)).read_bytes(), b'0')
self.assertEqual(self.groups[-1], 'preferences')
self.assertFalse(self.owner.apply(request))
self.assertFalse(Path(self.params.get_param_path('ExperimentalLongitudinalEnabled')).exists())
self.preferences = False
self.assertFalse(self.row().available)
self.assertFalse(self.owner.apply(FeatureSettingsRequest(KEY, b'0', 'On')))
self.assertEqual(Path(self.params.get_param_path(KEY)).read_bytes(), b'0')
def test_onroad_save_changes_persistent_choice_without_replacing_active_selection(self):
self.parked = False
active = read_selection(self.params)
self.assertTrue(active.starpilot)
row = self.row()
self.assertTrue(row.available)
self.assertTrue(self.owner.apply(FeatureSettingsRequest(KEY, row.source, 'Off')))
self.assertTrue(active.starpilot)
self.assertFalse(read_selection(self.params).starpilot)
self.assertFalse(Path(self.params.get_param_path('ExperimentalLongitudinalEnabled')).exists())
if __name__ == '__main__':
unittest.main()