1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for the sanitizer that normalizes housenumbers.
12 from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim.indexer.place_info import PlaceInfo
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()})
22 place = PlaceInfo({'address': kwargs})
23 _, address = PlaceSanitizer([sanitizer_args]).process_names(place)
25 return sorted([(p.kind, p.name) for p in address])
30 def test_simple_number(sanitize):
31 assert sanitize(housenumber='34') == [('housenumber', '34')]
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')]
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')]
47 @pytest.mark.parametrize('number', ('6523', 'n/a', '4'))
48 def test_convert_to_name_converted(number):
49 sanitizer_args = {'step': 'clean-housenumbers',
50 'convert-to-name': (r'\d+', 'n/a')}
52 place = PlaceInfo({'address': {'housenumber': number}})
53 names, address = PlaceSanitizer([sanitizer_args]).process_names(place)
55 assert ('housenumber', number) in set((p.kind, p.name) for p in names)
56 assert 'housenumber' not in set(p.kind for p in address)