import warnings
import ferro_hgvs
COALESCING_INPUT = "NP_000079.2:p.[Ala100Gly;Ala101Gly]"
COALESCED_OUTPUT = "NP_000079.2:p.Ala100_Ala101delinsGlyGly"
CLEAN_INPUT = "NM_000088.3:c.4C>G"
def _normalize_with_warnings(variant: str):
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
return ferro_hgvs.normalize_with_warnings(variant)
def _normalize(variant: str) -> str:
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
return ferro_hgvs.normalize(variant)
class TestFreeFunctionNormalizeWithWarnings:
def test_the_coalesce_provenance_reaches_the_caller(self) -> None:
result = _normalize_with_warnings(COALESCING_INPUT)
assert str(result.result) == COALESCED_OUTPUT, (
"precondition: this input must actually coalesce"
)
assert [w.code for w in result.warnings] == ["MEMBERS_COALESCED_FROM_REPORTED_FORM"]
assert result.has_warnings() is True
message = result.warnings[0].message
assert "input described 2 cis members" in message, message
assert "normalized form describes 1" in message, message
assert "not recoverable from the normalized string" in message, message
def test_the_string_is_identical_to_the_quiet_entry_point(self) -> None:
for variant in (COALESCING_INPUT, CLEAN_INPUT):
quiet = _normalize(variant)
loud = _normalize_with_warnings(variant)
assert quiet == str(loud.result), (
f"the warning-bearing exit moved the string for {variant}"
)
def test_a_clean_input_reports_nothing(self) -> None:
result = _normalize_with_warnings(CLEAN_INPUT)
assert result.warnings == []
assert result.has_warnings() is False
assert str(result.result) == CLEAN_INPUT
def test_it_is_exported_from_the_package(self) -> None:
assert "normalize_with_warnings" in ferro_hgvs.__all__
assert "NormalizeResultWithWarnings" in ferro_hgvs.__all__
assert callable(ferro_hgvs.normalize_with_warnings)