Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/taskwarrior/services/uda_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/test_uda_values.py
Original file line number Diff line number Diff line change
@@ -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
Loading