2 Tests for methods of the SPCsvLoader class.
6 from nominatim.errors import UsageError
7 from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader
9 def test_parse_csv(sp_csv_loader):
11 Test method parse_csv()
12 Should return the right SpecialPhrase objects.
14 phrases = sp_csv_loader.parse_csv()
15 assert check_phrases_content(phrases)
17 def test_next(sp_csv_loader):
19 Test objects returned from the next() method.
20 It should return all SpecialPhrases objects of
21 the sp_csv_test.csv special phrases.
23 phrases = next(sp_csv_loader)
24 assert check_phrases_content(phrases)
26 def test_check_csv_validity(sp_csv_loader):
28 Test method check_csv_validity()
29 It should raise an exception when file with a
30 different exception than .csv is given.
32 sp_csv_loader.csv_path = 'test.csv'
33 sp_csv_loader.check_csv_validity()
34 sp_csv_loader.csv_path = 'test.wrong'
35 with pytest.raises(UsageError):
36 assert sp_csv_loader.check_csv_validity()
38 def check_phrases_content(phrases):
40 Asserts that the given phrases list contains
41 the right phrases of the sp_csv_test.csv special phrases.
43 return len(phrases) > 1 \
44 and any(p.p_label == 'Billboard'
45 and p.p_class == 'advertising'
46 and p.p_type == 'billboard'
47 and p.p_operator == '-' for p in phrases) \
48 and any(p.p_label == 'Zip Lines'
49 and p.p_class == 'aerialway'
50 and p.p_type == 'zip_line'
51 and p.p_operator == '-' for p in phrases)
54 def sp_csv_loader(src_dir):
56 Return an instance of SPCsvLoader.
58 csv_path = (src_dir / 'test' / 'testdata' / 'sp_csv_test.csv').resolve()
59 loader = SPCsvLoader(csv_path)