1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 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_core.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
17 def sp_csv_loader(src_dir):
19 Return an instance of SPCsvLoader.
21 csv_path = (src_dir / 'test' / 'testdata' / 'sp_csv_test.csv').resolve()
22 loader = SPCsvLoader(csv_path)
26 def test_generate_phrases(sp_csv_loader):
28 Test method parse_csv()
29 Should return the right SpecialPhrase objects.
31 phrases = list(sp_csv_loader.generate_phrases())
33 assert len(phrases) == 42
34 assert len(set(phrases)) == 41
36 assert SpecialPhrase('Billboard', 'advertising', 'billboard', '-') in phrases
37 assert SpecialPhrase('Zip Lines', 'aerialway', 'zip_line', '-') in phrases
40 def test_invalid_cvs_file():
42 Test method check_csv_validity()
43 It should raise an exception when file with a
44 different exception than .csv is given.
46 loader = SPCsvLoader('test.wrong')
48 with pytest.raises(UsageError, match='not a csv file'):
49 next(loader.generate_phrases())