Skip to content

Commit

Permalink
skip unicode tests for jellyfish
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Sep 28, 2023
1 parent 82cef66 commit e66149f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 17 additions & 1 deletion tests/test_external.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions textdistance/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -142,15 +142,15 @@ 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))
return sequences


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
Expand Down

0 comments on commit e66149f

Please sign in to comment.