From d274a5aecc740199a220a966b6135960be05e8a1 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 12 Feb 2026 20:14:13 +0100 Subject: [PATCH] add fixtures for country table --- test/python/conftest.py | 20 ++++++++++++++++++-- test/python/data/test_country_info.py | 9 ++++----- test/python/tools/test_admin.py | 5 ++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/test/python/conftest.py b/test/python/conftest.py index 95f3cb0a..b249643c 100644 --- a/test/python/conftest.py +++ b/test/python/conftest.py @@ -131,6 +131,20 @@ def project_env(tmp_path): return cfg +@pytest.fixture +def country_table(table_factory): + table_factory('country_name', 'partition INT, country_code varchar(2), name hstore') + + +@pytest.fixture +def country_row(country_table, temp_db_cursor): + def _add(partition=None, country=None, names=None): + temp_db_cursor.insert_row('country_name', partition=partition, + country_code=country, name=names) + + return _add + + @pytest.fixture def property_table(table_factory, temp_db_conn): table_factory('nominatim_properties', 'property TEXT, value TEXT') @@ -248,8 +262,10 @@ def osmline_table(temp_db_with_extensions, table_factory): @pytest.fixture -def sql_preprocessor_cfg(tmp_path, table_factory, temp_db_with_extensions): - table_factory('country_name', 'partition INT', ((0, ), (1, ), (2, ))) +def sql_preprocessor_cfg(tmp_path, table_factory, temp_db_with_extensions, country_row): + for part in range(3): + country_row(partition=part) + cfg = Configuration(None) cfg.set_libdirs(sql=tmp_path) return cfg diff --git a/test/python/data/test_country_info.py b/test/python/data/test_country_info.py index ea7caa3e..c2b2a0db 100644 --- a/test/python/data/test_country_info.py +++ b/test/python/data/test_country_info.py @@ -53,11 +53,10 @@ def test_setup_country_tables(src_dir, temp_db_with_extensions, dsn, temp_db_cur @pytest.mark.parametrize("languages", (None, ['fr', 'en'])) def test_create_country_names(temp_db_with_extensions, temp_db_conn, temp_db_cursor, - table_factory, tokenizer_mock, languages, loaded_country): - - table_factory('country_name', 'country_code varchar(2), name hstore', - content=(('us', '"name"=>"us1","name:af"=>"us2"'), - ('fr', '"name"=>"Fra", "name:en"=>"Fren"'))) + country_row, tokenizer_mock, languages, loaded_country): + temp_db_cursor.execute('TRUNCATE country_name') + country_row(country='us', names={"name": "us1", "name:af": "us2"}) + country_row(country='fr', names={"name": "Fra", "name:en": "Fren"}) assert temp_db_cursor.scalar("SELECT count(*) FROM country_name") == 2 diff --git a/test/python/tools/test_admin.py b/test/python/tools/test_admin.py index e758bca2..a3783f1a 100644 --- a/test/python/tools/test_admin.py +++ b/test/python/tools/test_admin.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. """ Tests for maintenance and analysis functions. @@ -77,7 +77,7 @@ def test_analyse_indexing_with_osm_id(project_env, temp_db_cursor): class TestAdminCleanDeleted: @pytest.fixture(autouse=True) - def setup_polygon_delete(self, project_env, table_factory, place_table, + def setup_polygon_delete(self, project_env, table_factory, country_table, place_table, osmline_table, temp_db_cursor, temp_db_conn, def_config, src_dir): """ Set up place_force_delete function and related tables """ @@ -104,7 +104,6 @@ class TestAdminCleanDeleted: class TEXT NOT NULL, type TEXT NOT NULL, deferred BOOLEAN""") - table_factory('country_name', 'partition INT') table_factory('import_polygon_error', """osm_id BIGINT, osm_type CHAR(1), class TEXT NOT NULL,