Skip to content

Commit cc5fa23

Browse files
committed
fix custom processors in fuzz.*
1 parent fa17ff9 commit cc5fa23

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.14.0
1+
0.14.1

src/py_abstraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static inline PyObject* fuzz_call(bool processor_default, PyObject* args, PyObje
9595
}
9696

9797
if (non_default_process(processor)) {
98-
PyObject* proc_s1 = PyObject_CallFunctionObjArgs(processor, py_s2, NULL);
98+
PyObject* proc_s1 = PyObject_CallFunctionObjArgs(processor, py_s1, NULL);
9999
if (proc_s1 == NULL) {
100100
return NULL;
101101
}

src/rapidfuzz-cpp

Submodule rapidfuzz-cpp updated from 0282536 to 3917c16

src/rapidfuzz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"""
44
__author__ = "Max Bachmann"
55
__license__ = "MIT"
6-
__version__ = "0.14.0"
6+
__version__ = "0.14.1"
77

88
from rapidfuzz import process, fuzz, utils, levenshtein

tests/test_fuzz.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
import unittest
5+
import pytest
56

67
from rapidfuzz import process, fuzz, utils
78

@@ -19,31 +20,27 @@
1920
]
2021

2122
class RatioTest(unittest.TestCase):
22-
def setUp(self):
23-
self.s1 = "new york mets"
24-
self.s1a = "new york mets"
25-
self.s2 = "new YORK mets"
26-
self.s3 = "the wonderful new york mets"
27-
self.s4 = "new york mets vs atlanta braves"
28-
self.s5 = "atlanta braves vs new york mets"
29-
self.s6 = "new york mets - atlanta braves"
30-
31-
def testEqual(self):
32-
self.assertEqual(fuzz.ratio(self.s1, self.s1a),100)
33-
34-
def testCaseInsensitive(self):
35-
self.assertNotEqual(fuzz.ratio(self.s1, self.s2),100)
36-
self.assertEqual(fuzz.ratio(self.s1, self.s2, processor=True),100)
23+
s1 = "new york mets"
24+
s1a = "new york mets"
25+
s2 = "new YORK mets"
26+
s3 = "the wonderful new york mets"
27+
s4 = "new york mets vs atlanta braves"
28+
s5 = "atlanta braves vs new york mets"
29+
s6 = "new york mets - atlanta braves"
30+
31+
def testNoProcessor(self):
32+
self.assertEqual(fuzz.ratio(self.s1, self.s1a), 100)
33+
self.assertNotEqual(fuzz.ratio(self.s1, self.s2), 100)
3734

3835
def testPartialRatio(self):
39-
self.assertEqual(fuzz.partial_ratio(self.s1, self.s3),100)
36+
self.assertEqual(fuzz.partial_ratio(self.s1, self.s3), 100)
4037

4138
def testTokenSortRatio(self):
42-
self.assertEqual(fuzz.token_sort_ratio(self.s1, self.s1a),100)
39+
self.assertEqual(fuzz.token_sort_ratio(self.s1, self.s1a), 100)
4340

4441
def testPartialTokenSortRatio(self):
45-
self.assertEqual(fuzz.partial_token_sort_ratio(self.s1, self.s1a),100)
46-
self.assertEqual(fuzz.partial_token_sort_ratio(self.s4, self.s5),100)
42+
self.assertEqual(fuzz.partial_token_sort_ratio(self.s1, self.s1a), 100)
43+
self.assertEqual(fuzz.partial_token_sort_ratio(self.s4, self.s5), 100)
4744

4845
def testTokenSetRatio(self):
4946
self.assertEqual(fuzz.token_set_ratio(self.s4, self.s5),100)
@@ -100,27 +97,34 @@ def testQRatioUnicodeString(self):
10097
score = fuzz.QRatio(s1, s2)
10198
self.assertEqual(0, score)
10299

103-
def testWithProcessor(self):
104-
"""
105-
Any scorer should accept any type as s1 and s2, as long as it is a string
106-
after preprocessing.
107-
"""
108-
s1 = ["chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm"]
109-
s2 = ["chicago cubs vs new york mets", "CitiFields", "2012-05-11", "9pm"]
110-
111-
for scorer in scorers:
112-
score = scorer(s1, s2, processor=lambda event: event[0])
113-
self.assertEqual(score, 100)
114-
115-
def testHelp(self):
116-
"""
117-
test that all help texts can be printed without throwing an exception,
118-
since they are implemented in C++ aswell
119-
"""
120-
121-
for scorer in scorers:
122-
help(scorer)
123100

101+
@pytest.mark.parametrize("processor", [True, utils.default_process, lambda s: utils.default_process(s)])
102+
def testRatioCaseInsensitive(processor):
103+
assert fuzz.ratio(RatioTest.s1, RatioTest.s2, processor=processor) == 100
104+
105+
@pytest.mark.parametrize("processor", [False, None, lambda s: s])
106+
def testRatioNotCaseInsensitive(processor):
107+
assert fuzz.ratio(RatioTest.s1, RatioTest.s2, processor=processor) != 100
108+
109+
@pytest.mark.parametrize("scorer", scorers)
110+
def testCustomProcessor(scorer):
111+
"""
112+
Any scorer should accept any type as s1 and s2, as long as it is a string
113+
after preprocessing.
114+
"""
115+
s1 = ["chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm"]
116+
s2 = ["chicago cubs vs new york mets", "CitiFields", "2012-05-11", "9pm"]
117+
s3 = ["different string", "CitiFields", "2012-05-11", "9pm"]
118+
assert scorer(s1, s2, processor=lambda event: event[0]) == 100
119+
assert scorer(s2, s3, processor=lambda event: event[0]) != 100
120+
121+
@pytest.mark.parametrize("scorer", scorers)
122+
def testHelp(scorer):
123+
"""
124+
test that all help texts can be printed without throwing an exception,
125+
since they are implemented in C++ aswell
126+
"""
127+
help(scorer)
124128

125129
if __name__ == '__main__':
126130
unittest.main()

0 commit comments

Comments
 (0)