mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 13:33:42 +08:00
a82935f326
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>
70 lines
3.3 KiB
Python
70 lines
3.3 KiB
Python
import unittest
|
|
from unittest.mock import Mock, patch
|
|
|
|
from openpilot.starpilot.ui.layout_preview_runtime import LayoutPreviewRuntime
|
|
|
|
|
|
class LayoutPreviewRuntimeTests(unittest.TestCase):
|
|
def test_start_failure_leaves_ui_available(self):
|
|
with patch("openpilot.starpilot.ui.layout_preview_runtime.LayoutPreviewRenderer") as renderer_type, \
|
|
patch("openpilot.starpilot.ui.layout_preview_runtime.PreviewService") as service_type:
|
|
service_type.return_value.start.side_effect = OSError("occupied")
|
|
authority = Mock()
|
|
runtime = LayoutPreviewRuntime(None, "large", authority=authority)
|
|
runtime.poll()
|
|
service_type.return_value.poll.assert_not_called()
|
|
service_type.return_value.close.assert_called_once()
|
|
runtime.close()
|
|
renderer_type.return_value.close.assert_called_once()
|
|
authority.close.assert_called_once()
|
|
|
|
def test_parked_loss_releases_canvas_before_transport_poll(self):
|
|
events = []
|
|
authority = Mock()
|
|
authority.parked.return_value = False
|
|
with patch("openpilot.starpilot.ui.layout_preview_runtime.LayoutPreviewRenderer") as renderer_type, \
|
|
patch("openpilot.starpilot.ui.layout_preview_runtime.PreviewService") as service_type:
|
|
renderer = renderer_type.return_value
|
|
renderer.has_resources = True
|
|
renderer.close.side_effect = lambda: events.append("release")
|
|
service_type.return_value.poll.side_effect = lambda: events.append("poll")
|
|
runtime = LayoutPreviewRuntime(None, "compact", authority=authority)
|
|
runtime.poll()
|
|
self.assertEqual(events, ["release", "poll"])
|
|
runtime.close()
|
|
|
|
def test_warmup_primes_fresh_source_then_stops_idle_reads(self):
|
|
authority = Mock()
|
|
authority.parked.side_effect = [False, True]
|
|
with patch("openpilot.starpilot.ui.layout_preview_runtime.LayoutPreviewRenderer") as renderer_type, \
|
|
patch("openpilot.starpilot.ui.layout_preview_runtime.PreviewService") as service_type, \
|
|
patch("openpilot.starpilot.ui.layout_preview_runtime.time.monotonic", side_effect=[10.0, 10.05, 10.11, 20.0]):
|
|
renderer_type.return_value.has_resources = False
|
|
runtime = LayoutPreviewRuntime(None, "large", authority=authority)
|
|
runtime.poll()
|
|
runtime.poll()
|
|
runtime.poll()
|
|
runtime.poll()
|
|
self.assertEqual(authority.parked.call_count, 2)
|
|
self.assertEqual(service_type.return_value.poll.call_count, 4)
|
|
service_type.assert_called_once_with(renderer_type.return_value, authority.parked, active_profile="large")
|
|
runtime.close()
|
|
|
|
def test_onroad_hint_defers_warmup_until_parked_then_restarts(self):
|
|
authority = Mock()
|
|
authority.parked.return_value = True
|
|
hint = Mock(side_effect=[False, True, False, True])
|
|
with patch("openpilot.starpilot.ui.layout_preview_runtime.LayoutPreviewRenderer") as renderer_type, \
|
|
patch("openpilot.starpilot.ui.layout_preview_runtime.PreviewService"), \
|
|
patch("openpilot.starpilot.ui.layout_preview_runtime.time.monotonic", side_effect=[1.0, 2.0, 3.0, 4.0]):
|
|
renderer_type.return_value.has_resources = False
|
|
runtime = LayoutPreviewRuntime(None, "compact", offroad_hint=hint, authority=authority)
|
|
for _ in range(4):
|
|
runtime.poll()
|
|
self.assertEqual(authority.parked.call_count, 2)
|
|
runtime.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|