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 methods of the SPWikiLoader class.
11 from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader
15 def sp_wiki_loader(src_dir, monkeypatch, def_config):
17 Return an instance of SPWikiLoader.
19 monkeypatch.setenv('NOMINATIM_LANGUAGES', 'en')
20 loader = SPWikiLoader(def_config)
22 def _mock_wiki_content(lang):
23 xml_test_content = src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt'
24 return xml_test_content.read_text()
26 monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader._get_wiki_content',
31 def test_generate_phrases(sp_wiki_loader):
33 Test objects returned from the next() method.
34 It should return all SpecialPhrases objects of
35 the 'en' special phrases.
37 phrases = list(sp_wiki_loader.generate_phrases())
39 assert set((p.p_label, p.p_class, p.p_type, p.p_operator) for p in phrases) ==\
40 {('Zip Line', 'aerialway', 'zip_line', '-'),
41 ('Zip Lines', 'aerialway', 'zip_line', '-'),
42 ('Zip Line in', 'aerialway', 'zip_line', 'in'),
43 ('Zip Lines in', 'aerialway', 'zip_line', 'in'),
44 ('Zip Line near', 'aerialway', 'zip_line', 'near'),
45 ('Animal shelter', 'amenity', 'animal_shelter', '-'),
46 ('Animal shelters', 'amenity', 'animal_shelter', '-'),
47 ('Animal shelter in', 'amenity', 'animal_shelter', 'in'),
48 ('Animal shelters in', 'amenity', 'animal_shelter', 'in'),
49 ('Animal shelter near', 'amenity', 'animal_shelter', 'near'),
50 ('Animal shelters near', 'amenity', 'animal_shelter', 'near'),
51 ('Drinking Water near', 'amenity', 'drinking_water', 'near'),
52 ('Water', 'amenity', 'drinking_water', '-'),
53 ('Water in', 'amenity', 'drinking_water', 'in'),
54 ('Water near', 'amenity', 'drinking_water', 'near'),
55 ('Embassy', 'amenity', 'embassy', '-'),
56 ('Embassys', 'amenity', 'embassy', '-'),
57 ('Embassies', 'amenity', 'embassy', '-')}