1
0
forked from drath/libratbag

test: add test for sinowealth driver sections in device files

This commit is contained in:
Yaroslav Chvanov
2023-03-19 01:47:45 +03:00
parent 2522e4ed20
commit 4b936bf478

View File

@@ -275,6 +275,20 @@ def validate_data_file_name(path: str):
)
SINOWEALTH_DEVICE_SECTION_PREFIX = "Driver/sinowealth/devices/"
SINOWEALTH_REQUIRED_KEYS = (
"DeviceName",
"FwVersion",
"LedType",
)
SINOWEALTH_PERMITTED_KEYS = (
*SINOWEALTH_REQUIRED_KEYS,
"ButtonCount",
"ProfileCount",
"SensorType",
)
def parse_data_file(path: str):
print(f"Parsing file {path}")
data = configparser.ConfigParser(strict=True)
@@ -289,9 +303,19 @@ def parse_data_file(path: str):
driver_section = f"Driver/{driver}"
permitted_sections = ["Device", driver_section]
# FIXME: remove this once `sinowealth` driver has a better way of defining data.
# The sinowealth driver uses non-static section names in device files as it
# uses a single device file for several actual devices. See the example
# device file for details.
if driver == "sinowealth":
print("Skipping `Driver` section check for a `sinowealth` device")
for device_section_name in data.sections():
if not device_section_name.startswith(SINOWEALTH_DEVICE_SECTION_PREFIX):
continue
device_section = data[device_section_name]
for key in SINOWEALTH_REQUIRED_KEYS:
assert key in device_section
for key in device_section:
assert key in SINOWEALTH_PERMITTED_KEYS
else:
for s in data.sections():
assert s in permitted_sections