X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c3788d765ed4e7ddf00794085af757714bc102cf..5b02cd22b9d9bdf9d3cd32d9e4cfcb971a92c606:/test/python/tools/test_sp_csv_loader.py diff --git a/test/python/tools/test_sp_csv_loader.py b/test/python/tools/test_sp_csv_loader.py index 6f5670f0..49d5a853 100644 --- a/test/python/tools/test_sp_csv_loader.py +++ b/test/python/tools/test_sp_csv_loader.py @@ -11,56 +11,39 @@ import pytest from nominatim.errors import UsageError from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader +from nominatim.tools.special_phrases.special_phrase import SpecialPhrase -def test_parse_csv(sp_csv_loader): +@pytest.fixture +def sp_csv_loader(src_dir): """ - Test method parse_csv() - Should return the right SpecialPhrase objects. + Return an instance of SPCsvLoader. """ - phrases = sp_csv_loader.parse_csv() - assert check_phrases_content(phrases) + csv_path = (src_dir / 'test' / 'testdata' / 'sp_csv_test.csv').resolve() + loader = SPCsvLoader(csv_path) + return loader + -def test_next(sp_csv_loader): +def test_generate_phrases(sp_csv_loader): """ - Test objects returned from the next() method. - It should return all SpecialPhrases objects of - the sp_csv_test.csv special phrases. + Test method parse_csv() + Should return the right SpecialPhrase objects. """ - phrases = next(sp_csv_loader) - assert check_phrases_content(phrases) + phrases = list(sp_csv_loader.generate_phrases()) + + assert len(phrases) == 42 + assert len(set(phrases)) == 41 + + assert SpecialPhrase('Billboard', 'advertising', 'billboard', '-') in phrases + assert SpecialPhrase('Zip Lines', 'aerialway', 'zip_line', '-') in phrases -def test_check_csv_validity(sp_csv_loader): + +def test_invalid_cvs_file(): """ Test method check_csv_validity() It should raise an exception when file with a different exception than .csv is given. """ - sp_csv_loader.csv_path = 'test.csv' - sp_csv_loader.check_csv_validity() - sp_csv_loader.csv_path = 'test.wrong' - with pytest.raises(UsageError): - assert sp_csv_loader.check_csv_validity() - -def check_phrases_content(phrases): - """ - Asserts that the given phrases list contains - the right phrases of the sp_csv_test.csv special phrases. - """ - return len(phrases) > 1 \ - and any(p.p_label == 'Billboard' - and p.p_class == 'advertising' - and p.p_type == 'billboard' - and p.p_operator == '-' for p in phrases) \ - and any(p.p_label == 'Zip Lines' - and p.p_class == 'aerialway' - and p.p_type == 'zip_line' - and p.p_operator == '-' for p in phrases) + loader = SPCsvLoader('test.wrong') -@pytest.fixture -def sp_csv_loader(src_dir): - """ - Return an instance of SPCsvLoader. - """ - csv_path = (src_dir / 'test' / 'testdata' / 'sp_csv_test.csv').resolve() - loader = SPCsvLoader(csv_path) - return loader + with pytest.raises(UsageError, match='not a csv file'): + next(loader.generate_phrases())