Cover matcher and API scenarios
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.aliases import ProductAliasIndex
|
||||
from app.normalization import normalize_text
|
||||
from app.typo import damerau_levenshtein_distance, word_similarity
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "expected"),
|
||||
[
|
||||
("Шуруповёрт", "шуруповерт"),
|
||||
("3,5 × 25", "3.5x25"),
|
||||
("4.2 х 75", "4.2x75"),
|
||||
("М10", "m10"),
|
||||
("Р120", "p120"),
|
||||
],
|
||||
)
|
||||
def test_basic_canonicalization(source: str, expected: str) -> None:
|
||||
assert normalize_text(source) == expected
|
||||
|
||||
|
||||
def test_cyrillic_x_is_not_replaced_inside_words() -> None:
|
||||
assert normalize_text("хомут находится") == "хомут находится"
|
||||
|
||||
|
||||
def test_damerau_counts_adjacent_transposition_as_one_edit() -> None:
|
||||
assert damerau_levenshtein_distance("шуруповерт", "шурпуоверт") == 1
|
||||
|
||||
|
||||
def test_heavily_damaged_product_word_still_has_useful_score() -> None:
|
||||
assert word_similarity("шураывваверт", "шуруповерт") > 0.53
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("query", "canonical"),
|
||||
[
|
||||
("болгарка на 230", "ушм"),
|
||||
("шурик на 12в", "шуруповерт"),
|
||||
("пластиковые хомуты 4.8х400", "стяжка"),
|
||||
("шурпуоверт", "шуруповерт"),
|
||||
("шураыввавёрт", "шуруповерт"),
|
||||
],
|
||||
)
|
||||
def test_alias_and_typo_detection(query: str, canonical: str) -> None:
|
||||
match = ProductAliasIndex().detect(query)
|
||||
assert match is not None
|
||||
assert match.canonical == canonical
|
||||
Reference in New Issue
Block a user