"""The .tft builder. Real Editor output cannot be in the repo (it embeds Nextion firmware), so these tests use a fake "Editor folder" with generated stand-in files and check the structure. Byte-identity with the Editor is checked by test_against_editor_samples when NXHMI_TFT_SAMPLES points to a folder of .HMI + .tft pairs made with Nextion Editor 1.68.2.""" import glob import os import shutil import struct import tempfile import unittest from helpers import HAVE_PIL from nxhmi import cli, components as C, project, tft, tft_build from nxhmi.page import Page SAMPLES = os.environ.get("NXHMI_TFT_SAMPLES") class Build(unittest.TestCase): def setUp(self): self.tmp = tempfile.mkdtemp() for i, n in enumerate(tft_build.FIRMWARE_FILES): with open(os.path.join(self.tmp, n), "wb") as fh: fh.write(bytes([i + 1]) * (100 + 7 * i)) def tearDown(self): shutil.rmtree(self.tmp) def project(self): h = project.new_project("NX4832T035_011") p = Page.parse(h.read("0.pa")) C.add(p, "hotspot", x=10, y=20, w=30, h=40) C.add(p, "variable") h.write("0.pa", p.pack()) project.add_page(h, "second") return h def test_structure(self): out = tft_build.build_tft(self.project(), self.tmp) self.assertEqual(len(out) % 4, 0) self.assertTrue(tft.verify_header(out)) self.assertTrue(tft.verify_trailer(out)) self.assertEqual(struct.unpack_from("