1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for sanitizer that clean up TIGER tags.
12 from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
13 from nominatim.data.place_info import PlaceInfo
15 class TestCleanTigerTags:
17 @pytest.fixture(autouse=True)
18 def setup_country(self, def_config):
19 self.config = def_config
22 def run_sanitizer_on(self, addr):
23 place = PlaceInfo({'address': addr})
24 _, outaddr = PlaceSanitizer([{'step': 'clean-tiger-tags'}], self.config).process_names(place)
26 return sorted([(p.name, p.kind, p.suffix) for p in outaddr])
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')]
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')]
41 def test_unmatched(self):
42 assert self.run_sanitizer_on({'tiger:country': 'US'})\
43 == [('US', 'tiger', 'country')]