Skip to content

Commit 9085d4c

Browse files
committed
Update variant model tests for labels
Signed-off-by: Michał Górny <mgorny@quansight.com>
1 parent 295c1f9 commit 9085d4c

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

tests/models/test_variant.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import pytest
77
from hypothesis import given
88
from hypothesis import strategies as st
9+
from variantlib.constants import NULL_VARIANT_LABEL
910
from variantlib.constants import VALIDATION_FEATURE_NAME_REGEX
1011
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
1112
from variantlib.constants import VALIDATION_VALUE_REGEX
13+
from variantlib.constants import VALIDATION_VARIANT_LABEL_REGEX
1214
from variantlib.errors import ValidationError
1315
from variantlib.models.variant import VARIANT_HASH_LENGTH
1416
from variantlib.models.variant import VariantDescription
@@ -214,6 +216,7 @@ def test_null_variant() -> None:
214216
vdesc = VariantDescription()
215217
assert vdesc.properties == []
216218
assert vdesc.hexdigest == hashlib.sha256(b"").hexdigest()[:VARIANT_HASH_LENGTH]
219+
assert vdesc.label == NULL_VARIANT_LABEL
217220

218221

219222
def test_variantdescription_initialization() -> None:
@@ -224,7 +227,8 @@ def test_variantdescription_initialization() -> None:
224227
vprop2 = VariantProperty(
225228
namespace="tyrell_corporation", feature="client_id", value="secret_pass"
226229
)
227-
vdesc = VariantDescription([vprop1, vprop2])
230+
vdesc = VariantDescription([vprop1, vprop2], label="test")
231+
assert vdesc.label == "test"
228232

229233
# Check that the _data property is a list
230234
assert isinstance(vdesc.properties, list)
@@ -257,14 +261,13 @@ def test_variantdescription_duplicate_data() -> None:
257261

258262

259263
def test_variantdescription_partial_duplicate_data() -> None:
260-
# Test that duplicate VariantProperty instances are removed
261264
vprop1 = VariantProperty(
262265
namespace="omnicorp", feature="custom_feat", value="secret_value"
263266
)
264267
vprop2 = VariantProperty(
265268
namespace="omnicorp", feature="custom_feat", value="another_value"
266269
)
267-
VariantDescription([vprop1, vprop2])
270+
VariantDescription([vprop1, vprop2], label="test")
268271

269272

270273
def test_variantdescription_sorted_data() -> None:
@@ -278,7 +281,7 @@ def test_variantdescription_sorted_data() -> None:
278281
vprop3 = VariantProperty(
279282
namespace="omnicorp", feature="secret_pass", value="client_value"
280283
)
281-
vdesc = VariantDescription([vprop1, vprop2, vprop3])
284+
vdesc = VariantDescription([vprop1, vprop2, vprop3], label="test")
282285

283286
# Check that data is sorted by namespace, feature, and value
284287
sorted_vprops = sorted(
@@ -296,7 +299,7 @@ def test_variantdescription_hexdigest() -> None:
296299
namespace="tyrell_corporation", feature="client_id", value="secret_pass"
297300
)
298301
vprops = [vprop1, vprop2]
299-
vdesc = VariantDescription(vprops)
302+
vdesc = VariantDescription(vprops, label="test")
300303

301304
# Compute the expected hash using shake_128 (mock the hash output for testing)
302305
hash_object = hashlib.sha256(
@@ -314,13 +317,15 @@ def test_variantdescription_hexdigest_adjacent_strings() -> None:
314317
[
315318
VariantProperty("a", "b", "cx"),
316319
VariantProperty("d", "e", "f"),
317-
]
320+
],
321+
label="test",
318322
).hexdigest
319323
!= VariantDescription(
320324
[
321325
VariantProperty("a", "b", "c"),
322326
VariantProperty("xd", "e", "f"),
323-
]
327+
],
328+
label="another",
324329
).hexdigest
325330
)
326331

@@ -390,7 +395,7 @@ def test_fuzzy_variantprop(namespace: str, feature: str, value: str) -> None:
390395
)
391396
def test_fuzzy_variantdescription(vprop: list[VariantProperty]) -> None:
392397
# Fuzzy test for random combinations of VariantDescription
393-
vdesc = VariantDescription(vprop)
398+
vdesc = VariantDescription(vprop, label="test")
394399
assert isinstance(vdesc.properties, list)
395400
assert len(vdesc.properties) >= 1
396401

@@ -414,8 +419,23 @@ def test_fuzzy_variantdescription(vprop: list[VariantProperty]) -> None:
414419
value=st.from_regex(VALIDATION_NAMESPACE_REGEX, fullmatch=True),
415420
),
416421
),
422+
label=st.from_regex(VALIDATION_VARIANT_LABEL_REGEX, fullmatch=True),
417423
)
418424
)
419425
def test_random_hexdigest(vdesc: VariantDescription) -> None:
420426
assert isinstance(vdesc.hexdigest, str)
421427
assert len(vdesc.hexdigest) == VARIANT_HASH_LENGTH
428+
429+
430+
@pytest.mark.xfail(reason="Validation is disabled for porting")
431+
def test_null_variant_label():
432+
with pytest.raises(
433+
ValidationError,
434+
match=rf"{NULL_VARIANT_LABEL!r} label can be used only for the null variant",
435+
):
436+
VariantDescription([VariantProperty("a", "b", "c")], label=NULL_VARIANT_LABEL)
437+
with pytest.raises(
438+
ValidationError,
439+
match=rf"Null variant must always use {NULL_VARIANT_LABEL!r} label",
440+
):
441+
VariantDescription(label="zuul")

0 commit comments

Comments
 (0)