diff --git a/pyproject.toml b/pyproject.toml index 389b0c9..0cf4967 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vban-cmd" -version = "2.4.5" +version = "2.4.6" description = "Python interface for the VBAN RT Packet Service (Sendtext)" authors = ["onyx-and-iris "] license = "MIT" diff --git a/tests/banana.svg b/tests/banana.svg index 9b71f92..08a8acd 100644 --- a/tests/banana.svg +++ b/tests/banana.svg @@ -1 +1 @@ -tests: 48tests48 \ No newline at end of file +tests: 49tests49 \ No newline at end of file diff --git a/tests/basic.svg b/tests/basic.svg index 093e718..9ecc2fa 100644 --- a/tests/basic.svg +++ b/tests/basic.svg @@ -1 +1 @@ -tests: 50tests50 \ No newline at end of file +tests: 51tests51 \ No newline at end of file diff --git a/tests/potato.svg b/tests/potato.svg index 0eebed9..7300e06 100644 --- a/tests/potato.svg +++ b/tests/potato.svg @@ -1 +1 @@ -tests: 58tests58 \ No newline at end of file +tests: 59tests59 \ No newline at end of file diff --git a/tests/test_errors.py b/tests/test_errors.py index 90e6643..4090f36 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -14,7 +14,7 @@ class TestErrors: ): vban_cmd.api("unknown_kind") - def test_it_tests_an_invalid_config(self): + def test_it_tests_an_unknown_config_name(self): EXPECTED_MSG = ( f"No config with name 'unknown' is loaded into memory", f"Known configs: {list(vban.configs.keys())}", @@ -24,3 +24,13 @@ class TestErrors: e = exc_info.value assert e.message == "\n".join(EXPECTED_MSG) + + def test_it_tests_an_invalid_config_key(self): + CONFIG = { + "strip-0": {"A1": True, "B1": True, "gain": -6.0}, + "bus-0": {"mute": True, "eq": {"on": True}}, + "unknown-0": {"state": True}, + "vban-out-1": {"name": "streamname"}, + } + with pytest.raises(ValueError, match="invalid config key 'unknown'"): + vban.apply(CONFIG) diff --git a/vban_cmd/vbancmd.py b/vban_cmd/vbancmd.py index 9f26d52..73e9fbd 100644 --- a/vban_cmd/vbancmd.py +++ b/vban_cmd/vbancmd.py @@ -182,16 +182,23 @@ class VbanCmd(metaclass=ABCMeta): minor delay between each recursion """ - def param(key): - obj, m2, *rem = key.split("-") - index = int(m2) if m2.isnumeric() else int(*rem) - if obj in ("strip", "bus", "button"): - return getattr(self, obj)[index] - elif obj == "vban": - return getattr(getattr(self, obj), f"{m2}stream")[index] - raise ValueError(obj) + def target(key): + kls, m2, *rem = key.split("-") + match kls: + case "strip" | "bus" | "button": + index = m2 + target = getattr(self, kls) + case "vban": + dir = f"{m2.rstrip('stream')}stream" + index = rem[0] + target = getattr(self.vban, dir) + case _: + ERR_MSG = f"invalid config key '{kls}'" + self.logger.error(ERR_MSG) + raise ValueError(ERR_MSG) + return target[int(index)] - [param(key).apply(datum).then_wait() for key, datum in data.items()] + [target(key).apply(di).then_wait() for key, di in data.items()] def apply_config(self, name): """applies a config from memory"""