]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tokenizer/sanitizers/test_strip_brace_terms.py
Merge pull request #2588 from lonvia/housenumber-sanitizer
[nominatim.git] / test / python / tokenizer / sanitizers / test_strip_brace_terms.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 handles braced suffixes.
9 """
10 import pytest
11
12 from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim.indexer.place_info import PlaceInfo
14
15 def run_sanitizer_on(**kwargs):
16     place = PlaceInfo({'name': kwargs})
17     name, _ = PlaceSanitizer([{'step': 'strip-brace-terms'}]).process_names(place)
18
19     return sorted([(p.name, p.kind, p.suffix) for p in name])
20
21
22 def test_no_braces():
23     assert run_sanitizer_on(name='foo', ref='23') == [('23', 'ref', None),
24                                                       ('foo', 'name', None)]
25
26
27 def test_simple_braces():
28     assert run_sanitizer_on(name='Halle (Saale)', ref='3')\
29       == [('3', 'ref', None), ('Halle', 'name', None), ('Halle (Saale)', 'name', None)]
30     assert run_sanitizer_on(name='ack ( bar')\
31       == [('ack', 'name', None), ('ack ( bar', 'name', None)]
32
33
34 def test_only_braces():
35     assert run_sanitizer_on(name='(maybe)') == [('(maybe)', 'name', None)]
36
37
38 def test_double_braces():
39     assert run_sanitizer_on(name='a((b))') == [('a', 'name', None),
40                                                ('a((b))', 'name', None)]
41     assert run_sanitizer_on(name='a (b) (c)') == [('a', 'name', None),
42                                                   ('a (b) (c)', 'name', None)]
43
44
45 def test_no_names():
46     place = PlaceInfo({'address': {'housenumber': '3'}})
47     name, address = PlaceSanitizer([{'step': 'strip-brace-terms'}]).process_names(place)
48
49     assert not name
50     assert len(address) == 1