Skip to content

Commit

Permalink
Failing test for unset conf (#17445)
Browse files Browse the repository at this point in the history
* Initial sketch for better unset of confs

* Fail test for now

* Make choice'ed unset behave the same

---------

Co-authored-by: Carlos Zoido <mrgalleta@gmail.com>
  • Loading branch information
AbrilRBS and czoido authored Dec 11, 2024
1 parent 91f743b commit 04d31d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 19 additions & 0 deletions test/unittests/model/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 04d31d9

Please sign in to comment.