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)
19 def test_next(sp_csv_loader):
21 Test objects returned from the next() method.
22 It should return all SpecialPhrases objects of
23 the sp_csv_test.csv special phrases.
25 phrases = next(sp_csv_loader)
26 assert check_phrases_content(phrases)
28 def test_check_csv_validity(sp_csv_loader):
30 Test method check_csv_validity()
31 It should raise an exception when file with a
32 different exception than .csv is given.
34 sp_csv_loader.csv_path = 'test.csv'
35 sp_csv_loader.check_csv_validity()
36 sp_csv_loader.csv_path = 'test.wrong'
37 with pytest.raises(UsageError):
38 assert sp_csv_loader.check_csv_validity()
40 def check_phrases_content(phrases):
42 Asserts that the given phrases list contains
43 the right phrases of the sp_csv_test.csv special phrases.
45 return len(phrases) > 1 \
46 and any(p.p_label == 'Billboard' and p.p_class == 'advertising' and p.p_type == 'billboard'
47 and p.p_operator == '-' for p in phrases) \
48 and any(p.p_label == 'Zip Lines' and p.p_class == 'aerialway' and p.p_type == 'zip_line'
49 and p.p_operator == '-' for p in phrases)
54 Return an instance of SPCsvLoader.
56 csv_path = (TEST_BASE_DIR / 'testdata' / 'sp_csv_test.csv').resolve()
57 loader = SPCsvLoader(csv_path)