]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tokenizer/sanitizers/test_strip_brace_terms.py
use place_to_be_deleted when force deleting objects
[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.data.place_info import PlaceInfo
14
15 class TestStripBrace:
16
17     @pytest.fixture(autouse=True)
18     def setup_country(self, def_config):
19         self.config = def_config
20
21     def run_sanitizer_on(self, **kwargs):
22         place = PlaceInfo({'name': kwargs})
23         name, _ = PlaceSanitizer([{'step': 'strip-brace-terms'}], self.config).process_names(place)
24
25         return sorted([(p.name, p.kind, p.suffix) for p in name])
26
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
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)]
38
39
40     def test_only_braces(self):
41         assert self.run_sanitizer_on(name='(maybe)') == [('(maybe)', 'name', None)]
42
43
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)]
49
50
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)
54
55     assert not name
56     assert len(address) == 1