diff options
author | Tim Fuller <tjfulle@sandia.gov> | 2023-12-22 08:10:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-22 16:10:43 +0100 |
commit | 4540980337f6b516b634f075a82e515b3464cf6b (patch) | |
tree | c3226b1c4f4aa6a1227a20cd63145562718379c4 | |
parent | ec9d08e71ec2ef0b50d834f2ee7ad25658689e01 (diff) | |
download | spack-4540980337f6b516b634f075a82e515b3464cf6b.tar.gz spack-4540980337f6b516b634f075a82e515b3464cf6b.tar.bz2 spack-4540980337f6b516b634f075a82e515b3464cf6b.tar.xz spack-4540980337f6b516b634f075a82e515b3464cf6b.zip |
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>
-rw-r--r-- | lib/spack/spack/test/variant.py | 37 | ||||
-rw-r--r-- | lib/spack/spack/variant.py | 2 |
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/spack/spack/test/variant.py b/lib/spack/spack/test/variant.py index 517197654c..62954138e5 100644 --- a/lib/spack/spack/test/variant.py +++ b/lib/spack/spack/test/variant.py @@ -734,3 +734,40 @@ def test_conditional_value_comparable_to_bool(other): value = spack.variant.Value("98", when="@1.0") comparison = value == other 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 diff --git a/lib/spack/spack/variant.py b/lib/spack/spack/variant.py index f9f6f8b960..1c6931d40e 100644 --- a/lib/spack/spack/variant.py +++ b/lib/spack/spack/variant.py @@ -75,7 +75,7 @@ class Variant: self.single_value_validator = isa_type - if callable(values): + elif callable(values): # If 'values' is a callable, assume it is a single value # validator and reset the values to be explicit during debug self.single_value_validator = values |