from pathlib import Path
import pytest
import ferro_hgvs
_VALID_HGVS = "NM_000088.3:c.4C>G"
_ANY_DIRECTION_VALUE = [
"3prime",
"5prime",
"3",
"5",
"3'",
"5'",
"3PRIME",
"5Prime",
"5prim",
"five",
"3prine",
"",
"left",
"threeprime",
"sideways",
]
_UNEXPECTED_KWARG = "unexpected keyword argument 'direction'|takes no keyword arguments"
class TestNormalizerConstructor:
@pytest.mark.parametrize("direction", _ANY_DIRECTION_VALUE)
def test_direction_keyword_rejected(self, direction: str) -> None:
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.Normalizer(direction=direction)
def test_constructs_without_the_keyword(self) -> None:
ferro_hgvs.Normalizer()
class TestModuleLevelNormalize:
@pytest.mark.parametrize("direction", _ANY_DIRECTION_VALUE)
def test_direction_keyword_rejected(self, direction: str) -> None:
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.normalize(_VALID_HGVS, direction=direction)
def test_normalizes_without_the_keyword(self) -> None:
result = ferro_hgvs.normalize(_VALID_HGVS)
assert isinstance(result, str)
assert result
class TestHgvsVariantNormalize:
@pytest.mark.parametrize("direction", _ANY_DIRECTION_VALUE)
def test_direction_keyword_rejected(self, direction: str) -> None:
variant = ferro_hgvs.parse(_VALID_HGVS)
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
variant.normalize(direction=direction)
def test_normalizes_without_the_keyword(self) -> None:
variant = ferro_hgvs.parse(_VALID_HGVS)
result = variant.normalize()
assert str(result)
class TestVariantProjectorConstructor:
@pytest.mark.parametrize("direction", _ANY_DIRECTION_VALUE)
def test_direction_keyword_rejected(self, direction: str) -> None:
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.VariantProjector(direction=direction)
def test_constructs_without_the_keyword(self) -> None:
ferro_hgvs.VariantProjector()
MANIFEST_TINY = (
Path(__file__).parent.parent / "fixtures" / "python" / "manifest_tiny" / "manifest.json"
)
class TestFromManifestDirection:
@pytest.mark.parametrize("direction", _ANY_DIRECTION_VALUE)
def test_normalizer_from_manifest_rejects(self, direction: str) -> None:
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.Normalizer.from_manifest(str(MANIFEST_TINY), direction=direction)
@pytest.mark.parametrize("direction", _ANY_DIRECTION_VALUE)
def test_projector_from_manifest_rejects(self, direction: str) -> None:
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.VariantProjector.from_manifest(str(MANIFEST_TINY), direction=direction)
def test_normalizer_from_manifest_loads_without_the_keyword(self) -> None:
ferro_hgvs.Normalizer.from_manifest(str(MANIFEST_TINY))
class TestFromSequencesEntryPoints:
@pytest.mark.parametrize("direction", ["3prime", "5prime"])
def test_free_from_sequences_rejects(self, direction: str) -> None:
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.from_sequences("NC_000001.11", 100, "A", "AT", direction=direction)
@pytest.mark.parametrize("direction", ["3prime", "5prime"])
def test_free_from_sequences_detailed_rejects(self, direction: str) -> None:
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.from_sequences_detailed("NC_000001.11", 100, "A", "AT", direction=direction)
def test_free_from_sequences_works_without_the_keyword(self) -> None:
assert str(ferro_hgvs.from_sequences("NC_000001.11", 100, "A", "AT"))
class TestDirectionRejectedBeforeReferenceLoad:
def test_normalizer_new_bad_json_and_direction(self, tmp_path: Path) -> None:
missing = tmp_path / "does_not_exist.json"
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.Normalizer(reference_json=str(missing), direction="5prime")
def test_normalizer_from_manifest_bad_path_and_direction(self, tmp_path: Path) -> None:
missing = tmp_path / "does_not_exist.json"
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.Normalizer.from_manifest(str(missing), direction="5prime")
def test_projector_new_bad_json_and_direction(self, tmp_path: Path) -> None:
missing = tmp_path / "does_not_exist.json"
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.VariantProjector(reference_json=str(missing), direction="5prime")
def test_projector_from_manifest_bad_path_and_direction(self, tmp_path: Path) -> None:
missing = tmp_path / "does_not_exist.json"
with pytest.raises(TypeError, match=_UNEXPECTED_KWARG):
ferro_hgvs.VariantProjector.from_manifest(str(missing), direction="5prime")
def test_projector_bad_assembly_validated_before_bad_path(self, tmp_path: Path) -> None:
missing = tmp_path / "does_not_exist.json"
with pytest.raises(ValueError, match="unrecognized assembly"):
ferro_hgvs.VariantProjector.from_manifest(str(missing), assembly="bogus")