From 88a3b2be531f1caa11b4280dc214a051cf2f0312 Mon Sep 17 00:00:00 2001 From: nsz Date: Tue, 7 Apr 2026 19:42:01 +0200 Subject: [PATCH] fix uda values --- src/taskwarrior/services/uda_service.py | 3 +- tests/unit/test_uda_values.py | 48 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_uda_values.py diff --git a/src/taskwarrior/services/uda_service.py b/src/taskwarrior/services/uda_service.py index a66207b..bb87a29 100644 --- a/src/taskwarrior/services/uda_service.py +++ b/src/taskwarrior/services/uda_service.py @@ -69,7 +69,8 @@ def define_uda(self, uda: UdaConfig) -> None: for field_name in field_names: value = getattr(uda, field_name) if value is not None and value != "": - commands.append(["config", f"uda.{uda.name}.{field_name}", str(value)]) + value_str = ",".join(map(str, value)) if field_name == "values" else str(value) + commands.append(["config", f"uda.{uda.name}.{field_name}", value_str]) # Execute commands via adapter; if any fail, raise and do not modify registry for cmd in commands: diff --git a/tests/unit/test_uda_values.py b/tests/unit/test_uda_values.py new file mode 100644 index 0000000..98757a8 --- /dev/null +++ b/tests/unit/test_uda_values.py @@ -0,0 +1,48 @@ +import types + +from taskwarrior.dto.uda_dto import UdaConfig, UdaType +from taskwarrior.services.uda_service import UdaService + + +def test_define_uda_with_list_values(): + calls = [] + + class DummyAdapter: + def run_task_command(self, cmd): + # record the command and simulate success + calls.append(cmd) + return types.SimpleNamespace(returncode=0, stdout="", stderr="") + + class DummyConfigStore: + pass + + uda = UdaConfig(name="complexity", uda_type=UdaType.STRING, values=["low", "medium", "high"], label="Complexity level") + svc = UdaService(DummyAdapter(), DummyConfigStore()) + svc.define_uda(uda) + + # Type command must be present + assert ["config", "uda.complexity.type", uda.uda_type.value] in calls + + # Values list should be converted to comma-separated string + assert ["config", "uda.complexity.values", "low,medium,high"] in calls + + +def test_define_uda_with_int_values(): + calls = [] + + class DummyAdapter: + def run_task_command(self, cmd): + calls.append(cmd) + return types.SimpleNamespace(returncode=0, stdout="", stderr="") + + class DummyConfigStore: + pass + + # values provided as ints should be stringified and joined + # construct without validation to simulate non-str inputs + uda = UdaConfig.model_construct(name="score", uda_type=UdaType.NUMERIC, values=[1, 2, 3], label="Score levels") + svc = UdaService(DummyAdapter(), DummyConfigStore()) + svc.define_uda(uda) + + assert ["config", "uda.score.type", uda.uda_type.value] in calls + assert ["config", "uda.score.values", "1,2,3"] in calls