1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for methods of the SPCsvLoader class.
12 from nominatim_db.errors import UsageError
13 from nominatim_db.tools.special_phrases.sp_csv_loader import SPCsvLoader
14 from nominatim_db.tools.special_phrases.special_phrase import SpecialPhrase
18 def sp_csv_loader(src_dir):
20 Return an instance of SPCsvLoader.
22 csv_path = (src_dir / 'test' / 'testdata' / 'sp_csv_test.csv').resolve()
23 loader = SPCsvLoader(csv_path)
27 def test_generate_phrases(sp_csv_loader):
29 Test method parse_csv()
30 Should return the right SpecialPhrase objects.
32 phrases = list(sp_csv_loader.generate_phrases())
34 assert len(phrases) == 42
35 assert len(set(phrases)) == 41
37 assert SpecialPhrase('Billboard', 'advertising', 'billboard', '-') in phrases
38 assert SpecialPhrase('Zip Lines', 'aerialway', 'zip_line', '-') in phrases
41 def test_invalid_cvs_file():
43 Test method check_csv_validity()
44 It should raise an exception when file with a
45 different exception than .csv is given.
47 loader = SPCsvLoader('test.wrong')
49 with pytest.raises(UsageError, match='not a csv file'):
50 next(loader.generate_phrases())