From 65fb8990c99ac7e71225e3c6956b94590a3f5660 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 10 Aug 2023 16:24:30 +0100 Subject: [PATCH] make better use of pattern matching features error test updated --- tests/test_errors.py | 2 +- voicemeeterlib/remote.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/test_errors.py b/tests/test_errors.py index 364e10e..b1aa4f0 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -43,5 +43,5 @@ class TestErrors: "unknown-0": {"state": True}, "vban-out-1": {"name": "streamname"}, } - with pytest.raises(ValueError, match="invalid config key 'unknown'"): + with pytest.raises(ValueError, match="invalid config key 'unknown-0'"): vm.apply(CONFIG) diff --git a/voicemeeterlib/remote.py b/voicemeeterlib/remote.py index a96466c..a7c6ac0 100644 --- a/voicemeeterlib/remote.py +++ b/voicemeeterlib/remote.py @@ -300,17 +300,13 @@ class Remote(CBindings): """ def target(key): - kls, m2, *rem = key.split("-") - match kls: - case "strip" | "bus" | "button": - index = m2 + match key.split("-"): + case ["strip" | "bus" | "button" as kls, index]: target = getattr(self, kls) - case "vban": - dir = f"{m2.rstrip('stream')}stream" - index = rem[0] - target = getattr(self.vban, dir) + case ["vban", direction, index]: + target = getattr(self.vban, f"{direction.rstrip('stream')}stream") case _: - ERR_MSG = f"invalid config key '{kls}'" + ERR_MSG = f"invalid config key '{key}'" self.logger.error(ERR_MSG) raise ValueError(ERR_MSG) return target[int(index)]