]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tokenizer/sanitizers/test_strip_brace_terms.py
sanetizer no longer strips name parts in brackets when more parts follow
[nominatim.git] / test / python / tokenizer / sanitizers / test_strip_brace_terms.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2025 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_db.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim_db.data.place_info import PlaceInfo
14
15
16 class TestStripBrace:
17
18     @pytest.fixture(autouse=True)
19     def setup_country(self, def_config):
20         self.config = def_config
21
22     def run_sanitizer_on(self, **kwargs):
23         place = PlaceInfo({'name': kwargs})
24         name, _ = PlaceSanitizer([{'step': 'strip-brace-terms'}], self.config).process_names(place)
25
26         return sorted([(p.name, p.kind, p.suffix) for p in name])
27
28     def test_no_braces(self):
29         assert self.run_sanitizer_on(name='foo', ref='23') == [('23', 'ref', None),
30                                                                ('foo', 'name', None)]
31
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)]
37         assert self.run_sanitizer_on(name='Berlin (Ost) Hauptbahnhof') \
38             == [('Berlin (Ost) Hauptbahnhof', 'name', None)]
39
40     def test_only_braces(self):
41         assert self.run_sanitizer_on(name='(maybe)') == [('(maybe)', 'name', None)]
42
43     def test_double_braces(self):
44         assert self.run_sanitizer_on(name='a((b))') == [('a', 'name', None),
45                                                         ('a((b))', 'name', None)]
46         assert self.run_sanitizer_on(name='a (b) (c)') == [('a', 'name', None),
47                                                            ('a (b) (c)', 'name', None)]
48
49
50 def test_no_names(def_config):
51     place = PlaceInfo({'address': {'housenumber': '3'}})
52     name, address = PlaceSanitizer([{'step': 'strip-brace-terms'}], def_config).process_names(place)
53
54     assert not name
55     assert len(address) == 1