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
14 def xml_wiki_content(src_dir):
16 return the content of the static xml test file.
18 xml_test_content = src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt'
19 return xml_test_content.read_text()
23 def sp_wiki_loader(monkeypatch, def_config, xml_wiki_content):
25 Return an instance of SPWikiLoader.
27 loader = SPWikiLoader(def_config, ['en'])
28 monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader.SPWikiLoader._get_wiki_content',
29 lambda self, lang: xml_wiki_content)
33 def test_parse_xml(sp_wiki_loader, xml_wiki_content):
35 Test method parse_xml()
36 Should return the right SpecialPhrase objects.
38 phrases = sp_wiki_loader.parse_xml(xml_wiki_content)
39 check_phrases_content(phrases)
42 def test_next(sp_wiki_loader):
44 Test objects returned from the next() method.
45 It should return all SpecialPhrases objects of
46 the 'en' special phrases.
48 phrases = next(sp_wiki_loader)
49 check_phrases_content(phrases)
51 def check_phrases_content(phrases):
53 Asserts that the given phrases list contains
54 the right phrases of the 'en' special phrases.
56 assert set((p.p_label, p.p_class, p.p_type, p.p_operator) for p in phrases) ==\
57 {('Zip Line', 'aerialway', 'zip_line', '-'),
58 ('Zip Lines', 'aerialway', 'zip_line', '-'),
59 ('Zip Line in', 'aerialway', 'zip_line', 'in'),
60 ('Zip Lines in', 'aerialway', 'zip_line', 'in'),
61 ('Zip Line near', 'aerialway', 'zip_line', 'near'),
62 ('Animal shelter', 'amenity', 'animal_shelter', '-'),
63 ('Animal shelters', 'amenity', 'animal_shelter', '-'),
64 ('Animal shelter in', 'amenity', 'animal_shelter', 'in'),
65 ('Animal shelters in', 'amenity', 'animal_shelter', 'in'),
66 ('Animal shelter near', 'amenity', 'animal_shelter', 'near'),
67 ('Animal shelters near', 'amenity', 'animal_shelter', 'near'),
68 ('Drinking Water near', 'amenity', 'drinking_water', 'near'),
69 ('Water', 'amenity', 'drinking_water', '-'),
70 ('Water in', 'amenity', 'drinking_water', 'in'),
71 ('Water near', 'amenity', 'drinking_water', 'near'),
72 ('Embassy', 'amenity', 'embassy', '-'),
73 ('Embassys', 'amenity', 'embassy', '-'),
74 ('Embassies', 'amenity', 'embassy', '-')}