Files
homeassistant_espscreen/tests/test_release_lint.py
T
Max Gramser d76461d774 Build every screen from one shared core plus a small file per board, the same firmware as before (0.2.84)
The two board profiles (5,000 lines each, 87 % the same text) become packages/core.yaml and one file per
board under packages/boards/: the hardware, a table of 84 sizes and font sizes, 18 hooks with the lines of C++
only that board adds inside a shared lambda, and the board's own sections. packages/cyd.yaml and
packages/guition.yaml keep their names and places (a screen installed from ESP Screens builds as before);
home-like-2432s028.yaml and guition-4848s040.yaml become the same entries for a checkout.

The firmware stays 0.2.70: the C++ ESPHome generates for each board, through the checkout profile and
through the GitHub package route, was compared line by line with the old profiles' (docs/TEST_RESULTS_0284.md).
tools/check_packages.py replaces tools/generate_packages.py; tools/profiles.py gives the tests and tools the
three files as one; docs/PROFILES.md says how the files fit together and how a board is added.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-18 22:57:14 +02:00

73 lines
3.5 KiB
Python

"""Release lint (app 0.2.78): the version numbers of a release agree, and the packages fetch only fonts that exist.
Every push to main is a release (docs/RELEASING.md), so these run with the rest of the suite in tools/check.sh and CI.
Standard library only.
"""
from pathlib import Path
import re
import sys
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'tools'))
import profiles # noqa: E402
sys.path.insert(0, str(ROOT / 'screen_manager/app'))
from core import FIRMWARE_VERSION # noqa: E402
CHANGELOG = ROOT / 'screen_manager/CHANGELOG.md'
# An app release: "## 0.2.76 (firmware 0.2.63)"; the oldest ones name no firmware. The two "## Firmware 0.2.1x"
# sections are firmware-only releases between app 0.2.11 and 0.2.12 and carry no app version, so they don't count.
APP_HEADING = re.compile(r'^## (\d+)\.(\d+)\.(\d+)\b(.*)$', re.M)
FIRMWARE_IN_HEADING = re.compile(r'\(firmware (\d+\.\d+\.\d+)\)')
# The published entries (packages/<board>.yaml) point ${FONT_DIR} at the raw GitHub URL of fonts/ on main.
FONT_URL = re.compile(r'https://raw\.githubusercontent\.com/MaxGramser/homeassistant_espscreen/[^/\s"\']+/(fonts/[^"\'\s]+)')
def app_headings():
"""[(version tuple, text after the version)] of the CHANGELOG, top to bottom."""
return [((int(a), int(b), int(c)), rest) for a, b, c, rest in APP_HEADING.findall(CHANGELOG.read_text())]
def dotted(version):
return '.'.join(map(str, version))
class ReleaseVersionTests(unittest.TestCase):
def test_config_version_is_the_newest_changelog_entry(self):
match = re.search(r'^version:\s*["\']?([^"\'\s]+)["\']?\s*$', (ROOT / 'screen_manager/config.yaml').read_text(), re.M)
self.assertIsNotNone(match, 'screen_manager/config.yaml has no version line')
headings = app_headings()
self.assertTrue(headings, 'screen_manager/CHANGELOG.md has no "## x.y.z" heading')
self.assertEqual(match.group(1), dotted(headings[0][0]),
'Home Assistant offers the update by config.yaml: bump it together with a new CHANGELOG entry')
def test_newest_entry_names_the_shipped_firmware(self):
version, rest = app_headings()[0]
firmware = FIRMWARE_IN_HEADING.search(rest)
if firmware:
self.assertEqual(firmware.group(1), FIRMWARE_VERSION,
f'CHANGELOG {dotted(version)} names firmware {firmware.group(1)}, core.FIRMWARE_VERSION is {FIRMWARE_VERSION}')
def test_changelog_versions_are_unique_and_newest_first(self):
versions = [version for version, _ in app_headings()]
duplicates = sorted({dotted(v) for v in versions if versions.count(v) > 1})
self.assertEqual(duplicates, [], 'a CHANGELOG version appears twice')
for newer, older in zip(versions, versions[1:]):
self.assertGreater(newer, older, f'CHANGELOG {dotted(newer)} stands above {dotted(older)}')
class PackageFontTests(unittest.TestCase):
def test_every_font_a_package_fetches_is_in_the_tree(self):
seen = 0
for package in profiles.PACKAGES:
# The shared core names its fonts as ${FONT_DIR}/...; the published entry says where that is (app 0.2.84+).
for path in FONT_URL.findall(profiles.merged(package)):
seen += 1
self.assertTrue((ROOT / path).is_file(), f'{package} fetches {path}, which is not in the tree')
# A changed URL form must not turn this into a test of nothing.
self.assertGreater(seen, 0, 'no fonts/... URL found in packages/*.yaml')
if __name__ == '__main__':
unittest.main()