From 59a947c5f5ae8a3e588158aab1730ae8377ab77e Mon Sep 17 00:00:00 2001 From: anqixxx Date: Mon, 14 Apr 2025 10:14:57 -0700 Subject: [PATCH] Removed class type pair getter that used style sheets from both spi_importer and the associated testing function --- .../tools/special_phrases/sp_importer.py | 25 ------- test/python/tools/test_sp_importer.py | 71 ------------------- 2 files changed, 96 deletions(-) diff --git a/src/nominatim_db/tools/special_phrases/sp_importer.py b/src/nominatim_db/tools/special_phrases/sp_importer.py index a4d0eaf6..89ac6dac 100644 --- a/src/nominatim_db/tools/special_phrases/sp_importer.py +++ b/src/nominatim_db/tools/special_phrases/sp_importer.py @@ -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, diff --git a/test/python/tools/test_sp_importer.py b/test/python/tools/test_sp_importer.py index 4d2dd8d4..b27172c8 100644 --- a/test/python/tools/test_sp_importer.py +++ b/test/python/tools/test_sp_importer.py @@ -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: