From: Sarah Hoffmann Date: Wed, 20 Jan 2021 08:02:45 +0000 (+0100) Subject: add tests for Python exec_utils X-Git-Tag: v3.7.0~49^2~6 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/52b76d1d0164149446c497121225aa3bf36f1148?hp=a3767f9142d19970371c1dfd3bdb624fc94d3c58 add tests for Python exec_utils --- diff --git a/nominatim/tools/exec_utils.py b/nominatim/tools/exec_utils.py index d5b08392..9e16e293 100644 --- a/nominatim/tools/exec_utils.py +++ b/nominatim/tools/exec_utils.py @@ -68,7 +68,10 @@ def run_api_script(endpoint, project_dir, extra_env=None, phpcgi_bin=None, check=False) if proc.returncode != 0 or proc.stderr: - log.error(proc.stderr.decode('utf-8').replace('\\n', '\n')) + if proc.stderr: + log.error(proc.stderr.decode('utf-8').replace('\\n', '\n')) + else: + log.error(proc.stdout.decode('utf-8').replace('\\n', '\n')) return proc.returncode or 1 result = proc.stdout.decode('utf-8') diff --git a/test/python/test_tools_exec_utils.py b/test/python/test_tools_exec_utils.py new file mode 100644 index 00000000..d9f80740 --- /dev/null +++ b/test/python/test_tools_exec_utils.py @@ -0,0 +1,102 @@ +""" +Tests for tools.exec_utils module. +""" +from pathlib import Path +import subprocess +import tempfile + +import pytest + +from nominatim.config import Configuration +import nominatim.tools.exec_utils as exec_utils + +@pytest.fixture +def tmp_phplib_dir(): + with tempfile.TemporaryDirectory() as phpdir: + (Path(phpdir) / 'admin').mkdir() + + yield Path(phpdir) + +@pytest.fixture +def nominatim_env(tmp_phplib_dir): + class _NominatimEnv: + config = Configuration(None, Path(__file__) / '..' / '..' / '..' / 'settings') + phplib_dir = tmp_phplib_dir + data_dir = Path('data') + project_dir = Path('.') + module_dir = 'module' + osm2pgsql_path = 'osm2pgsql' + + return _NominatimEnv + +@pytest.fixture +def test_script(nominatim_env): + def _create_file(code): + with (nominatim_env.phplib_dir / 'admin' / 't.php').open(mode='w') as fd: + fd.write('