X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/4774e45218bcfcef3390f820ad48b1b67b2bd0c4..2bab0ca060ff224091b20a0ac808a3febaba04b1:/test/python/tokenizer/sanitizers/test_clean_housenumbers.py diff --git a/test/python/tokenizer/sanitizers/test_clean_housenumbers.py b/test/python/tokenizer/sanitizers/test_clean_housenumbers.py index 5784619b..01fb162b 100644 --- a/test/python/tokenizer/sanitizers/test_clean_housenumbers.py +++ b/test/python/tokenizer/sanitizers/test_clean_housenumbers.py @@ -1,26 +1,26 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2022 by the Nominatim developer community. +# Copyright (C) 2024 by the Nominatim developer community. # For a full list of authors see the git log. """ Tests for the sanitizer that normalizes housenumbers. """ import pytest -from nominatim.tokenizer.place_sanitizer import PlaceSanitizer -from nominatim.indexer.place_info import PlaceInfo +from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer +from nominatim_db.data.place_info import PlaceInfo @pytest.fixture -def sanitize(request): +def sanitize(request, def_config): sanitizer_args = {'step': 'clean-housenumbers'} for mark in request.node.iter_markers(name="sanitizer_params"): sanitizer_args.update({k.replace('_', '-') : v for k,v in mark.kwargs.items()}) def _run(**kwargs): place = PlaceInfo({'address': kwargs}) - _, address = PlaceSanitizer([sanitizer_args]).process_names(place) + _, address = PlaceSanitizer([sanitizer_args], def_config).process_names(place) return sorted([(p.kind, p.name) for p in address]) @@ -42,3 +42,27 @@ def test_housenumber_lists(sanitize, number): def test_filter_kind(sanitize): assert sanitize(housenumber='34', number='4', badnumber='65') == \ [('badnumber', '65'), ('housenumber', '34'), ('housenumber', '4')] + + +@pytest.mark.parametrize('number', ('6523', 'n/a', '4')) +def test_convert_to_name_converted(def_config, number): + sanitizer_args = {'step': 'clean-housenumbers', + 'convert-to-name': (r'\d+', 'n/a')} + + place = PlaceInfo({'address': {'housenumber': number}}) + names, address = PlaceSanitizer([sanitizer_args], def_config).process_names(place) + + assert ('housenumber', number) in set((p.kind, p.name) for p in names) + assert 'housenumber' not in set(p.kind for p in address) + + +@pytest.mark.parametrize('number', ('a54', 'n.a', 'bow')) +def test_convert_to_name_unconverted(def_config, number): + sanitizer_args = {'step': 'clean-housenumbers', + 'convert-to-name': (r'\d+', 'n/a')} + + place = PlaceInfo({'address': {'housenumber': number}}) + names, address = PlaceSanitizer([sanitizer_args], def_config).process_names(place) + + assert 'housenumber' not in set(p.kind for p in names) + assert ('housenumber', number) in set((p.kind, p.name) for p in address)