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_path = (src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt').resolve()
13 with open(xml_test_content_path) as xml_content_reader:
14 return xml_content_reader.read()
18 def sp_wiki_loader(monkeypatch, def_config, xml_wiki_content):
20 Return an instance of SPWikiLoader.
22 loader = SPWikiLoader(def_config, ['en'])
23 monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader.SPWikiLoader._get_wiki_content',
24 lambda self, lang: xml_wiki_content)
28 def test_parse_xml(sp_wiki_loader, xml_wiki_content):
30 Test method parse_xml()
31 Should return the right SpecialPhrase objects.
33 phrases = sp_wiki_loader.parse_xml(xml_wiki_content)
34 assert check_phrases_content(phrases)
37 def test_next(sp_wiki_loader):
39 Test objects returned from the next() method.
40 It should return all SpecialPhrases objects of
41 the 'en' special phrases.
43 phrases = next(sp_wiki_loader)
44 assert check_phrases_content(phrases)
46 def check_phrases_content(phrases):
48 Asserts that the given phrases list contains
49 the right phrases of the 'en' special phrases.
51 return len(phrases) > 1 \
52 and any(p.p_label == 'Embassies' and p.p_class == 'amenity' and p.p_type == 'embassy'
53 and p.p_operator == '-' for p in phrases) \
54 and any(p.p_label == 'Zip Line' and p.p_class == 'aerialway' and p.p_type == 'zip_line'
55 and p.p_operator == '-' for p in phrases)