Black-box reverse-engineered .HMI format (container, three checksums, pages, all 31 component types, pictures, fonts), readable JSON, page renderer matching Nextion Editor, demo project built from code and a test suite (66 tests). See docs/COVERAGE.md for status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
import unittest
|
|
|
|
import helpers # noqa: F401
|
|
|
|
from nxhmi import components as C
|
|
from nxhmi.page import Page
|
|
|
|
|
|
class Templates(unittest.TestCase):
|
|
def test_all_31_types(self):
|
|
self.assertEqual(len(C.TYPES), 31)
|
|
self.assertEqual(len(C.INTELLIGENT_ONLY), 11)
|
|
for t, tpl in C.TYPES.items():
|
|
names = [a[0] for a in tpl["att"]]
|
|
self.assertEqual(names[:3], ["type", "id", "objname"], tpl["kind"])
|
|
self.assertEqual(dict((a[0], a[2]) for a in tpl["att"])["type"], t)
|
|
|
|
def test_templates_have_no_project_specific_names(self):
|
|
self.assertEqual(dict((a[0], a[2]) for a in C.TYPES[121]["att"])["objname"], "page0")
|
|
|
|
|
|
class Factory(unittest.TestCase):
|
|
def test_add_every_kind(self):
|
|
p = C.new_page("p0")
|
|
for k in C.kinds():
|
|
if k == "page":
|
|
continue
|
|
att = {a[0] for a in C.TYPES[C.KINDS[k]]["att"]}
|
|
kw = dict(x=5, y=6, w=50, h=20) if "x" in att else {}
|
|
C.add(p, k, **kw)
|
|
q = Page.parse(p.pack())
|
|
self.assertEqual(len(q.components), len(C.kinds()))
|
|
ids = [c.get("id") for c in q.components]
|
|
self.assertEqual(sorted(ids), list(range(len(ids))))
|
|
self.assertEqual(len({c.name for c in q.components}), len(q.components))
|
|
|
|
def test_endx_endy_and_events(self):
|
|
p = C.new_page("p0")
|
|
b = C.add(p, "button", x=10, y=20, w=30, h=40, txt="ok", events={"codesup": ["page 1"]})
|
|
self.assertEqual((b.get("endx"), b.get("endy")), (39, 59))
|
|
self.assertEqual(b.event("codesup"), ["page 1"])
|
|
|
|
def test_duplicate_name_rejected(self):
|
|
p = C.new_page("p0")
|
|
C.add(p, "text", "t0")
|
|
with self.assertRaises(ValueError):
|
|
C.add(p, "text", "t0")
|
|
|
|
def test_new_page_defaults(self):
|
|
p = C.new_page("x", w=800, h=480)
|
|
pc = p.components[0]
|
|
self.assertEqual((pc.get("sta"), pc.get("bco"), pc.get("w"), pc.get("h")), (1, 0xFFFF, 800, 480))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|