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 assert 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 assert 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 return len(phrases) > 1 \
51 and any(p.p_label == 'Embassies' and p.p_class == 'amenity' and p.p_type == 'embassy'
52 and p.p_operator == '-' for p in phrases) \
53 and any(p.p_label == 'Zip Line' and p.p_class == 'aerialway' and p.p_type == 'zip_line'
54 and p.p_operator == '-' for p in phrases)