2 Tests for methods of the SPWikiLoader class.
5 from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader
8 def xml_wiki_content(src_dir):
10 return the content of the static xml test file.
12 xml_test_content = src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt'
13 return xml_test_content.read_text()
17 def sp_wiki_loader(monkeypatch, def_config, xml_wiki_content):
19 Return an instance of SPWikiLoader.
21 loader = SPWikiLoader(def_config, ['en'])
22 monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader.SPWikiLoader._get_wiki_content',
23 lambda self, lang: xml_wiki_content)
27 def test_parse_xml(sp_wiki_loader, xml_wiki_content):
29 Test method parse_xml()
30 Should return the right SpecialPhrase objects.
32 phrases = sp_wiki_loader.parse_xml(xml_wiki_content)
33 check_phrases_content(phrases)
36 def test_next(sp_wiki_loader):
38 Test objects returned from the next() method.
39 It should return all SpecialPhrases objects of
40 the 'en' special phrases.
42 phrases = next(sp_wiki_loader)
43 check_phrases_content(phrases)
45 def check_phrases_content(phrases):
47 Asserts that the given phrases list contains
48 the right phrases of the 'en' special phrases.
50 assert set((p.p_label, p.p_class, p.p_type, p.p_operator) for p in phrases) ==\
51 {('Zip Line', 'aerialway', 'zip_line', '-'),
52 ('Zip Lines', 'aerialway', 'zip_line', '-'),
53 ('Zip Line in', 'aerialway', 'zip_line', 'in'),
54 ('Zip Lines in', 'aerialway', 'zip_line', 'in'),
55 ('Zip Line near', 'aerialway', 'zip_line', 'near'),
56 ('Animal shelter', 'amenity', 'animal_shelter', '-'),
57 ('Animal shelters', 'amenity', 'animal_shelter', '-'),
58 ('Animal shelter in', 'amenity', 'animal_shelter', 'in'),
59 ('Animal shelters in', 'amenity', 'animal_shelter', 'in'),
60 ('Animal shelter near', 'amenity', 'animal_shelter', 'near'),
61 ('Animal shelters near', 'amenity', 'animal_shelter', 'near'),
62 ('Drinking Water near', 'amenity', 'drinking_water', 'near'),
63 ('Water', 'amenity', 'drinking_water', '-'),
64 ('Water in', 'amenity', 'drinking_water', 'in'),
65 ('Water near', 'amenity', 'drinking_water', 'near'),
66 ('Embassy', 'amenity', 'embassy', '-'),
67 ('Embassys', 'amenity', 'embassy', '-'),
68 ('Embassies', 'amenity', 'embassy', '-')}