mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 04:15:09 +00:00
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
import pytest
|
|
|
|
from unshackle.core.providers import fuzzy_match
|
|
from unshackle.core.providers._base import clean, title_ratio
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("title", "expected"),
|
|
[
|
|
("The Matrix (1999)", "thematrix1999"),
|
|
("Spider-Man: No Way Home", "spidermannowayhome"),
|
|
("Léon", "leon"),
|
|
("Straße", "strasse"),
|
|
("XYZ 12", "xyz12"),
|
|
("进击的巨人", "进击的巨人"),
|
|
("Брат 2", "брат2"),
|
|
("İstanbul", "istanbul"),
|
|
("Title™", "titletm"),
|
|
("사랑의 불시착", "사랑의불시착"),
|
|
("がっこうぐらし", "がっこうぐらし"),
|
|
("เป็นต่อ", "เป็นต่อ"),
|
|
("진격의 거인", "진격의거인"),
|
|
("進撃の巨人", "進撃の巨人"),
|
|
],
|
|
)
|
|
def test_clean_keeps_letters_and_digits_of_every_script(title: str, expected: str) -> None:
|
|
assert clean(title) == expected
|
|
|
|
|
|
@pytest.mark.parametrize("title", ["เป็นต่อ", "हिंदी", "进击的巨人", "Война и мир", "The Matrix"])
|
|
def test_fuzzy_match_a_title_with_itself(title: str) -> None:
|
|
assert fuzzy_match(title, title)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("a", "b"),
|
|
[
|
|
("เป็นต่อ", "हिंदी"),
|
|
("进击的巨人", "鬼灭之刃"),
|
|
("Война и мир", "Преступление и наказание"),
|
|
("เป็นต่อ", "The Matrix"),
|
|
("사랑", "사람"),
|
|
("슬기로운 의사생활", "슬기로운 감빵생활"),
|
|
("がっこうぐらし", "かっこうくらし"),
|
|
("ガンダム", "カンタム"),
|
|
("कहानी", "कहना"),
|
|
],
|
|
)
|
|
def test_fuzzy_match_rejects_different_non_latin_titles(a: str, b: str) -> None:
|
|
assert not fuzzy_match(a, b)
|
|
|
|
|
|
@pytest.mark.parametrize(("a", "b"), [("!!!", "!!!"), ("", ""), ("---", "The Matrix")])
|
|
def test_a_title_with_no_letters_or_digits_matches_nothing(a: str, b: str) -> None:
|
|
assert title_ratio(a, b) == 0.0
|
|
assert not fuzzy_match(a, b)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("a", "b", "expected"),
|
|
[
|
|
("The Matrix", "the matrix", True),
|
|
("Spider-Man: No Way Home", "Spider Man No Way Home", True),
|
|
("Leon", "Léon", True),
|
|
("The Matrix", "The Godfather", False),
|
|
],
|
|
)
|
|
def test_fuzzy_match_latin_titles(a: str, b: str, expected: bool) -> None:
|
|
assert fuzzy_match(a, b) is expected
|