X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/efafa5271957fb54b356ec1c90e8613f14de40d4..96e1ef3ff846324bbfef1f209bfe30d88125b5bd:/test/python/tools/test_sp_wiki_loader.py diff --git a/test/python/tools/test_sp_wiki_loader.py b/test/python/tools/test_sp_wiki_loader.py index bfe93c57..2f47734e 100644 --- a/test/python/tools/test_sp_wiki_loader.py +++ b/test/python/tools/test_sp_wiki_loader.py @@ -10,49 +10,32 @@ import pytest from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader -@pytest.fixture -def xml_wiki_content(src_dir): - """ - return the content of the static xml test file. - """ - xml_test_content = src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt' - return xml_test_content.read_text() - @pytest.fixture -def sp_wiki_loader(monkeypatch, def_config, xml_wiki_content): +def sp_wiki_loader(src_dir, monkeypatch, def_config): """ Return an instance of SPWikiLoader. """ - loader = SPWikiLoader(def_config, ['en']) - monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader.SPWikiLoader._get_wiki_content', - lambda self, lang: xml_wiki_content) - return loader + monkeypatch.setenv('NOMINATIM_LANGUAGES', 'en') + loader = SPWikiLoader(def_config) + def _mock_wiki_content(lang): + xml_test_content = src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt' + return xml_test_content.read_text() -def test_parse_xml(sp_wiki_loader, xml_wiki_content): - """ - Test method parse_xml() - Should return the right SpecialPhrase objects. - """ - phrases = sp_wiki_loader.parse_xml(xml_wiki_content) - check_phrases_content(phrases) + monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader._get_wiki_content', + _mock_wiki_content) + return loader -def test_next(sp_wiki_loader): +def test_generate_phrases(sp_wiki_loader): """ Test objects returned from the next() method. It should return all SpecialPhrases objects of the 'en' special phrases. """ - phrases = next(sp_wiki_loader) - check_phrases_content(phrases) + phrases = list(sp_wiki_loader.generate_phrases()) -def check_phrases_content(phrases): - """ - Asserts that the given phrases list contains - the right phrases of the 'en' special phrases. - """ assert set((p.p_label, p.p_class, p.p_type, p.p_operator) for p in phrases) ==\ {('Zip Line', 'aerialway', 'zip_line', '-'), ('Zip Lines', 'aerialway', 'zip_line', '-'),