From 04d31d9ab6e39a8aa6862c6844638e3db7ae45e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Wed, 11 Dec 2024 21:07:25 +0100 Subject: [PATCH] Failing test for unset conf (#17445) * Initial sketch for better unset of confs * Fail test for now * Make choice'ed unset behave the same --------- Co-authored-by: Carlos Zoido --- conans/model/conf.py | 2 +- test/unittests/model/test_conf.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/conans/model/conf.py b/conans/model/conf.py index 9140be00a31..a9664b891cd 100644 --- a/conans/model/conf.py +++ b/conans/model/conf.py @@ -322,7 +322,7 @@ def get(self, conf_name, default=None, check_type=None, choices=None): conf_value = self._values.get(conf_name) if conf_value: v = conf_value.value - if choices is not None and v not in choices: + if choices is not None and v not in choices and v is not None: raise ConanException(f"Unknown value '{v}' for '{conf_name}'") # Some smart conversions if check_type is bool and not isinstance(v, bool): diff --git a/test/unittests/model/test_conf.py b/test/unittests/model/test_conf.py index f0d155a74f9..841a87bf7d4 100644 --- a/test/unittests/model/test_conf.py +++ b/test/unittests/model/test_conf.py @@ -326,3 +326,22 @@ def test_conf_scope_patterns_bad(scope, conf, assert_message): c.loads(final_conf) c.validate() assert assert_message in str(exc_info.value) + + +@pytest.mark.parametrize("choices", [None, ["Foo", "Bar"]]) +def test_unset_basic_same_behaviour(choices): + c = ConfDefinition() + assert c.get("user.company.cpu:jobs", choices=choices) is None + + c2 = ConfDefinition() + c2.loads("user.company.cpu:jobs=!") + assert c2.get("user.company.cpu:jobs", choices=choices) is None + + c3 = ConfDefinition() + c3.loads("user.company.cpu:jobs=4") + + c4 = ConfDefinition() + c4.loads("user.company.cpu:jobs=!") + c3.update_conf_definition(c4) + + assert c3.get("user.company.cpu:jobs", choices=choices) is None