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
15 def test_parse_csv(sp_csv_loader):
17 Test method parse_csv()
18 Should return the right SpecialPhrase objects.
20 phrases = sp_csv_loader.parse_csv()
21 assert check_phrases_content(phrases)
23 def test_next(sp_csv_loader):
25 Test objects returned from the next() method.
26 It should return all SpecialPhrases objects of
27 the sp_csv_test.csv special phrases.
29 phrases = next(sp_csv_loader)
30 assert check_phrases_content(phrases)
32 def test_check_csv_validity(sp_csv_loader):
34 Test method check_csv_validity()
35 It should raise an exception when file with a
36 different exception than .csv is given.
38 sp_csv_loader.csv_path = 'test.csv'
39 sp_csv_loader.check_csv_validity()
40 sp_csv_loader.csv_path = 'test.wrong'
41 with pytest.raises(UsageError):
42 assert sp_csv_loader.check_csv_validity()
44 def check_phrases_content(phrases):
46 Asserts that the given phrases list contains
47 the right phrases of the sp_csv_test.csv special phrases.
49 return len(phrases) > 1 \
50 and any(p.p_label == 'Billboard'
51 and p.p_class == 'advertising'
52 and p.p_type == 'billboard'
53 and p.p_operator == '-' for p in phrases) \
54 and any(p.p_label == 'Zip Lines'
55 and p.p_class == 'aerialway'
56 and p.p_type == 'zip_line'
57 and p.p_operator == '-' for p in phrases)
60 def sp_csv_loader(src_dir):
62 Return an instance of SPCsvLoader.
64 csv_path = (src_dir / 'test' / 'testdata' / 'sp_csv_test.csv').resolve()
65 loader = SPCsvLoader(csv_path)