mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-08 07:33:53 +01:00
test: add test for sinowealth driver sections in device files
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user