fixed edge-case of broken input handling in find_near_matches()
This commit is contained in:
parent
8b3467361d
commit
44be967e43
|
@ -68,12 +68,11 @@ def find_near_matches(subsequence, sequence,
|
|||
|
||||
# if it is enough to just take into account the maximum Levenshtein
|
||||
# distance, use find_near_matches_levenshtein()
|
||||
elif max_l_dist <= min([
|
||||
param for param in [
|
||||
max_substitutions, max_insertions, max_deletions
|
||||
]
|
||||
if param is not None
|
||||
]):
|
||||
elif max_l_dist <= min(
|
||||
(max_substitutions if max_substitutions is not None else (1 << 29)),
|
||||
(max_insertions if max_insertions is not None else (1 << 29)),
|
||||
(max_deletions if max_deletions is not None else (1 << 29)),
|
||||
):
|
||||
return find_near_matches_levenshtein(subsequence, sequence, max_l_dist)
|
||||
|
||||
# if none of the special cases above are met, use the most generic version
|
||||
|
|
|
@ -107,6 +107,15 @@ class TestFindNearMatches(unittest.TestCase):
|
|||
)
|
||||
self.assertEqual(self.mock_search_exact.call_count, 1)
|
||||
|
||||
def test_all_none_except_max_l_dist(self):
|
||||
self.mock_find_near_matches_levenshtein.return_value = [42]
|
||||
|
||||
self.assertEqual(
|
||||
find_near_matches('a', 'a', max_l_dist=1),
|
||||
[42],
|
||||
)
|
||||
self.assertEqual(self.mock_find_near_matches_levenshtein.call_count, 1)
|
||||
|
||||
def test_levenshtein(self):
|
||||
"""test cases where 0 < max_l_dist <= max(others)"""
|
||||
# in these cases, find_near_matches should call
|
||||
|
|
Loading…
Reference in New Issue