From d691cfc35dfdb9b23665695563321afff6de64ea Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 12 Feb 2026 21:12:10 +0100 Subject: [PATCH] switch table definitions in conftest to use production SQL --- test/python/conftest.py | 48 ++++++++--------------- test/python/tools/test_database_import.py | 20 ++++++++-- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/test/python/conftest.py b/test/python/conftest.py index b249643c..6e4e3ba1 100644 --- a/test/python/conftest.py +++ b/test/python/conftest.py @@ -2,7 +2,7 @@ # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2025 by the Nominatim developer community. +# Copyright (C) 2026 by the Nominatim developer community. # For a full list of authors see the git log. import itertools import sys @@ -146,28 +146,28 @@ def country_row(country_table, temp_db_cursor): @pytest.fixture -def property_table(table_factory, temp_db_conn): - table_factory('nominatim_properties', 'property TEXT, value TEXT') +def load_sql(temp_db_conn, country_row): + proc = SQLPreprocessor(temp_db_conn, Configuration(None)) + + def _run(filename, **kwargs): + proc.run_sql_file(temp_db_conn, filename, **kwargs) + + return _run + + +@pytest.fixture +def property_table(load_sql, temp_db_conn): + load_sql('tables/nominatim_properties.sql') return mocks.MockPropertyTable(temp_db_conn) @pytest.fixture -def status_table(table_factory): +def status_table(load_sql): """ Create an empty version of the status table and the status logging table. """ - table_factory('import_status', - """lastimportdate timestamp with time zone NOT NULL, - sequence_id integer, - indexed boolean""") - table_factory('import_osmosis_log', - """batchend timestamp, - batchseq integer, - batchsize bigint, - starttime timestamp, - endtime timestamp, - event text""") + load_sql('tables/status.sql') @pytest.fixture @@ -243,22 +243,8 @@ def placex_table(temp_db_with_extensions, temp_db_conn): @pytest.fixture -def osmline_table(temp_db_with_extensions, table_factory): - table_factory('location_property_osmline', - """place_id BIGINT, - osm_id BIGINT, - parent_place_id BIGINT, - geometry_sector INTEGER, - indexed_date TIMESTAMP, - startnumber INTEGER, - endnumber INTEGER, - partition SMALLINT, - indexed_status SMALLINT, - linegeo GEOMETRY, - interpolationtype TEXT, - address HSTORE, - postcode TEXT, - country_code VARCHAR(2)""") +def osmline_table(temp_db_with_extensions, load_sql): + load_sql('tables/interpolation.sql') @pytest.fixture diff --git a/test/python/tools/test_database_import.py b/test/python/tools/test_database_import.py index df22100c..f901067b 100644 --- a/test/python/tools/test_database_import.py +++ b/test/python/tools/test_database_import.py @@ -170,15 +170,27 @@ def test_truncate_database_tables(temp_db_conn, temp_db_cursor, table_factory, w @pytest.mark.asyncio async def test_load_data(dsn, place_row, placex_table, osmline_table, temp_db_cursor, threads): - for func in ('precompute_words', 'getorcreate_housenumber_id', 'make_standard_name'): - temp_db_cursor.execute(pysql.SQL("""CREATE FUNCTION {} (src TEXT) - RETURNS TEXT AS $$ SELECT 'a'::TEXT $$ LANGUAGE SQL - """).format(pysql.Identifier(func))) for oid in range(100, 130): place_row(osm_id=oid) place_row(osm_type='W', osm_id=342, cls='place', typ='houses', geom='LINESTRING(0 0, 10 10)') + temp_db_cursor.execute(""" + CREATE OR REPLACE FUNCTION osmline_insert() RETURNS TRIGGER AS $$ + BEGIN + NEW.place_id := nextval('seq_place'); + IF NEW.indexed_status IS NULL THEN + NEW.indexed_status := 1; + NEW.partition := 0; + NEW.geometry_sector := 2424; + END IF; + RETURN NEW; + END; $$ LANGUAGE plpgsql STABLE PARALLEL SAFE; + + CREATE TRIGGER osmline_before_insert BEFORE INSERT ON location_property_osmline + FOR EACH ROW EXECUTE PROCEDURE osmline_insert() + """) + await database_import.load_data(dsn, threads) assert temp_db_cursor.table_rows('placex') == 30