Skip to content

Commit 32993fe

Browse files
ameynertclaude
andcommitted
test: add error-path tests for malformed Haplotype variant strings
Add three tests covering ValueError propagation when parsed_variants() receives an empty string or a variant token with fewer than 4 colon- delimited fields, and that contig() surfaces the same error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c08c96e commit 32993fe

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

divref/tests/tools/test_remap_divref.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from typing import Any
44

5+
import pytest
6+
57
from divref.tools.remap_divref import Haplotype
68
from divref.tools.remap_divref import ReferenceMapping
79
from divref.tools.remap_divref import Variant
@@ -279,3 +281,29 @@ def test_parse_pop_freqs_nulls_become_zero() -> None:
279281

280282
def test_parse_pop_freqs_single_null() -> None:
281283
assert _parse_pop_freqs("null") == [0.0]
284+
285+
286+
# ---------------------------------------------------------------------------
287+
# Error paths: malformed variant strings
288+
# ---------------------------------------------------------------------------
289+
290+
291+
def test_parsed_variants_empty_string_raises() -> None:
292+
# variants="" yields one empty token which cannot be split into 4 fields.
293+
hap = create_haplotype(variants="", n_variants=0)
294+
with pytest.raises(ValueError):
295+
hap.parsed_variants()
296+
297+
298+
def test_parsed_variants_too_few_fields_raises() -> None:
299+
# "chr1:100:A" has only 3 colon-delimited fields; unpacking into 4 raises ValueError.
300+
hap = create_haplotype(variants="chr1:100:A", n_variants=1)
301+
with pytest.raises(ValueError):
302+
hap.parsed_variants()
303+
304+
305+
def test_contig_malformed_variants_raises() -> None:
306+
# contig() delegates to parsed_variants(), so a malformed string propagates the error.
307+
hap = create_haplotype(variants="", n_variants=0)
308+
with pytest.raises(ValueError):
309+
hap.contig()

0 commit comments

Comments
 (0)