clean_housenumbers: make kinds and delimiters configurable

Also adds unit tests for various options.
This commit is contained in:
Sarah Hoffmann
2022-01-20 12:07:12 +01:00
parent 206ee87188
commit 4774e45218
7 changed files with 133 additions and 20 deletions

View File

@@ -0,0 +1,43 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# This file is part of Nominatim. (https://nominatim.org)
#
# Copyright (C) 2022 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for sanitizer helper functions.
"""
import pytest
from nominatim.errors import UsageError
import nominatim.tokenizer.sanitizers.helpers as helpers
@pytest.mark.parametrize('inp', ('fg34', 'f\\f', 'morning [glory]', '56.78'))
def test_create_split_regex_no_params_unsplit(inp):
regex = helpers.create_split_regex({})
assert list(regex.split(inp)) == [inp]
@pytest.mark.parametrize('inp,outp', [('here,there', ['here', 'there']),
('ying;;yang', ['ying', 'yang']),
(';a; ;c;d,', ['', 'a', '', 'c', 'd', '']),
('1, 3 ,5', ['1', '3', '5'])
])
def test_create_split_regex_no_params_split(inp, outp):
regex = helpers.create_split_regex({})
assert list(regex.split(inp)) == outp
@pytest.mark.parametrize('delimiter', ['.', '\\', '[]', ' ', '/.*+'])
def test_create_split_regex_custom(delimiter):
regex = helpers.create_split_regex({'delimiters': delimiter})
assert list(regex.split(f'out{delimiter}house')) == ['out', 'house']
assert list(regex.split('out,house')) == ['out,house']
def test_create_split_regex_empty_delimiter():
with pytest.raises(UsageError):
regex = helpers.create_split_regex({'delimiters': ''})