6 from nominatim_db.tools.special_phrases.sp_importer import SPImporter
8 # Testing Style Class Pair Retrival
10 def sample_style_file():
13 "keys" : ["emergency"],
15 "fire_hydrant" : "skip",
22 "keys" : ["historic", "military"],
30 "keys" : ["name:prefix", "name:suffix", "name:prefix:*", "name:suffix:*",
31 "name:botanical", "wikidata", "*:wikidata"],
37 "keys" : ["addr:housename"],
50 content = ",".join(json.dumps(entry) for entry in sample_data)
52 with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp:
59 def test_get_classtype_style(sample_style_file):
61 def get_import_style_file(self):
62 return sample_style_file
64 def load_sub_configuration(self, name):
65 return {'blackList': {}, 'whiteList': {}}
68 importer = SPImporter(config=config, conn=None, sp_loader=None)
70 result = importer.get_classtype_pairs_style()
73 ("highway", "motorway"),
76 assert expected.issubset(result)
78 # Testing Database Class Pair Retrival using Mock Database
79 def test_get_classtype_pairs(monkeypatch):
81 def load_sub_configuration(self, path, section=None):
82 return {"blackList": {}, "whiteList": {}}
85 def execute(self, query): pass
88 ("highway", "motorway"),
89 ("historic", "castle")
91 def __enter__(self): return self
92 def __exit__(self, exc_type, exc_val, exc_tb): pass
95 def cursor(self): return Cursor()
99 importer = SPImporter(config=config, conn=conn, sp_loader=None)
101 result = importer.get_classtype_pairs()
104 ("highway", "motorway"),
105 ("historic", "castle")
108 assert result == expected
110 # Testing Database Class Pair Retrival using Conftest.py and placex
111 def test_get_classtype_pair_data(placex_table, temp_db_conn):
113 def load_sub_configuration(self, *_):
114 return {'blackList': {}, 'whiteList': {}}
117 placex_table.add(cls='highway', typ='motorway') # edge case 101
120 placex_table.add(cls='amenity', typ='prison') # edge case 99
123 placex_table.add(cls='tourism', typ='hotel')
126 importer = SPImporter(config=config, conn=temp_db_conn, sp_loader=None)
128 result = importer.get_classtype_pairs()
131 ("highway", "motorway"),
135 assert result == expected, f"Expected {expected}, got {result}"
137 def test_get_classtype_pair_data_more(placex_table, temp_db_conn):
139 def load_sub_configuration(self, *_):
140 return {'blackList': {}, 'whiteList': {}}
143 placex_table.add(cls='emergency', typ='firehydrant') # edge case 100, not included
146 placex_table.add(cls='amenity', typ='prison')
148 for _ in range(3478):
149 placex_table.add(cls='tourism', typ='hotel')
152 importer = SPImporter(config=config, conn=temp_db_conn, sp_loader=None)
154 result = importer.get_classtype_pairs()
157 ("amenity", "prison"),
161 assert result == expected, f"Expected {expected}, got {result}"