import json
import ferro_hgvs
def _make_reference_json(tmp_path, contig: str, start_1based: int, bases: str) -> str:
seq = ["A"] * max(2000, start_1based + len(bases) + 200)
for i, b in enumerate(bases):
seq[start_1based - 1 + i] = b
payload = {
"transcripts": [],
"proteins": {},
"genomic_sequences": {contig: "".join(seq)},
}
path = tmp_path / "ref.json"
path.write_text(json.dumps(payload))
return str(path)
class TestNormalizeWithWarnings:
def test_normalize_with_warnings_returns_result_and_warnings(self) -> None:
normalizer = ferro_hgvs.Normalizer()
result = normalizer.normalize_with_warnings("NM_000088.3:c.4C>G")
assert result.has_warnings() is False
assert result.warnings == []
assert str(result.result) == "NM_000088.3:c.4C>G"
def test_normalize_with_warnings_surfaces_overlap_conflict(self, tmp_path) -> None:
ref = _make_reference_json(tmp_path, "NC_000001.11", 100, "A")
normalizer = ferro_hgvs.Normalizer(reference_json=ref)
result = normalizer.normalize_with_warnings("NC_000001.11:g.[100A>C;100A>G]")
codes = [w.code for w in result.warnings]
assert "OVERLAP_CONFLICTING_EDITS" in codes, (
f"expected OVERLAP_CONFLICTING_EDITS in warnings; got {codes}"
)
assert result.has_warnings() is True
def test_normalization_warning_has_code_and_message(self, tmp_path) -> None:
ref = _make_reference_json(tmp_path, "NC_000001.11", 100, "A")
normalizer = ferro_hgvs.Normalizer(reference_json=ref)
result = normalizer.normalize_with_warnings("NC_000001.11:g.[100A>C;100A>G]")
assert len(result.warnings) > 0
w = result.warnings[0]
assert isinstance(w.code, str) and len(w.code) > 0
assert isinstance(w.message, str) and len(w.message) > 0
repr_str = repr(w)
assert w.code in repr_str