1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for tools.exec_utils module.
10 from pathlib import Path
15 from nominatim.config import Configuration
16 import nominatim.tools.exec_utils as exec_utils
17 import nominatim.paths
20 class TestRunApiScript:
23 @pytest.fixture(autouse=True)
24 def setup_project_dir(tmp_path):
25 webdir = tmp_path / 'website'
27 (webdir / 'test.php').write_text("<?php\necho 'OK\n';")
31 def test_run_api(tmp_path):
32 assert exec_utils.run_api_script('test', tmp_path) == 0
35 def test_run_api_execution_error(tmp_path):
36 assert exec_utils.run_api_script('badname', tmp_path) != 0
39 def test_run_api_with_extra_env(tmp_path):
40 extra_env = dict(SCRIPT_FILENAME=str(tmp_path / 'website' / 'test.php'))
41 assert exec_utils.run_api_script('badname', tmp_path, extra_env=extra_env) == 0
44 def test_custom_phpcgi(tmp_path, capfd):
45 assert exec_utils.run_api_script('test', tmp_path, phpcgi_bin='env',
46 params={'q' : 'Berlin'}) == 0
47 captured = capfd.readouterr()
49 assert '?q=Berlin' in captured.out
52 def test_fail_on_error_output(tmp_path):
53 # Starting PHP 8 the PHP CLI no longer has STDERR defined as constant
56 if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'wb'));
57 fwrite(STDERR, 'WARNING'.PHP_EOL);
59 (tmp_path / 'website' / 'bad.php').write_text(php)
61 assert exec_utils.run_api_script('bad', tmp_path) == 1
65 def test_run_osm2pgsql(osm2pgsql_options):
66 osm2pgsql_options['append'] = False
67 osm2pgsql_options['import_file'] = 'foo.bar'
68 osm2pgsql_options['tablespaces']['slim_data'] = 'extra'
69 exec_utils.run_osm2pgsql(osm2pgsql_options)
72 def test_run_osm2pgsql_disable_jit(osm2pgsql_options):
73 osm2pgsql_options['append'] = True
74 osm2pgsql_options['import_file'] = 'foo.bar'
75 osm2pgsql_options['disable_jit'] = True
76 exec_utils.run_osm2pgsql(osm2pgsql_options)