Skip to content

Commit

Permalink
test: allow adding extra bits to a TabletFile wrapper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whot committed Nov 4, 2024
1 parent 3db4f04 commit e4f16e4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/test_libwacom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down

0 comments on commit e4f16e4

Please sign in to comment.