45
45
from variantlib .constants import VARIANTS_JSON_SCHEMA_URL
46
46
from variantlib .constants import VARIANTS_JSON_VARIANT_DATA_KEY
47
47
from variantlib .constants import VariantsJsonDict
48
+ from variantlib .errors import ValidationError
48
49
from variantlib .models import provider as pconfig
49
50
from variantlib .models import variant as vconfig
50
51
from variantlib .models .configuration import VariantConfiguration as VConfigurationModel
@@ -349,8 +350,10 @@ def test_validate_variant(mocked_plugin_apis: list[str], optional: bool) -> None
349
350
@pytest .mark .parametrize (
350
351
"pyproject_toml" , [None , PYPROJECT_TOML , PYPROJECT_TOML_MINIMAL ]
351
352
)
353
+ @pytest .mark .parametrize ("label" , [None , "foo" , "xy1.2" ])
352
354
def test_make_variant_dist_info (
353
355
pyproject_toml : VariantsJsonDict | None ,
356
+ label : str | None ,
354
357
) -> None :
355
358
expected : VariantsJsonDict = {
356
359
VARIANTS_JSON_SCHEMA_KEY : VARIANTS_JSON_SCHEMA_URL ,
@@ -359,7 +362,7 @@ def test_make_variant_dist_info(
359
362
},
360
363
VARIANT_INFO_PROVIDER_DATA_KEY : {},
361
364
VARIANTS_JSON_VARIANT_DATA_KEY : {
362
- "67fcaf38" : {
365
+ label if label else "67fcaf38" : {
363
366
"ns1" : {
364
367
"f1" : ["p1" ],
365
368
"f2" : ["p2" ],
@@ -424,6 +427,7 @@ def test_make_variant_dist_info(
424
427
variant_info = VariantPyProjectToml (pyproject_toml ) # type: ignore[arg-type]
425
428
if pyproject_toml is not None
426
429
else None ,
430
+ variant_label = label ,
427
431
)
428
432
)
429
433
== expected
@@ -542,3 +546,28 @@ def test_get_variant_environment_dict() -> None:
542
546
"ns3 :: feat2 :: val2" ,
543
547
},
544
548
}
549
+
550
+
551
+ def test_make_variant_dist_info_invalid_label ():
552
+ with pytest .raises (
553
+ ValidationError , match = r"Variant label cannot be specified for the null variant"
554
+ ):
555
+ make_variant_dist_info (VariantDescription ([]), variant_label = "foo" )
556
+ with pytest .raises (
557
+ ValidationError ,
558
+ match = rf"{ NULL_VARIANT_HASH } label can be used only for the null variant" ,
559
+ ):
560
+ make_variant_dist_info (
561
+ VariantDescription ([VariantProperty ("a" , "b" , "c" )]),
562
+ variant_label = NULL_VARIANT_HASH ,
563
+ )
564
+ with pytest .raises (ValidationError , match = r"Invalid variant label: foo/bar" ):
565
+ make_variant_dist_info (
566
+ VariantDescription ([VariantProperty ("a" , "b" , "c" )]),
567
+ variant_label = "foo/bar" ,
568
+ )
569
+ with pytest .raises (ValidationError , match = r"Invalid variant label: 123456789" ):
570
+ make_variant_dist_info (
571
+ VariantDescription ([VariantProperty ("a" , "b" , "c" )]),
572
+ variant_label = "123456789" ,
573
+ )
0 commit comments