forked from hans/Nominatim
simplify constructor for SQL preprocessor
Use sql path from config.
This commit is contained in:
@@ -280,7 +280,11 @@ def osm2pgsql_options(temp_db):
|
||||
main_data='', main_index=''))
|
||||
|
||||
@pytest.fixture
|
||||
def sql_preprocessor(temp_db_conn, tmp_path, def_config, monkeypatch, table_factory):
|
||||
def sql_preprocessor(temp_db_conn, tmp_path, monkeypatch, table_factory):
|
||||
monkeypatch.setenv('NOMINATIM_DATABASE_MODULE_PATH', '.')
|
||||
table_factory('country_name', 'partition INT', (0, 1, 2))
|
||||
return SQLPreprocessor(temp_db_conn, def_config, tmp_path)
|
||||
cfg = Configuration(None, SRC_DIR.resolve() / 'settings')
|
||||
cfg.set_libdirs(module='.', osm2pgsql='.', php=SRC_DIR / 'lib-php',
|
||||
sql=tmp_path, data=SRC_DIR / 'data')
|
||||
|
||||
return SQLPreprocessor(temp_db_conn, cfg)
|
||||
|
||||
@@ -5,6 +5,11 @@ import pytest
|
||||
|
||||
from nominatim.tools.refresh import create_functions
|
||||
|
||||
@pytest.fixture
|
||||
def sql_tmp_path(tmp_path, def_config):
|
||||
def_config.lib_dir.sql = tmp_path
|
||||
return tmp_path
|
||||
|
||||
@pytest.fixture
|
||||
def conn(temp_db_conn, table_factory, monkeypatch):
|
||||
monkeypatch.setenv('NOMINATIM_DATABASE_MODULE_PATH', '.')
|
||||
@@ -12,8 +17,8 @@ def conn(temp_db_conn, table_factory, monkeypatch):
|
||||
return temp_db_conn
|
||||
|
||||
|
||||
def test_create_functions(temp_db_cursor, conn, def_config, tmp_path):
|
||||
sqlfile = tmp_path / 'functions.sql'
|
||||
def test_create_functions(temp_db_cursor, conn, def_config, sql_tmp_path):
|
||||
sqlfile = sql_tmp_path / 'functions.sql'
|
||||
sqlfile.write_text("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
|
||||
AS $$
|
||||
BEGIN
|
||||
@@ -22,14 +27,14 @@ def test_create_functions(temp_db_cursor, conn, def_config, tmp_path):
|
||||
$$ LANGUAGE plpgsql IMMUTABLE;
|
||||
""")
|
||||
|
||||
create_functions(conn, def_config, tmp_path)
|
||||
create_functions(conn, def_config, sql_tmp_path)
|
||||
|
||||
assert temp_db_cursor.scalar('SELECT test()') == 43
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dbg,ret", ((True, 43), (False, 22)))
|
||||
def test_create_functions_with_template(temp_db_cursor, conn, def_config, tmp_path, dbg, ret):
|
||||
sqlfile = tmp_path / 'functions.sql'
|
||||
def test_create_functions_with_template(temp_db_cursor, conn, def_config, sql_tmp_path, dbg, ret):
|
||||
sqlfile = sql_tmp_path / 'functions.sql'
|
||||
sqlfile.write_text("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
|
||||
AS $$
|
||||
BEGIN
|
||||
@@ -42,6 +47,6 @@ def test_create_functions_with_template(temp_db_cursor, conn, def_config, tmp_pa
|
||||
$$ LANGUAGE plpgsql IMMUTABLE;
|
||||
""")
|
||||
|
||||
create_functions(conn, def_config, tmp_path, enable_debug=dbg)
|
||||
create_functions(conn, def_config, sql_tmp_path, enable_debug=dbg)
|
||||
|
||||
assert temp_db_cursor.scalar('SELECT test()') == ret
|
||||
|
||||
Reference in New Issue
Block a user