From ffddb2fd53107b99cd8ea4b01beede9ba86c7402 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 23 Oct 2024 15:20:55 +1000 Subject: [PATCH] test: allow adding extra bits to a TabletFile wrapper This switches the config to a dict first so we can easily merge it, then we can set up the ConfigParser from our merged dict. --- test/test_libwacom.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/test_libwacom.py b/test/test_libwacom.py index 5d344a0f..938c7180 100644 --- a/test/test_libwacom.py +++ b/test/test_libwacom.py @@ -89,11 +89,15 @@ class TabletFile: has_stylus: bool = True is_reversible: bool = False styli: list[str] = field(default_factory=list) + # extra additions to the tablet file, e.g. { "Buttons": { "Left" : "A;B;" } + extra: dict[str, dict[str, str]] = field(default_factory=dict) def write_to(self, filename): config = ConfigParser() config.optionxform = lambda option: option - config["Device"] = { + + cfg = {} + cfg["Device"] = { "Name": self.name, "DeviceMatch": ";".join(self.matches), "Width": self.width, @@ -103,12 +107,18 @@ def write_to(self, filename): "Layout": self.layout, } if self.styli: - config["Device"]["Styli"] = ";".join(self.styli) + cfg["Device"]["Styli"] = ";".join(self.styli) - config["Features"] = { + cfg["Features"] = { "Stylus": self.has_stylus, "Reversible": self.is_reversible, } + + cfg = cfg | self.extra + + for k, v in cfg.items(): + config[k] = v + with open(filename, "w") as fd: config.write(fd, space_around_delimiters=False)