Removed class type pair getter that used style sheets from both spi_importer and the associated testing function

This commit is contained in:
anqixxx
2025-04-14 10:14:57 -07:00
parent 1952290359
commit 59a947c5f5
2 changed files with 0 additions and 96 deletions

View File

@@ -16,7 +16,6 @@
from typing import Iterable, Tuple, Mapping, Sequence, Optional, Set
import logging
import re
import json
from psycopg.sql import Identifier, SQL
from ...typing import Protocol
@@ -65,30 +64,6 @@ class SPImporter():
# special phrases class/type on the wiki.
self.table_phrases_to_delete: Set[str] = set()
def get_classtype_pairs_style(self) -> Set[Tuple[str, str]]:
"""
Returns list of allowed special phrases from the the style file,
restricting to a list of combinations of classes and types
which have a 'main' property
Note: This requirement was from 2021 and I am a bit unsure if it is still relevant
"""
style_file = self.config.get_import_style_file() # import style file as json
with open(style_file, 'r') as file:
style_data = json.loads(f'[{file.read()}]')
style_combinations = set()
for _map in style_data: # following ../settings/import-extratags.style
classes = _map.get("keys", [])
values = _map.get("values", {})
for _type, properties in values.items():
if "main" in properties and _type: # make sure the tag is a non-empty string
for _class in classes:
style_combinations.add((_class, _type)) # type is the value of the main tag
return style_combinations
def get_classtype_pairs(self) -> Set[Tuple[str, str]]:
"""
Returns list of allowed special phrases from the database,

View File

@@ -1,80 +1,9 @@
import pytest
import tempfile
import json
import os
from nominatim_db.tools.special_phrases.sp_importer import SPImporter
# Testing Style Class Pair Retrival
@pytest.fixture
def sample_style_file():
sample_data = [
{
"keys" : ["emergency"],
"values" : {
"fire_hydrant" : "skip",
"yes" : "skip",
"no" : "skip",
"" : "main"
}
},
{
"keys" : ["historic", "military"],
"values" : {
"no" : "skip",
"yes" : "skip",
"" : "main"
}
},
{
"keys" : ["name:prefix", "name:suffix", "name:prefix:*", "name:suffix:*",
"name:botanical", "wikidata", "*:wikidata"],
"values" : {
"" : "extra"
}
},
{
"keys" : ["addr:housename"],
"values" : {
"" : "name,house"
}
},
{
"keys": ["highway"],
"values": {
"motorway": "main",
"": "skip"
}
}
]
content = ",".join(json.dumps(entry) for entry in sample_data)
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp:
tmp.write(content)
tmp_path = tmp.name
yield tmp_path
os.remove(tmp_path)
def test_get_classtype_style(sample_style_file):
class Config:
def get_import_style_file(self):
return sample_style_file
def load_sub_configuration(self, name):
return {'blackList': {}, 'whiteList': {}}
config = Config()
importer = SPImporter(config=config, conn=None, sp_loader=None)
result = importer.get_classtype_pairs_style()
expected = {
("highway", "motorway"),
}
assert expected.issubset(result)
# Testing Database Class Pair Retrival using Mock Database
def test_get_classtype_pairs(monkeypatch):
class Config: