Align uploader and torque layout test fixtures

This commit is contained in:
Dom
2026-10-23 04:39:20 -05:00
parent 7c795af543
commit e0bea55fa9
3 changed files with 22 additions and 5 deletions
@@ -6,7 +6,7 @@ from unittest.mock import patch
import numpy as np
import pyray as rl
from openpilot.starpilot.ui.onroad_customization import PROFILES, default_document, validate_document
from openpilot.starpilot.ui.onroad_customization import PROFILES, default_document, validate_document, widget_size
from openpilot.starpilot.ui.onroad_state import OnroadState, SpeedLimitObservation
from openpilot.starpilot.ui.onroad_torque import TorqueBarWidget
@@ -79,7 +79,11 @@ class TestTorqueLayout(unittest.TestCase):
for key in ('max_speed', 'driver_monitor', 'steering_wheel'):
with self.subTest(key=key):
invalid = default_document()
invalid['layouts']['compact'][key].update(x=174, y=19 if key == 'max_speed' else 130)
actions = invalid['layouts']['compact']['speed_limit_actions']
_, height = widget_size(invalid, 'compact', key)
invalid['layouts']['compact'][key].update(x=actions['x'], y=actions['y'] - height)
self.assertEqual(validate_document(invalid), invalid) # Touching edges do not overlap.
invalid['layouts']['compact'][key]['y'] += 1
with self.assertRaises(ValueError):
validate_document(invalid)
@@ -20,7 +20,7 @@ class TestUploadPreferences(unittest.TestCase):
def run_loop(self, observations, *, force_wifi=False):
main = next(node for node in ast.parse(Path(__file__).parents[1].joinpath('uploader.py').read_text()).body
if isinstance(node, ast.FunctionDef) and node.name == 'main')
state = NS(index=-1, calls=[], reads=[], cleared=False)
state = NS(index=-1, calls=[], reads=[], cleared=False, phone_checks=[])
class Saved:
def get(self, key):
@@ -47,12 +47,16 @@ class TestUploadPreferences(unittest.TestCase):
state.calls.append((network, metered))
return None
def phone_uplink_active():
state.phone_checks.append(state.index)
return observations[state.index].get('phone_uplink', False)
namespace: dict = {'threading': NS(Event=object), 'Params': Saved, 'Uploader': InertUploader,
'Paths': NS(log_root=lambda: '/unused'), 'clear_locks': lambda _: None,
'set_core_affinity': lambda _: None, 'messaging': NS(SubMaster=lambda _: Master()),
'NetworkType': Network, 'force_wifi': force_wifi, 'allow_sleep': False,
'cloudlog': NS(info=lambda *_: None, exception=lambda *_: None),
'active_provider': lambda: NS(name='comma')}
'active_provider': lambda: NS(name='comma'), 'phone_uplink_active': phone_uplink_active}
exec(compile(ast.Module(body=[main], type_ignores=[]), 'uploader.py', 'exec'), namespace)
namespace['main'](NS(is_set=lambda: state.index + 1 >= len(observations)))
return state
@@ -73,6 +77,15 @@ class TestUploadPreferences(unittest.TestCase):
state = self.run_loop([{'network': Network.none}, {'network': Network.cell, 'allow': True}], force_wifi=True)
self.assertEqual(state.calls, [(0, True), (2, False)])
def test_phone_uplink_blocks_uploads_and_refreshes_despite_overrides(self):
for force_wifi in (False, True):
for allow in (False, True):
with self.subTest(force_wifi=force_wifi, allow=allow):
state = self.run_loop([{'phone_uplink': active, 'allow': allow} for active in (False, True, False)],
force_wifi=force_wifi)
self.assertEqual(state.calls, [(2, not allow), (2, not allow)])
self.assertEqual(state.phone_checks, [0, 1, 2])
def test_typed_persistent_default_is_off(self):
keys = Path(__file__).parents[3].joinpath('common/params_keys.h').read_text()
self.assertIn('{"AlwaysAllowUploads", {PERSISTENT, BOOL, "0"}}', keys)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "f67743695765baac2e41d58bd57379accffa3e773fe4c199e16e73ecc5e7f50b", "schema_version": 1}
{"protected_inventory_sha256": "072f4638b5b9840bb8c54308d1b2883dab17baf259105a9a773ad42be02392af", "schema_version": 1}