Files
StarPilot/openpilot/starpilot/galaxy/tests/test_widget_art_header.py
T
dirwin31 3edf46a991 UI: curve-speed glow, gas-override blink and Theme maker preview
- Steady the curve-speed glow and the gas-override blink on the on-road screen
- Stop the Theme maker preview flapping to "unavailable" and allow for Galaxy tunnel latency
- Carry the widget sprite sheet in a header so it survives the tunnel
2026-11-04 08:07:17 -08:00

30 lines
1023 B
Python

import base64
import json
import struct
import unittest
import zlib
from openpilot.starpilot.galaxy.batch_routes import widget_art_header
def chunk(kind, body):
return struct.pack('!I', len(body)) + kind + body + struct.pack('!I', zlib.crc32(kind + body))
class WidgetArtHeaderTest(unittest.TestCase):
def png(self, text):
return b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('!IIBBBBB', 1, 1, 8, 6, 0, 0, 0)) + text + chunk(b'IEND', b'')
def test_sheet_is_copied_into_header(self):
meta = {'version': 1, 'width': 1, 'height': 1, 'sprites': {}}
image = self.png(chunk(b'tEXt', b'starpilot-widget-art\0' + json.dumps(meta).encode()))
self.assertEqual(json.loads(base64.b64decode(widget_art_header(image))), meta)
def test_missing_or_oversized_sheet_gives_no_header(self):
self.assertEqual(widget_art_header(self.png(b'')), '')
self.assertEqual(widget_art_header(self.png(chunk(b'tEXt', b'starpilot-widget-art\0' + b'x' * 9000))), '')
if __name__ == '__main__':
unittest.main()