Files
pmaports-rtwo/.ci/testcases/test_deviceinfo.py
T
Pablo Correa Gómez d035338047 ci: fix remaining ruff issues and run ruff format
We only disable LOG015 rule, as in the simple situation of pmaports,
it doesn't matter too much if in pytest we are using the root logger
or a custom one.

Signed-off-by: Pablo Correa Gómez <pabloyoyoista@postmarketos.org>
Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/9363>
2026-08-12 05:39:47 +00:00

65 lines
2.1 KiB
Python

# Copyright 2021 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import re
import pmb.parse
from pmb.core.pkgrepo import pkgrepo_iglob
def test_deviceinfo():
"""
Parse all deviceinfo files successfully and run checks on the parsed data.
"""
# Iterate over all devices
last_exception = None
count = 0
pattern = re.compile('^deviceinfo_[a-zA-Z0-9_]*=".*"(\\s*# .*)?$')
for folder in pkgrepo_iglob("device/*/device-*"):
device = folder.name.split("-", 1)[1]
with open(folder / "deviceinfo") as f:
lines = f.read().split("\n")
try:
for line in lines:
# Skip empty lines and comments
if not line or line.startswith("# "):
continue
# Check line against regex (can't use multiple lines etc.)
if not pattern.match(line) or line.endswith('\\"'):
raise RuntimeError(
"Line looks invalid, maybe missing"
" quotes/multi-line string/malformed"
f" inline comment? {line}"
)
# Successful deviceinfo parsing / obsolete options
info = pmb.parse.deviceinfo(device)
# deviceinfo_name must start with manufacturer
name = info.name
manufacturer = info.manufacturer
if (
not name.startswith(manufacturer)
and not name.startswith("Google")
and not name.startswith("Jolla")
):
raise RuntimeError(
"Please add the manufacturer in front of"
" the deviceinfo_name, e.g.: '" + manufacturer + " " + name + "'"
)
# Don't abort on first error
except (RuntimeError, SyntaxError, ValueError) as e:
last_exception = e
count += 1
print(device + ": " + str(e))
# Raise the last exception
if last_exception:
print("deviceinfo error count: " + str(count))
raise last_exception