1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 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.errors import UsageError
13 from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader
16 def sp_csv_loader(src_dir):
18 Return an instance of SPCsvLoader.
20 csv_path = (src_dir / 'test' / 'testdata' / 'sp_csv_test.csv').resolve()
21 loader = SPCsvLoader(csv_path)
25 def test_generate_phrases(sp_csv_loader):
27 Test method parse_csv()
28 Should return the right SpecialPhrase objects.
30 phrases = list(sp_csv_loader.generate_phrases())
32 assert len(phrases) == 41
33 assert len(set(phrases)) == 41
35 assert any(p.p_label == 'Billboard'
36 and p.p_class == 'advertising'
37 and p.p_type == 'billboard'
38 and p.p_operator == '-' for p in phrases)
39 assert any(p.p_label == 'Zip Lines'
40 and p.p_class == 'aerialway'
41 and p.p_type == 'zip_line'
42 and p.p_operator == '-' for p in phrases)
45 def test_invalid_cvs_file():
47 Test method check_csv_validity()
48 It should raise an exception when file with a
49 different exception than .csv is given.
51 loader = SPCsvLoader('test.wrong')
53 with pytest.raises(UsageError, match='not a csv file'):
54 next(loader.generate_phrases())