mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 02:47:59 +00:00
use data paths from new nominatim.paths
This commit is contained in:
@@ -53,11 +53,7 @@ def cli_call(src_dir):
|
||||
def _call_nominatim(*args):
|
||||
return nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
|
||||
osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
|
||||
phplib_dir=str(src_dir / 'lib-php'),
|
||||
data_dir=str(src_dir / 'data'),
|
||||
phpcgi_path='/usr/bin/php-cgi',
|
||||
sqllib_dir=str(src_dir / 'lib-sql'),
|
||||
config_dir=str(src_dir / 'settings'),
|
||||
cli_args=args)
|
||||
|
||||
return _call_nominatim
|
||||
|
||||
@@ -82,19 +82,17 @@ def test_cli_export_command(cli_call, mock_run_legacy):
|
||||
('restrict-to-osm-way', '727'),
|
||||
('restrict-to-osm-relation', '197532')
|
||||
])
|
||||
def test_export_parameters(src_dir, tmp_path, param, value):
|
||||
def test_export_parameters(src_dir, tmp_path, param, value, monkeypatch):
|
||||
(tmp_path / 'admin').mkdir()
|
||||
(tmp_path / 'admin' / 'export.php').write_text(f"""<?php
|
||||
exit(strpos(implode(' ', $_SERVER['argv']), '--{param} {value}') >= 0 ? 0 : 10);
|
||||
""")
|
||||
|
||||
monkeypatch.setattr(nominatim.paths, 'PHPLIB_DIR', tmp_path)
|
||||
|
||||
assert nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
|
||||
osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
|
||||
phplib_dir=str(tmp_path),
|
||||
data_dir=str(src_dir / 'data'),
|
||||
phpcgi_path='/usr/bin/php-cgi',
|
||||
sqllib_dir=str(src_dir / 'lib-sql'),
|
||||
config_dir=str(src_dir / 'settings'),
|
||||
cli_args=['export', '--' + param, value]) == 0
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import pytest
|
||||
import nominatim.cli
|
||||
import nominatim.indexer.indexer
|
||||
import nominatim.tools.replication
|
||||
import nominatim.tools.refresh
|
||||
from nominatim.db import status
|
||||
|
||||
@pytest.fixture
|
||||
@@ -107,7 +108,7 @@ class TestCliReplication:
|
||||
def test_replication_update_once_no_index(self, update_mock):
|
||||
assert self.call_nominatim('--once', '--no-index') == 0
|
||||
|
||||
assert str(update_mock.last_args[1]['osm2pgsql']) == 'OSM2PGSQL NOT AVAILABLE'
|
||||
assert str(update_mock.last_args[1]['osm2pgsql']).endswith('OSM2PGSQL NOT AVAILABLE')
|
||||
|
||||
|
||||
def test_replication_update_custom_osm2pgsql(self, monkeypatch, update_mock):
|
||||
|
||||
@@ -14,23 +14,23 @@ from nominatim.config import Configuration, flatten_config_list
|
||||
from nominatim.errors import UsageError
|
||||
|
||||
@pytest.fixture
|
||||
def make_config(src_dir):
|
||||
def make_config():
|
||||
""" Create a configuration object from the given project directory.
|
||||
"""
|
||||
def _mk_config(project_dir=None):
|
||||
return Configuration(project_dir, src_dir / 'settings')
|
||||
return Configuration(project_dir)
|
||||
|
||||
return _mk_config
|
||||
|
||||
@pytest.fixture
|
||||
def make_config_path(src_dir, tmp_path):
|
||||
def make_config_path(tmp_path):
|
||||
""" Create a configuration object with project and config directories
|
||||
in a temporary directory.
|
||||
"""
|
||||
def _mk_config():
|
||||
(tmp_path / 'project').mkdir()
|
||||
(tmp_path / 'config').mkdir()
|
||||
conf = Configuration(tmp_path / 'project', src_dir / 'settings')
|
||||
conf = Configuration(tmp_path / 'project')
|
||||
conf.config_dir = tmp_path / 'config'
|
||||
return conf
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def test_config(src_dir, tmp_path):
|
||||
"""
|
||||
(tmp_path / 'project').mkdir()
|
||||
(tmp_path / 'config').mkdir()
|
||||
conf = Configuration(tmp_path / 'project', src_dir / 'settings')
|
||||
conf = Configuration(tmp_path / 'project')
|
||||
conf.config_dir = tmp_path / 'config'
|
||||
return conf
|
||||
|
||||
|
||||
@@ -107,24 +107,18 @@ def table_factory(temp_db_cursor):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def def_config(src_dir):
|
||||
cfg = Configuration(None, src_dir / 'settings')
|
||||
cfg.set_libdirs(module='.', osm2pgsql='.',
|
||||
php=src_dir / 'lib-php',
|
||||
sql=src_dir / 'lib-sql',
|
||||
data=src_dir / 'data')
|
||||
def def_config():
|
||||
cfg = Configuration(None)
|
||||
cfg.set_libdirs(module='.', osm2pgsql='.')
|
||||
return cfg
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def project_env(src_dir, tmp_path):
|
||||
def project_env(tmp_path):
|
||||
projdir = tmp_path / 'project'
|
||||
projdir.mkdir()
|
||||
cfg = Configuration(projdir, src_dir / 'settings')
|
||||
cfg.set_libdirs(module='.', osm2pgsql='.',
|
||||
php=src_dir / 'lib-php',
|
||||
sql=src_dir / 'lib-sql',
|
||||
data=src_dir / 'data')
|
||||
cfg = Configuration(projdir)
|
||||
cfg.set_libdirs(module='.', osm2pgsql='.')
|
||||
return cfg
|
||||
|
||||
|
||||
@@ -214,9 +208,8 @@ 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, )))
|
||||
cfg = Configuration(None, SRC_DIR.resolve() / 'settings')
|
||||
cfg.set_libdirs(module='.', osm2pgsql='.', php=SRC_DIR / 'lib-php',
|
||||
sql=tmp_path, data=SRC_DIR / 'data')
|
||||
cfg = Configuration(None)
|
||||
cfg.set_libdirs(module='.', osm2pgsql='.', sql=tmp_path)
|
||||
return cfg
|
||||
|
||||
|
||||
|
||||
@@ -12,31 +12,28 @@ import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from nominatim.config import Configuration
|
||||
import nominatim.tools.exec_utils as exec_utils
|
||||
import nominatim.paths
|
||||
|
||||
class TestRunLegacyScript:
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_nominatim_env(self, tmp_path, def_config):
|
||||
def setup_nominatim_env(self, tmp_path, monkeypatch):
|
||||
tmp_phplib_dir = tmp_path / 'phplib'
|
||||
tmp_phplib_dir.mkdir()
|
||||
(tmp_phplib_dir / 'admin').mkdir()
|
||||
|
||||
class _NominatimEnv:
|
||||
config = def_config
|
||||
phplib_dir = tmp_phplib_dir
|
||||
data_dir = Path('data')
|
||||
project_dir = Path('.')
|
||||
sqllib_dir = Path('lib-sql')
|
||||
config_dir = Path('settings')
|
||||
module_dir = 'module'
|
||||
osm2pgsql_path = 'osm2pgsql'
|
||||
monkeypatch.setattr(nominatim.paths, 'PHPLIB_DIR', tmp_phplib_dir)
|
||||
|
||||
self.testenv = _NominatimEnv
|
||||
self.phplib_dir = tmp_phplib_dir
|
||||
self.config = Configuration(tmp_path)
|
||||
self.config.set_libdirs(module='.', osm2pgsql='default_osm2pgsql',
|
||||
php=tmp_phplib_dir)
|
||||
|
||||
|
||||
def mk_script(self, code):
|
||||
codefile = self.testenv.phplib_dir / 'admin' / 't.php'
|
||||
codefile = self.phplib_dir / 'admin' / 't.php'
|
||||
codefile.write_text('<?php\n' + code + '\n')
|
||||
|
||||
return 't.php'
|
||||
@@ -46,25 +43,25 @@ class TestRunLegacyScript:
|
||||
def test_run_legacy_return_exit_code(self, return_code):
|
||||
fname = self.mk_script('exit({});'.format(return_code))
|
||||
assert return_code == \
|
||||
exec_utils.run_legacy_script(fname, nominatim_env=self.testenv)
|
||||
exec_utils.run_legacy_script(fname, config=self.config)
|
||||
|
||||
|
||||
def test_run_legacy_return_throw_on_fail(self):
|
||||
fname = self.mk_script('exit(11);')
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
exec_utils.run_legacy_script(fname, nominatim_env=self.testenv,
|
||||
exec_utils.run_legacy_script(fname, config=self.config,
|
||||
throw_on_fail=True)
|
||||
|
||||
|
||||
def test_run_legacy_return_dont_throw_on_success(self):
|
||||
fname = self.mk_script('exit(0);')
|
||||
assert exec_utils.run_legacy_script(fname, nominatim_env=self.testenv,
|
||||
assert exec_utils.run_legacy_script(fname, config=self.config,
|
||||
throw_on_fail=True) == 0
|
||||
|
||||
def test_run_legacy_use_given_module_path(self):
|
||||
fname = self.mk_script("exit($_SERVER['NOMINATIM_DATABASE_MODULE_PATH'] == '' ? 0 : 23);")
|
||||
|
||||
assert exec_utils.run_legacy_script(fname, nominatim_env=self.testenv) == 0
|
||||
assert exec_utils.run_legacy_script(fname, config=self.config) == 0
|
||||
|
||||
|
||||
def test_run_legacy_do_not_overwrite_module_path(self, monkeypatch):
|
||||
@@ -72,13 +69,13 @@ class TestRunLegacyScript:
|
||||
fname = self.mk_script(
|
||||
"exit($_SERVER['NOMINATIM_DATABASE_MODULE_PATH'] == 'other' ? 0 : 1);")
|
||||
|
||||
assert exec_utils.run_legacy_script(fname, nominatim_env=self.testenv) == 0
|
||||
assert exec_utils.run_legacy_script(fname, config=self.config) == 0
|
||||
|
||||
|
||||
def test_run_legacy_default_osm2pgsql_binary(self, monkeypatch):
|
||||
fname = self.mk_script("exit($_SERVER['NOMINATIM_OSM2PGSQL_BINARY'] == 'osm2pgsql' ? 0 : 23);")
|
||||
fname = self.mk_script("exit($_SERVER['NOMINATIM_OSM2PGSQL_BINARY'] == 'default_osm2pgsql' ? 0 : 23);")
|
||||
|
||||
assert exec_utils.run_legacy_script(fname, nominatim_env=self.testenv) == 0
|
||||
assert exec_utils.run_legacy_script(fname, config=self.config) == 0
|
||||
|
||||
|
||||
def test_run_legacy_override_osm2pgsql_binary(self, monkeypatch):
|
||||
@@ -86,7 +83,7 @@ class TestRunLegacyScript:
|
||||
|
||||
fname = self.mk_script("exit($_SERVER['NOMINATIM_OSM2PGSQL_BINARY'] == 'somethingelse' ? 0 : 23);")
|
||||
|
||||
assert exec_utils.run_legacy_script(fname, nominatim_env=self.testenv) == 0
|
||||
assert exec_utils.run_legacy_script(fname, config=self.config) == 0
|
||||
|
||||
|
||||
class TestRunApiScript:
|
||||
|
||||
Reference in New Issue
Block a user