from __future__ import annotations
import json
from pathlib import Path
import ferro_hgvs
MT_ACCESSION = "NC_012920.1"
CONTIG_LENGTH = 100
def _reference_json(tmp_path: Path) -> str:
payload = {
"transcripts": [],
"proteins": {},
"genomic_sequences": {MT_ACCESSION: "A" * CONTIG_LENGTH},
}
path = tmp_path / "ref.json"
path.write_text(json.dumps(payload))
return str(path)
def test_get_sequence_length_forwarded_mt_past_end_warns(tmp_path: Path) -> None:
norm = ferro_hgvs.Normalizer(reference_json=_reference_json(tmp_path))
result = norm.normalize_with_warnings(f"{MT_ACCESSION}:m.150A>G")
codes = [w.code for w in result.warnings]
assert "POSITION_PAST_END" in codes, (
f"expected a POSITION_PAST_END (W4004) warning once the contig length is "
f"available via the forwarded get_sequence_length; got {codes}"
)
def test_in_bounds_mt_position_does_not_warn(tmp_path: Path) -> None:
norm = ferro_hgvs.Normalizer(reference_json=_reference_json(tmp_path))
result = norm.normalize_with_warnings(f"{MT_ACCESSION}:m.50A>G")
codes = [w.code for w in result.warnings]
assert "POSITION_PAST_END" not in codes, (
f"an in-bounds m. position must not emit POSITION_PAST_END; got {codes}"
)