1
0
forked from drath/libratbag

test: use a simply assert instead of using a helper

This commit is contained in:
Yaroslav Chvanov
2023-03-02 14:05:37 +03:00
parent 1d24aa71d3
commit a9545b2b63

View File

@@ -31,21 +31,6 @@ import re
import sys
import traceback
from typing import Collection, TypeVar
T = TypeVar("T")
def assertIn(element: T, collection: Collection[T]):
if element not in collection:
raise ValueError(f"{element} must be in {collection}")
def assertNotIn(element: T, collection: Collection[T]):
if element in collection:
raise ValueError(f"{element} must not be in {collection}")
def check_match_str(string: str):
bustypes = ["usb", "bluetooth"]
@@ -57,7 +42,7 @@ def check_match_str(string: str):
parts = match.split(":")
assert len(parts) == 3
assertIn(parts[0], bustypes)
assert parts[0] in bustypes
vid = parts[1]
assert vid == f"{int(vid, 16):04x}"
pid = parts[2]
@@ -66,17 +51,17 @@ def check_match_str(string: str):
def check_devicetype_str(string):
permitted_types = ["mouse", "keyboard", "other"]
assertIn(string, permitted_types)
assert string in permitted_types
def check_section_device(section: configparser.SectionProxy):
required_keys = ["Name", "Driver", "DeviceMatch", "DeviceType"]
for key in section:
assertIn(key, required_keys)
assert key in required_keys
for r in required_keys:
assertIn(r, section)
assert r in section
check_devicetype_str(section["DeviceType"])
@@ -117,7 +102,7 @@ def check_dpi_list_str(string: str):
def check_profile_type_str(string: str):
types = ["G9", "G500", "G700"]
assertIn(string, types)
assert string in types
def check_section_asus(section: configparser.SectionProxy):
@@ -132,7 +117,7 @@ def check_section_asus(section: configparser.SectionProxy):
"Wireless",
)
for key in section:
assertIn(key, permitted_keys)
assert key in permitted_keys
try:
check_dpi_range_str(section["DpiRange"])
@@ -146,7 +131,7 @@ def check_section_asus(section: configparser.SectionProxy):
"STRIX_PROFILE",
)
for quirk in section["Quirks"].split(";"):
assertIn(quirk, quirks)
assert quirk in quirks
except KeyError:
# No such section - not an error.
pass
@@ -162,7 +147,7 @@ def check_section_hidpp10(section: configparser.SectionProxy):
"Leds",
]
for key in section:
assertIn(key, permitted)
assert key in permitted
try:
nprofiles = int(section["Profiles"])
@@ -181,14 +166,14 @@ def check_section_hidpp10(section: configparser.SectionProxy):
try:
check_dpi_range_str(section["DpiRange"])
assertNotIn("DpiList", section.keys())
assert "DpiList" not in section.keys()
except KeyError:
# No such section - not an error.
pass
try:
check_dpi_list_str(section["DpiList"])
assertNotIn("DpiRange", section.keys())
assert "DpiRange" not in section.keys()
except KeyError:
# No such section - not an error.
pass
@@ -211,7 +196,7 @@ def check_section_hidpp10(section: configparser.SectionProxy):
def check_section_hidpp20(section: configparser.SectionProxy):
permitted = ["Buttons", "DeviceIndex", "Leds", "ReportRate", "Quirk"]
for key in section:
assertIn(key, permitted)
assert key in permitted
try:
index = int(section["DeviceIndex"], 16)
@@ -232,25 +217,25 @@ def check_section_steelseries(section: configparser.SectionProxy):
"Quirk",
)
for key in section:
assertIn(key, permitted_keys)
assert key in permitted_keys
try:
check_dpi_list_str(section["DpiList"])
assertNotIn("DpiRange", section.keys())
assert "DpiRange" not in section.keys()
except KeyError:
# No such section - not an error.
pass
try:
check_dpi_range_str(section["DpiRange"])
assertNotIn("DpiList", section.keys())
assert "DpiList" not in section.keys()
except KeyError:
# No such section - not an error.
pass
try:
quirks = ("Rival100", "SenseiRAW")
assertIn(section["Quirk"], quirks)
assert section["Quirk"] in quirks
except KeyError:
# No such section - not an error.
pass
@@ -297,7 +282,7 @@ def parse_data_file(path: str):
data.optionxform = lambda option: option
data.read(path)
assertIn("Device", data.sections())
assert "Device" in data.sections()
check_section_device(data["Device"])
driver = data["Device"]["Driver"]
@@ -309,7 +294,7 @@ def parse_data_file(path: str):
print("Skipping `Driver` section check for a `sinowealth` device")
else:
for s in data.sections():
assertIn(s, permitted_sections)
assert s in permitted_sections
if data.has_section(driver_section):
check_section_driver(driver, data[driver_section])
@@ -326,7 +311,7 @@ def main() -> None:
try:
validate_data_file_name(path_str)
parse_data_file(path_str)
except ValueError:
except Exception:
is_error = True
traceback.print_exc(file=sys.stdout)