From a7bd1a8a80dd2e3d88a6e951502eb87b1e065a10 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 22 Dec 2025 23:31:06 +0100 Subject: [PATCH] tests/f2: allow string lists as config values not all values are sets. the search path for example is definitely ordered. Change-Id: Ice94fe324319731ae3a83c757768c48576ba8b36 --- tests/functional2/testlib/fixtures/nix.py | 4 ++-- tests/functional2/testlib/test_utils.py | 1 + tests/functional2/testlib/utils.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/functional2/testlib/fixtures/nix.py b/tests/functional2/testlib/fixtures/nix.py index 219d81036..c56cf7e64 100644 --- a/tests/functional2/testlib/fixtures/nix.py +++ b/tests/functional2/testlib/fixtures/nix.py @@ -62,12 +62,12 @@ class NixSettings: def serialise(value: Any) -> str: # TODO(Commentator2.0): why exactly are ints supported? - if is_value_of_type(value, set[str | int]): + if is_value_of_type(value, set[str | int] | list[str | int]): return " ".join(serialise(e) for e in value) if is_value_of_type(value, str | int): return str(value) - msg = f"Value is unsupported in nix config: {value!r}, must bei either `str|int` or `set[str|int]`" + msg = f"Value is unsupported in nix config: {value!r}, must bei either `str|int` or `set[str|int]` or `list[str|int]`" raise ValueError(msg) def field_may(name: str, value: Any, serializer: Callable[[Any], str] = serialise): diff --git a/tests/functional2/testlib/test_utils.py b/tests/functional2/testlib/test_utils.py index 3efba199e..d257e39c4 100644 --- a/tests/functional2/testlib/test_utils.py +++ b/tests/functional2/testlib/test_utils.py @@ -11,6 +11,7 @@ def test_list_type_valid(): def test_list_type_valid_multi_type(): assert is_value_of_type([1, "a", 2], list[int | str]) + assert is_value_of_type([1, "a", 2], set[str | int] | list[int | str]) def test_list_type_invalid_single_fail(): diff --git a/tests/functional2/testlib/utils.py b/tests/functional2/testlib/utils.py index c87373501..6f9b83b6b 100644 --- a/tests/functional2/testlib/utils.py +++ b/tests/functional2/testlib/utils.py @@ -120,8 +120,10 @@ def is_value_of_type(value: Any, expected_type: type[Any] | UnionType) -> bool: if expected_type is Any: return True match origin: - case None | types.UnionType: + case None: return isinstance(value, expected_type) + case types.UnionType: + return any(is_value_of_type(value, t) for t in get_args(expected_type)) case typing.Literal: return value in get_args(expected_type) case builtins.type: