1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for the sanitizer that handles braced suffixes.
12 from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim_db.data.place_info import PlaceInfo
17 @pytest.fixture(autouse=True)
18 def setup_country(self, def_config):
19 self.config = def_config
21 def run_sanitizer_on(self, **kwargs):
22 place = PlaceInfo({'name': kwargs})
23 name, _ = PlaceSanitizer([{'step': 'strip-brace-terms'}], self.config).process_names(place)
25 return sorted([(p.name, p.kind, p.suffix) for p in name])
28 def test_no_braces(self):
29 assert self.run_sanitizer_on(name='foo', ref='23') == [('23', 'ref', None),
30 ('foo', 'name', None)]
33 def test_simple_braces(self):
34 assert self.run_sanitizer_on(name='Halle (Saale)', ref='3')\
35 == [('3', 'ref', None), ('Halle', 'name', None), ('Halle (Saale)', 'name', None)]
36 assert self.run_sanitizer_on(name='ack ( bar')\
37 == [('ack', 'name', None), ('ack ( bar', 'name', None)]
40 def test_only_braces(self):
41 assert self.run_sanitizer_on(name='(maybe)') == [('(maybe)', 'name', None)]
44 def test_double_braces(self):
45 assert self.run_sanitizer_on(name='a((b))') == [('a', 'name', None),
46 ('a((b))', 'name', None)]
47 assert self.run_sanitizer_on(name='a (b) (c)') == [('a', 'name', None),
48 ('a (b) (c)', 'name', None)]
51 def test_no_names(def_config):
52 place = PlaceInfo({'address': {'housenumber': '3'}})
53 name, address = PlaceSanitizer([{'step': 'strip-brace-terms'}], def_config).process_names(place)
56 assert len(address) == 1