mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-25 18:48:15 +00:00
move database setup to generic conftest.py
This commit is contained in:
@@ -11,6 +11,8 @@ import sys
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import psycopg
|
||||||
|
|
||||||
# always test against the source
|
# always test against the source
|
||||||
SRC_DIR = (Path(__file__) / '..' / '..' / '..').resolve()
|
SRC_DIR = (Path(__file__) / '..' / '..' / '..').resolve()
|
||||||
sys.path.insert(0, str(SRC_DIR / 'src'))
|
sys.path.insert(0, str(SRC_DIR / 'src'))
|
||||||
@@ -23,12 +25,13 @@ pytest.register_assert_rewrite('utils')
|
|||||||
|
|
||||||
from utils.api_runner import APIRunner
|
from utils.api_runner import APIRunner
|
||||||
from utils.api_result import APIResult
|
from utils.api_result import APIResult
|
||||||
from utils.checks import ResultAttr, COMPARATOR_TERMS
|
from utils.checks import ResultAttr, COMPARATOR_TERMS, check_table_content, check_table_has_lines
|
||||||
from utils.geometry_alias import ALIASES
|
from utils.geometry_alias import ALIASES
|
||||||
from utils.grid import Grid
|
from utils.grid import Grid
|
||||||
from utils.db import DBManager
|
from utils.db import DBManager
|
||||||
|
|
||||||
from nominatim_db.config import Configuration
|
from nominatim_db.config import Configuration
|
||||||
|
from nominatim_db import cli
|
||||||
|
|
||||||
|
|
||||||
def _strlist(inp):
|
def _strlist(inp):
|
||||||
@@ -95,6 +98,38 @@ def template_db(pytestconfig):
|
|||||||
return template_db
|
return template_db
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def def_config(pytestconfig):
|
||||||
|
dbname = pytestconfig.getini('nominatim_test_db')
|
||||||
|
|
||||||
|
return Configuration(None,
|
||||||
|
environ={'NOMINATIM_DATABASE_DSN': f"pgsql:dbname={dbname}"})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def db(template_db, pytestconfig):
|
||||||
|
""" Set up an empty database for use with osm2pgsql.
|
||||||
|
"""
|
||||||
|
dbm = DBManager(purge=pytestconfig.option.NOMINATIM_PURGE)
|
||||||
|
|
||||||
|
dbname = pytestconfig.getini('nominatim_test_db')
|
||||||
|
|
||||||
|
dbm.create_db_from_template(dbname, template_db)
|
||||||
|
|
||||||
|
yield dbname
|
||||||
|
|
||||||
|
if not pytestconfig.option.NOMINATIM_KEEP_DB:
|
||||||
|
dbm.drop_db(dbname)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def db_conn(def_config):
|
||||||
|
with psycopg.connect(def_config.get_libpq_dsn()) as conn:
|
||||||
|
info = psycopg.types.TypeInfo.fetch(conn, "hstore")
|
||||||
|
psycopg.types.hstore.register_hstore(info, conn)
|
||||||
|
yield conn
|
||||||
|
|
||||||
|
|
||||||
@when(step_parse(r'reverse geocoding (?P<lat>[\d.-]*),(?P<lon>[\d.-]*)'),
|
@when(step_parse(r'reverse geocoding (?P<lat>[\d.-]*),(?P<lon>[\d.-]*)'),
|
||||||
target_fixture='nominatim_result')
|
target_fixture='nominatim_result')
|
||||||
def reverse_geocode_via_api(test_config_env, pytestconfig, datatable, lat, lon):
|
def reverse_geocode_via_api(test_config_env, pytestconfig, datatable, lat, lon):
|
||||||
@@ -278,3 +313,22 @@ def set_node_grid(datatable, step, origin):
|
|||||||
raise RuntimeError('Grid origin must be either coordinate or alias.')
|
raise RuntimeError('Grid origin must be either coordinate or alias.')
|
||||||
|
|
||||||
return Grid(datatable, step, origin)
|
return Grid(datatable, step, origin)
|
||||||
|
|
||||||
|
|
||||||
|
@when('indexing')
|
||||||
|
def do_index(def_config):
|
||||||
|
""" Run Nominatim's indexing step.
|
||||||
|
"""
|
||||||
|
cli.nominatim(['index'], def_config.environ)
|
||||||
|
|
||||||
|
|
||||||
|
@then(step_parse(r'(?P<table>\w+) contains(?P<exact> exactly)?'))
|
||||||
|
def check_place_content(db_conn, datatable, node_grid, table, exact):
|
||||||
|
check_table_content(db_conn, table, datatable, grid=node_grid, exact=bool(exact))
|
||||||
|
|
||||||
|
|
||||||
|
@then(step_parse('(?P<table>placex?) has no entry for '
|
||||||
|
r'(?P<osm_type>[NRW])(?P<osm_id>\d+)(?::(?P<osm_class>\S+))?'),
|
||||||
|
converters={'osm_id': int})
|
||||||
|
def check_place_missing_lines(db_conn, table, osm_type, osm_id, osm_class):
|
||||||
|
check_table_has_lines(db_conn, table, osm_type, osm_id, osm_class)
|
||||||
|
|||||||
@@ -10,53 +10,14 @@ Collector for BDD osm2pgsql import style tests.
|
|||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import psycopg
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pytest_bdd.parsers import re as step_parse
|
from pytest_bdd import scenarios, when, given
|
||||||
from pytest_bdd import scenarios, when, given, then
|
|
||||||
|
|
||||||
from nominatim_db import cli
|
from nominatim_db import cli
|
||||||
from nominatim_db.config import Configuration
|
|
||||||
from nominatim_db.tools.exec_utils import run_osm2pgsql
|
from nominatim_db.tools.exec_utils import run_osm2pgsql
|
||||||
from nominatim_db.tools.database_import import load_data, create_table_triggers
|
from nominatim_db.tools.database_import import load_data, create_table_triggers
|
||||||
from nominatim_db.tools.replication import run_osm2pgsql_updates
|
from nominatim_db.tools.replication import run_osm2pgsql_updates
|
||||||
|
|
||||||
from utils.db import DBManager
|
|
||||||
from utils.checks import check_table_content, check_table_has_lines
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def def_config(pytestconfig):
|
|
||||||
dbname = pytestconfig.getini('nominatim_test_db')
|
|
||||||
|
|
||||||
return Configuration(None,
|
|
||||||
environ={'NOMINATIM_DATABASE_DSN': f"pgsql:dbname={dbname}"})
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def db(template_db, pytestconfig):
|
|
||||||
""" Set up an empty database for use with osm2pgsql.
|
|
||||||
"""
|
|
||||||
dbm = DBManager(purge=pytestconfig.option.NOMINATIM_PURGE)
|
|
||||||
|
|
||||||
dbname = pytestconfig.getini('nominatim_test_db')
|
|
||||||
|
|
||||||
dbm.create_db_from_template(dbname, template_db)
|
|
||||||
|
|
||||||
yield dbname
|
|
||||||
|
|
||||||
if not pytestconfig.option.NOMINATIM_KEEP_DB:
|
|
||||||
dbm.drop_db(dbname)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def db_conn(def_config):
|
|
||||||
with psycopg.connect(def_config.get_libpq_dsn()) as conn:
|
|
||||||
info = psycopg.types.TypeInfo.fetch(conn, "hstore")
|
|
||||||
psycopg.types.hstore.register_hstore(info, conn)
|
|
||||||
yield conn
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def osm2pgsql_options(def_config):
|
def osm2pgsql_options(def_config):
|
||||||
@@ -130,23 +91,4 @@ def update_from_osm_file(db_conn, def_config, osm2pgsql_options, opl_writer, doc
|
|||||||
run_osm2pgsql_updates(db_conn, osm2pgsql_options)
|
run_osm2pgsql_updates(db_conn, osm2pgsql_options)
|
||||||
|
|
||||||
|
|
||||||
@when('indexing')
|
|
||||||
def do_index(def_config):
|
|
||||||
""" Run Nominatim's indexing step.
|
|
||||||
"""
|
|
||||||
cli.nominatim(['index'], def_config.environ)
|
|
||||||
|
|
||||||
|
|
||||||
@then(step_parse(r'(?P<table>\w+) contains(?P<exact> exactly)?'))
|
|
||||||
def check_place_content(db_conn, datatable, node_grid, table, exact):
|
|
||||||
check_table_content(db_conn, table, datatable, grid=node_grid, exact=bool(exact))
|
|
||||||
|
|
||||||
|
|
||||||
@then(step_parse('(?P<table>placex?) has no entry for '
|
|
||||||
r'(?P<osm_type>[NRW])(?P<osm_id>\d+)(?::(?P<osm_class>\S+))?'),
|
|
||||||
converters={'osm_id': int})
|
|
||||||
def check_place_missing_lines(db_conn, table, osm_type, osm_id, osm_class):
|
|
||||||
check_table_has_lines(db_conn, table, osm_type, osm_id, osm_class)
|
|
||||||
|
|
||||||
|
|
||||||
scenarios('features/osm2pgsql')
|
scenarios('features/osm2pgsql')
|
||||||
|
|||||||
Reference in New Issue
Block a user