Files
mangavalkandClaude Opus 5.5 6616b47cb4 Readable value names for all Intelligent types; TextSelect lines follow dis
Value lists read from the Editor's attribute notes with an Intelligent model: drag, load effect
(page has two more), transparency background, switch direction, ComboBox arrow/expansion,
TextSelect lines, scroll bars, DataRecord options, media source/state/looping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 00:34:11 +01:00

57 lines
2.8 KiB
Python

import unittest
import helpers # noqa: F401
from nxhmi import enums
class Enums(unittest.TestCase):
def test_colours_exact_roundtrip(self):
for v in range(0, 0x10000, 37):
self.assertEqual(enums.hex_to_rgb565(enums.rgb565_to_hex(v)), v)
self.assertEqual(enums.rgb565_to_hex(0xF800), "#ff0000")
def test_general_and_per_type(self):
self.assertEqual(enums.to_label(116, "xcen", "u8", 2), "right")
self.assertEqual(enums.to_label(52, "sta", "u8", 1), "string") # variable type
self.assertEqual(enums.to_label(121, "sta", "u8", 0), "no background")
self.assertEqual(enums.to_label(58, "sta", "u8", 1), "has") # QR logo
self.assertEqual(enums.to_label(98, "style", "u8", 4), "3D_Auto")
self.assertEqual(enums.to_label(116, "style", "u8", 4), 4) # not a text style
def test_from_label(self):
self.assertEqual(enums.from_label(116, "xcen", "u8", "Center"), 1)
self.assertEqual(enums.from_label(116, "bco", "u16", "#ffffff"), 0xFFFF)
self.assertEqual(enums.from_label(116, "x", "u16", 7), 7)
self.assertEqual(enums.from_label(116, "x", "u16", "0x10"), 16)
with self.assertRaises(ValueError):
enums.from_label(116, "xcen", "u8", "sideways")
def test_intelligent_types(self):
# value lists from the Editor's attribute notes (Intelligent model)
self.assertEqual(enums.to_label(67, "dez", "u8", 1), "vertical") # switch
self.assertEqual(enums.to_label(61, "dir", "u8", 1), "down") # combobox
self.assertEqual(enums.to_label(68, "sta", "u8", 3), "transparency") # text select
self.assertEqual(enums.to_label(66, "order", "u8", 0), "new data before") # data record
self.assertEqual(enums.to_label(3, "en", "u8", 2), "pause") # video
self.assertEqual(enums.to_label(121, "effect", "u8", 10), "middle zoom in") # page only
self.assertEqual(enums.to_label(116, "effect", "u8", 10), 10)
self.assertEqual(enums.from_label(65, "psta", "u8", "yes"), 1) # file browser
def test_every_type_has_names(self):
import json, os
from nxhmi import components
here = os.path.dirname(components.__file__)
types = json.load(open(os.path.join(here, "templates_intelligent.json"), encoding="utf-8"))["types"]
for t, spec in types.items():
names = {a[0] for a in spec["att"]}
labelled = [a for a in names if enums.table(int(t), a)]
self.assertTrue(labelled, spec["kind"]) # vscope at least
def test_strings_untouched(self):
self.assertEqual(enums.to_label(116, "txt", "str", "#abc"), "#abc")
if __name__ == "__main__":
unittest.main()