1212
1313libraries = prototype .clone ()
1414
15+ # numpy throws a bunch of warning about abydos using `np.int` isntead of `int`.
16+ ABYDOS_WARNINGS = (
17+ 'ignore:`np.int` is a deprecated alias' ,
18+ 'ignore:`np.float` is a deprecated alias' ,
19+ 'ignore:Using or importing the ABCs' ,
20+ )
21+
1522
23+ @pytest .mark .filterwarnings (* ABYDOS_WARNINGS )
1624@pytest .mark .external
1725@pytest .mark .parametrize ('alg' , libraries .get_algorithms ())
1826@hypothesis .settings (deadline = None )
@@ -37,34 +45,40 @@ def test_compare(left, right, alg):
3745 assert isclose (int_result , ext_result ), str (lib )
3846
3947
48+ @pytest .mark .filterwarnings (* ABYDOS_WARNINGS )
4049@pytest .mark .external
4150@pytest .mark .parametrize ('alg' , libraries .get_algorithms ())
4251@hypothesis .given (
4352 left = hypothesis .strategies .text (min_size = 1 ),
4453 right = hypothesis .strategies .text (min_size = 1 ),
4554)
46- def test_qval (left , right , alg ):
55+ @pytest .mark .parametrize ('qval' , (None , 1 , 2 , 3 ))
56+ def test_qval (left , right , alg , qval ):
4757 for lib in libraries .get_libs (alg ):
4858 conditions = lib .conditions or {}
4959 internal_func = getattr (textdistance , alg )(external = False , ** conditions )
5060 external_func = lib .get_function ()
5161 # algorithm doesn't support q-grams
5262 if not hasattr (internal_func , 'qval' ):
5363 continue
54- for qval in (None , 1 , 2 , 3 ):
55- internal_func .qval = qval
56- # if qval unsopporting already set for lib
57- s1 , s2 = internal_func ._get_sequences (left , right )
58- if not lib .check_conditions (internal_func , s1 , s2 ):
59- continue
60-
61- # test
62- int_result = internal_func (left , right )
63- s1 , s2 = lib .prepare (s1 , s2 )
64- ext_result = external_func (s1 , s2 )
65- assert isclose (int_result , ext_result ), str (lib )
6664
65+ internal_func .qval = qval
66+ # if qval unsopporting already set for lib
67+ s1 , s2 = internal_func ._get_sequences (left , right )
68+ if not lib .check_conditions (internal_func , s1 , s2 ):
69+ continue
70+ quick_answer = internal_func .quick_answer (s1 , s2 )
71+ if quick_answer is not None :
72+ continue
6773
74+ # test
75+ int_result = internal_func (left , right )
76+ s1 , s2 = lib .prepare (s1 , s2 )
77+ ext_result = external_func (s1 , s2 )
78+ assert isclose (int_result , ext_result ), f'{ lib } ({ repr (s1 )} , { repr (s2 )} )'
79+
80+
81+ @pytest .mark .filterwarnings (* ABYDOS_WARNINGS )
6882@pytest .mark .external
6983@pytest .mark .parametrize ('alg' , libraries .get_algorithms ())
7084@hypothesis .given (
@@ -79,10 +93,13 @@ def test_list_of_numbers(left, right, alg):
7993 if external_func is None :
8094 raise RuntimeError ('cannot import {}' .format (str (lib )))
8195
96+ quick_answer = internal_func .quick_answer (left , right )
97+ if quick_answer is not None :
98+ continue
8299 if not lib .check_conditions (internal_func , left , right ):
83100 continue
84101
85102 int_result = internal_func (left , right )
86103 s1 , s2 = lib .prepare (left , right )
87104 ext_result = external_func (s1 , s2 )
88- assert isclose (int_result , ext_result ), str ( lib )
105+ assert isclose (int_result , ext_result ), f' { lib } ( { repr ( s1 ) } , { repr ( s2 ) } )'
0 commit comments