1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2025 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
18 @pytest.fixture(autouse=True)
19 def setup_country(self, def_config):
20 self.config = def_config
22 def run_sanitizer_on(self, **kwargs):
23 place = PlaceInfo({'name': kwargs})
24 name, _ = PlaceSanitizer([{'step': 'strip-brace-terms'}], self.config).process_names(place)
26 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)]
32 def test_simple_braces(self):
33 assert self.run_sanitizer_on(name='Halle (Saale)', ref='3') \
34 == [('3', 'ref', None), ('Halle', 'name', None), ('Halle (Saale)', 'name', None)]
35 assert self.run_sanitizer_on(name='ack ( bar') \
36 == [('ack', 'name', None), ('ack ( bar', 'name', None)]
38 def test_only_braces(self):
39 assert self.run_sanitizer_on(name='(maybe)') == [('(maybe)', 'name', None)]
41 def test_double_braces(self):
42 assert self.run_sanitizer_on(name='a((b))') == [('a', 'name', None),
43 ('a((b))', 'name', None)]
44 assert self.run_sanitizer_on(name='a (b) (c)') == [('a', 'name', None),
45 ('a (b) (c)', 'name', None)]
48 def test_no_names(def_config):
49 place = PlaceInfo({'address': {'housenumber': '3'}})
50 name, address = PlaceSanitizer([{'step': 'strip-brace-terms'}], def_config).process_names(place)
53 assert len(address) == 1