Remove hamming option from string distance tests (#9882)

Description: We should not test Hamming string distance for strings that
are not equal length, since this is not defined. Removing hamming
distance tests for unequal string distances.
This commit is contained in:
m3n3235 2023-09-11 13:50:20 -07:00 committed by GitHub
parent e6b7d9f65b
commit 2bd9f5da7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,8 +56,13 @@ async def test_zero_distance_pairwise_async(distance: StringDistance) -> None:
assert result["score"] == 0 assert result["score"] == 0
valid_distances = [
distance for distance in StringDistance if distance != StringDistance.HAMMING
]
@pytest.mark.requires("rapidfuzz") @pytest.mark.requires("rapidfuzz")
@pytest.mark.parametrize("distance", list(StringDistance)) @pytest.mark.parametrize("distance", valid_distances)
@pytest.mark.parametrize("normalize_score", [True, False]) @pytest.mark.parametrize("normalize_score", [True, False])
def test_non_zero_distance(distance: StringDistance, normalize_score: bool) -> None: def test_non_zero_distance(distance: StringDistance, normalize_score: bool) -> None:
eval_chain = StringDistanceEvalChain( eval_chain = StringDistanceEvalChain(
@ -74,7 +79,7 @@ def test_non_zero_distance(distance: StringDistance, normalize_score: bool) -> N
@pytest.mark.asyncio @pytest.mark.asyncio
@pytest.mark.requires("rapidfuzz") @pytest.mark.requires("rapidfuzz")
@pytest.mark.parametrize("distance", list(StringDistance)) @pytest.mark.parametrize("distance", valid_distances)
async def test_non_zero_distance_async(distance: StringDistance) -> None: async def test_non_zero_distance_async(distance: StringDistance) -> None:
eval_chain = StringDistanceEvalChain(distance=distance) eval_chain = StringDistanceEvalChain(distance=distance)
prediction = "I like to eat apples." prediction = "I like to eat apples."
@ -87,7 +92,7 @@ async def test_non_zero_distance_async(distance: StringDistance) -> None:
@pytest.mark.requires("rapidfuzz") @pytest.mark.requires("rapidfuzz")
@pytest.mark.parametrize("distance", list(StringDistance)) @pytest.mark.parametrize("distance", valid_distances)
def test_non_zero_distance_pairwise(distance: StringDistance) -> None: def test_non_zero_distance_pairwise(distance: StringDistance) -> None:
eval_chain = PairwiseStringDistanceEvalChain(distance=distance) eval_chain = PairwiseStringDistanceEvalChain(distance=distance)
prediction = "I like to eat apples." prediction = "I like to eat apples."
@ -101,7 +106,7 @@ def test_non_zero_distance_pairwise(distance: StringDistance) -> None:
@pytest.mark.asyncio @pytest.mark.asyncio
@pytest.mark.requires("rapidfuzz") @pytest.mark.requires("rapidfuzz")
@pytest.mark.parametrize("distance", list(StringDistance)) @pytest.mark.parametrize("distance", valid_distances)
async def test_non_zero_distance_pairwise_async(distance: StringDistance) -> None: async def test_non_zero_distance_pairwise_async(distance: StringDistance) -> None:
eval_chain = PairwiseStringDistanceEvalChain(distance=distance) eval_chain = PairwiseStringDistanceEvalChain(distance=distance)
prediction = "I like to eat apples." prediction = "I like to eat apples."