2 Tests for methods of the SPWikiLoader class.
5 from pathlib import Path
6 from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader
8 TEST_BASE_DIR = Path(__file__) / '..' / '..'
10 def test_parse_xml(sp_wiki_loader):
12 Test method parse_xml()
13 Should return the right SpecialPhrase objects.
15 xml = get_test_xml_wiki_content()
16 phrases = sp_wiki_loader.parse_xml(xml)
17 assert check_phrases_content(phrases)
20 def test_next(sp_wiki_loader):
22 Test objects returned from the next() method.
23 It should return all SpecialPhrases objects of
24 the 'en' special phrases.
26 phrases = next(sp_wiki_loader)
27 assert check_phrases_content(phrases)
29 def check_phrases_content(phrases):
31 Asserts that the given phrases list contains
32 the right phrases of the 'en' special phrases.
34 return len(phrases) > 1 \
35 and any(p.p_label == 'Embassies' and p.p_class == 'amenity' and p.p_type == 'embassy'
36 and p.p_operator == '-' for p in phrases) \
37 and any(p.p_label == 'Zip Line' and p.p_class == 'aerialway' and p.p_type == 'zip_line'
38 and p.p_operator == '-' for p in phrases)
41 def sp_wiki_loader(monkeypatch, def_config):
43 Return an instance of SPWikiLoader.
45 loader = SPWikiLoader(def_config, ['en'])
46 monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader.SPWikiLoader._get_wiki_content',
47 mock_get_wiki_content)
50 def mock_get_wiki_content(self, lang):
52 Mock the _get_wiki_content() method to return
53 static xml test file content.
55 return get_test_xml_wiki_content()
57 def get_test_xml_wiki_content():
59 return the content of the static xml test file.
61 xml_test_content_path = (TEST_BASE_DIR / 'testdata' / 'special_phrases_test_content.txt').resolve()
62 with open(xml_test_content_path) as xml_content_reader:
63 return xml_content_reader.read()