diff --git a/tests/test_external.py b/tests/test_external.py index 14e5b20..cd7fddb 100644 --- a/tests/test_external.py +++ b/tests/test_external.py @@ -1,8 +1,12 @@ +from __future__ import annotations + # built-in +import string from math import isclose # external import hypothesis +import hypothesis.strategies import pytest # project @@ -22,6 +26,12 @@ ) def test_compare(left, right, alg): for lib in libraries.get_libs(alg): + + if lib.module_name == 'jellyfish': + ascii = set(string.printable) + if (set(left) | set(right)) - ascii: + continue + conditions = lib.conditions or {} internal_func = getattr(textdistance, alg)(external=False, **conditions) external_func = lib.get_function() @@ -44,8 +54,14 @@ def test_compare(left, right, alg): right=hypothesis.strategies.text(min_size=1), ) @pytest.mark.parametrize('qval', (None, 1, 2, 3)) -def test_qval(left, right, alg, qval): +def test_qval(left: str, right: str, alg: str, qval: int | None) -> None: for lib in libraries.get_libs(alg): + + if lib.module_name == 'jellyfish': + ascii = set(string.printable) + if (set(left) | set(right)) - ascii: + continue + conditions = lib.conditions or {} internal_func = getattr(textdistance, alg)(external=False, **conditions) external_func = lib.get_function() diff --git a/textdistance/libraries.py b/textdistance/libraries.py index a0b9c16..23d9393 100644 --- a/textdistance/libraries.py +++ b/textdistance/libraries.py @@ -39,12 +39,12 @@ def optimize(self) -> None: # sort libs by speed self.libs[alg].sort(key=lambda lib: libs_names.index([lib.module_name, lib.func_name])) - def get_algorithms(self) -> list: + def get_algorithms(self) -> list[str]: """Get list of available algorithms. """ return list(self.libs.keys()) - def get_libs(self, alg) -> list[LibraryBase]: + def get_libs(self, alg: str) -> list[LibraryBase]: """Get libs list for algorithm """ if alg not in self.libs: @@ -69,7 +69,7 @@ def __init__( *, presets: dict[str, Any] | None = None, attr: str | None = None, - conditions: dict[str, Any] | None = None, + conditions: dict[str, bool] | None = None, ) -> None: self.module_name = module_name self.func_name = func_name @@ -89,7 +89,7 @@ def check_conditions(self, obj: object, *sequences: Sequence) -> bool: return True - def prepare(self, *sequences) -> tuple: + def prepare(self, *sequences: Sequence) -> tuple: return sequences @property @@ -128,7 +128,7 @@ def __str__(self) -> str: class TextLibrary(LibraryBase): - def check_conditions(self, obj, *sequences: Sequence) -> bool: + def check_conditions(self, obj: object, *sequences: Sequence) -> bool: if not super().check_conditions(obj, *sequences): return False @@ -142,7 +142,7 @@ def check_conditions(self, obj, *sequences: Sequence) -> bool: return False return True - def prepare(self, *sequences) -> tuple: + def prepare(self, *sequences: Sequence) -> tuple: # convert list of letters to string if isinstance(sequences[0], (tuple, list)): sequences = tuple(map(lambda x: ''.join(x), sequences)) @@ -150,7 +150,7 @@ def prepare(self, *sequences) -> tuple: class SameLengthLibrary(LibraryBase): - def check_conditions(self, obj, *sequences: Sequence) -> bool: + def check_conditions(self, obj: object, *sequences: Sequence) -> bool: if not super().check_conditions(obj, *sequences): return False # compare only same length iterators