Fix variant initialization logic to allow proper handling of values="*" (#40406)
Co-authored-by: psakiev <psakiev@sandia.gov> Co-authored-by: tjfulle <tjfulle@users.noreply.github.com>
This commit is contained in:
parent
ec9d08e71e
commit
4540980337
@ -734,3 +734,40 @@ def test_conditional_value_comparable_to_bool(other):
|
|||||||
value = spack.variant.Value("98", when="@1.0")
|
value = spack.variant.Value("98", when="@1.0")
|
||||||
comparison = value == other
|
comparison = value == other
|
||||||
assert comparison is False
|
assert comparison is False
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.regression("40405")
|
||||||
|
def test_wild_card_valued_variants_equivalent_to_str():
|
||||||
|
"""
|
||||||
|
There was a bug prioro to PR 40406 in that variants with wildcard values "*"
|
||||||
|
were being overwritten in the variant constructor.
|
||||||
|
The expected/appropriate behavior is for it to behave like value=str and this
|
||||||
|
test demonstrates that the two are now equivalent
|
||||||
|
"""
|
||||||
|
str_var = spack.variant.Variant(
|
||||||
|
name="str_var",
|
||||||
|
default="none",
|
||||||
|
values=str,
|
||||||
|
description="str variant",
|
||||||
|
multi=True,
|
||||||
|
validator=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
wild_var = spack.variant.Variant(
|
||||||
|
name="wild_var",
|
||||||
|
default="none",
|
||||||
|
values="*",
|
||||||
|
description="* variant",
|
||||||
|
multi=True,
|
||||||
|
validator=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
several_arbitrary_values = ("doe", "re", "mi")
|
||||||
|
# "*" case
|
||||||
|
wild_output = wild_var.make_variant(several_arbitrary_values)
|
||||||
|
wild_var.validate_or_raise(wild_output)
|
||||||
|
# str case
|
||||||
|
str_output = str_var.make_variant(several_arbitrary_values)
|
||||||
|
str_var.validate_or_raise(str_output)
|
||||||
|
# equivalence each instance already validated
|
||||||
|
assert str_output.value == wild_output.value
|
||||||
|
@ -75,7 +75,7 @@ def isa_type(v):
|
|||||||
|
|
||||||
self.single_value_validator = isa_type
|
self.single_value_validator = isa_type
|
||||||
|
|
||||||
if callable(values):
|
elif callable(values):
|
||||||
# If 'values' is a callable, assume it is a single value
|
# If 'values' is a callable, assume it is a single value
|
||||||
# validator and reset the values to be explicit during debug
|
# validator and reset the values to be explicit during debug
|
||||||
self.single_value_validator = values
|
self.single_value_validator = values
|
||||||
|
Loading…
Reference in New Issue
Block a user