]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tokenizer/sanitizers/test_clean_tiger_tags.py
add sanitizer for TIGER tags
[nominatim.git] / test / python / tokenizer / sanitizers / test_clean_tiger_tags.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 sanitizer that clean up TIGER tags.
9 """
10 import pytest
11
12 from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim.data.place_info import PlaceInfo
14
15 class TestCleanTigerTags:
16
17     @pytest.fixture(autouse=True)
18     def setup_country(self, def_config):
19         self.config = def_config
20
21
22     def run_sanitizer_on(self, addr):
23         place = PlaceInfo({'address': addr})
24         _, outaddr = PlaceSanitizer([{'step': 'clean-tiger-tags'}], self.config).process_names(place)
25
26         return sorted([(p.name, p.kind, p.suffix) for p in outaddr])
27
28     @pytest.mark.parametrize('inname,outname', [('Hamilton, AL', 'Hamilton'),
29                                                 ('Little, Borough, CA', 'Little, Borough')])
30     def test_well_formatted(self, inname, outname):
31         assert self.run_sanitizer_on({'tiger:county': inname})\
32             == [(outname, 'county', 'tiger')]
33
34
35     @pytest.mark.parametrize('name', ('Hamilton', 'Big, Road', ''))
36     def test_badly_formatted(self, name):
37         assert self.run_sanitizer_on({'tiger:county': name})\
38             == [(name, 'county', 'tiger')]
39
40
41     def test_unmatched(self):
42         assert self.run_sanitizer_on({'tiger:country': 'US'})\
43             == [('US', 'tiger', 'country')]