]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_sp_importer.py
Removed class type pair getter that used style sheets from both spi_importer and...
[nominatim.git] / test / python / tools / test_sp_importer.py
1 import pytest
2 import tempfile
3 import os
4
5 from nominatim_db.tools.special_phrases.sp_importer import SPImporter
6
7 # Testing Database Class Pair Retrival using Mock Database
8 def test_get_classtype_pairs(monkeypatch):
9     class Config:
10         def load_sub_configuration(self, path, section=None):
11             return {"blackList": {}, "whiteList": {}}
12
13     class Cursor:
14         def execute(self, query): pass
15         def fetchall(self):
16             return [
17                 ("highway", "motorway"),  
18                 ("historic", "castle")    
19             ]
20         def __enter__(self): return self
21         def __exit__(self, exc_type, exc_val, exc_tb): pass
22
23     class Connection:
24         def cursor(self): return Cursor()
25
26     config = Config()
27     conn = Connection()
28     importer = SPImporter(config=config, conn=conn, sp_loader=None)
29
30     result = importer.get_classtype_pairs()
31
32     expected = {
33         ("highway", "motorway"),
34         ("historic", "castle")
35     }
36
37     assert result == expected
38
39 # Testing Database Class Pair Retrival using Conftest.py and placex
40 def test_get_classtype_pair_data(placex_table, temp_db_conn):
41     class Config:
42         def load_sub_configuration(self, *_):
43             return {'blackList': {}, 'whiteList': {}}
44         
45     for _ in range(101):
46         placex_table.add(cls='highway', typ='motorway') # edge case 101
47
48     for _ in range(99):
49         placex_table.add(cls='amenity', typ='prison') # edge case 99
50
51     for _ in range(150):
52         placex_table.add(cls='tourism', typ='hotel')
53
54     config = Config()
55     importer = SPImporter(config=config, conn=temp_db_conn, sp_loader=None)
56
57     result = importer.get_classtype_pairs()
58
59     expected = {
60         ("highway", "motorway"),
61         ("tourism", "hotel")
62     }
63
64     assert result == expected, f"Expected {expected}, got {result}"
65
66 def test_get_classtype_pair_data_more(placex_table, temp_db_conn):
67     class Config:
68         def load_sub_configuration(self, *_):
69             return {'blackList': {}, 'whiteList': {}}
70         
71     for _ in range(100):
72         placex_table.add(cls='emergency', typ='firehydrant') # edge case 100, not included
73
74     for _ in range(199):
75         placex_table.add(cls='amenity', typ='prison') 
76
77     for _ in range(3478):
78         placex_table.add(cls='tourism', typ='hotel')
79
80     config = Config()
81     importer = SPImporter(config=config, conn=temp_db_conn, sp_loader=None)
82
83     result = importer.get_classtype_pairs()
84
85     expected = {
86         ("amenity", "prison"),
87         ("tourism", "hotel")
88     }
89
90     assert result == expected, f"Expected {expected}, got {result}"