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