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>
43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
import unittest
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
import pyray as rl
|
|
|
|
from openpilot.starpilot.ui.home import HomeView, validate_home_asset
|
|
|
|
|
|
class TestHomeResources(unittest.TestCase):
|
|
def test_unreviewed_or_changed_asset_is_rejected_before_native_load(self):
|
|
with TemporaryDirectory() as directory, patch("openpilot.starpilot.ui.home.rl.load_image") as load:
|
|
root = Path(directory)
|
|
with self.assertRaisesRegex(ValueError, "Unreviewed Home asset"):
|
|
validate_home_asset(root, "../../outside.png")
|
|
path = root / "icons_mici/settings.png"
|
|
path.parent.mkdir()
|
|
path.write_bytes(b"not an image")
|
|
view = object.__new__(HomeView)
|
|
view.assets, view._textures = root, {}
|
|
with self.assertRaisesRegex(ValueError, "reviewed manifest"):
|
|
view._texture("icons_mici/settings.png", 48, 48)
|
|
load.assert_not_called()
|
|
|
|
def test_failed_gpu_upload_unloads_image_without_caching_texture(self):
|
|
view = object.__new__(HomeView)
|
|
view.assets, view._textures, view._pixel_scale = Path("unused"), {}, (1.0, 1.0)
|
|
image = SimpleNamespace(data=rl.ffi.new("char[4]"), width=1, height=1)
|
|
with patch("openpilot.starpilot.ui.home.validate_home_asset", return_value=Path("unused")), \
|
|
patch("openpilot.starpilot.ui.home.rl.load_image", return_value=image), \
|
|
patch("openpilot.starpilot.ui.home.rl.load_texture_from_image", return_value=SimpleNamespace(id=0)), \
|
|
patch("openpilot.starpilot.ui.home.rl.unload_image") as unload:
|
|
with self.assertRaisesRegex(RuntimeError, "Unable to load Home texture"):
|
|
view._texture("unused", 1, 1)
|
|
unload.assert_called_once_with(image)
|
|
self.assertEqual(view._textures, {})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|