]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tokenizer/sanitizers/test_clean_housenumbers.py
clean_housenumbers: make kinds and delimiters configurable
[nominatim.git] / test / python / tokenizer / sanitizers / test_clean_housenumbers.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for the sanitizer that normalizes housenumbers.
9 """
10 import pytest
11
12 from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim.indexer.place_info import PlaceInfo
14
15 @pytest.fixture
16 def sanitize(request):
17     sanitizer_args = {'step': 'clean-housenumbers'}
18     for mark in request.node.iter_markers(name="sanitizer_params"):
19         sanitizer_args.update({k.replace('_', '-') : v for k,v in mark.kwargs.items()})
20
21     def _run(**kwargs):
22         place = PlaceInfo({'address': kwargs})
23         _, address = PlaceSanitizer([sanitizer_args]).process_names(place)
24
25         return sorted([(p.kind, p.name) for p in address])
26
27     return _run
28
29
30 def test_simple_number(sanitize):
31     assert sanitize(housenumber='34') == [('housenumber', '34')]
32
33
34 @pytest.mark.parametrize('number', ['1;2;3', '1,2,3', '1; 3 ,2',
35                                     '2,,3,1', '1;2;3;;', ';3;2;1'])
36 def test_housenumber_lists(sanitize, number):
37     assert sanitize(housenumber=number) == \
38            [('housenumber', '1'), ('housenumber', '2'), ('housenumber', '3')]
39
40
41 @pytest.mark.sanitizer_params(filter_kind=('number', 'streetnumber'))
42 def test_filter_kind(sanitize):
43     assert sanitize(housenumber='34', number='4', badnumber='65') == \
44             [('badnumber', '65'), ('housenumber', '34'), ('housenumber', '4')]