From: Sarah Hoffmann Date: Thu, 14 Jan 2021 17:19:22 +0000 (+0100) Subject: bdd: directly call utility scripts in lib X-Git-Tag: v3.7.0~57^2~2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/2f73bb36435c6e1a9b84745b4763a063e6391602?ds=sidebyside bdd: directly call utility scripts in lib This removes the dependency on php-symfony-dotenv for the tests. --- diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 8dd19aa4..e57431c0 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -47,7 +47,7 @@ jobs: - name: Install test prerequsites run: | - sudo apt-get install -y -qq php-codesniffer python3-tidylib php-symfony-dotenv + sudo apt-get install -y -qq php-codesniffer sudo pip3 install behave - name: PHP linting diff --git a/nominatim/config.py b/nominatim/config.py index 6395bf2a..911c7ddf 100644 --- a/nominatim/config.py +++ b/nominatim/config.py @@ -21,7 +21,8 @@ class Configuration: def __init__(self, project_dir, config_dir): self._config = dotenv_values(str((config_dir / 'env.defaults').resolve())) - self._config.update(dotenv_values(str((project_dir / '.env').resolve()))) + if project_dir is not None: + self._config.update(dotenv_values(str((project_dir / '.env').resolve()))) def __getattr__(self, name): name = 'NOMINATIM_' + name diff --git a/test/bdd/environment.py b/test/bdd/environment.py index cadfda18..30ea30a2 100644 --- a/test/bdd/environment.py +++ b/test/bdd/environment.py @@ -1,6 +1,7 @@ -from behave import * from pathlib import Path +from behave import * + from steps.geometry_factory import GeometryFactory from steps.nominatim_environment import NominatimEnvironment diff --git a/test/bdd/steps/nominatim_environment.py b/test/bdd/steps/nominatim_environment.py index e799306a..68d7b2f4 100644 --- a/test/bdd/steps/nominatim_environment.py +++ b/test/bdd/steps/nominatim_environment.py @@ -1,10 +1,13 @@ -import os from pathlib import Path +import sys import tempfile import psycopg2 import psycopg2.extras +sys.path.insert(1, str((Path(__file__) / '..' / '..' / '..' / '..').resolve())) + +from nominatim.config import Configuration from steps.utils import run_script class NominatimEnvironment: @@ -28,6 +31,7 @@ class NominatimEnvironment: self.code_coverage_path = config['PHPCOV'] self.code_coverage_id = 1 + self.default_config = Configuration(None, self.src_dir / 'settings').get_os_env() self.test_env = None self.template_db_done = False self.api_db_done = False @@ -78,11 +82,15 @@ class NominatimEnvironment: and dsn == self.test_env['NOMINATIM_DATABASE_DSN']: return # environment already set uo - self.test_env = os.environ + self.test_env = dict(self.default_config) self.test_env['NOMINATIM_DATABASE_DSN'] = dsn self.test_env['NOMINATIM_FLATNODE_FILE'] = '' self.test_env['NOMINATIM_IMPORT_STYLE'] = 'full' self.test_env['NOMINATIM_USE_US_TIGER_DATA'] = 'yes' + self.test_env['NOMINATIM_DATADIR'] = self.src_dir + self.test_env['NOMINATIM_BINDIR'] = self.src_dir / 'utils' + self.test_env['NOMINATIM_DATABASE_MODULE_PATH'] = self.build_dir / 'module' + self.test_env['NOMINATIM_OSM2PGSQL_BINARY'] = self.build_dir / 'osm2pgsql' / 'osm2pgsql' if self.server_module_path: self.test_env['NOMINATIM_DATABASE_MODULE_PATH'] = self.server_module_path @@ -253,7 +261,7 @@ class NominatimEnvironment: """ Run one of the Nominatim utility scripts with the given arguments. """ cmd = ['/usr/bin/env', 'php', '-Cq'] - cmd.append((Path(self.build_dir) / 'utils' / '{}.php'.format(script)).resolve()) + cmd.append((Path(self.src_dir) / 'lib' / 'admin' / '{}.php'.format(script)).resolve()) cmd.extend(['--' + x for x in args]) for k, v in kwargs.items(): cmd.extend(('--' + k.replace('_', '-'), str(v))) @@ -261,7 +269,7 @@ class NominatimEnvironment: if self.website_dir is not None: cwd = self.website_dir.name else: - cwd = self.build_dir + cwd = None run_script(cmd, cwd=cwd, env=self.test_env) diff --git a/test/bdd/steps/steps_api_queries.py b/test/bdd/steps/steps_api_queries.py index 7b3597da..a56081c0 100644 --- a/test/bdd/steps/steps_api_queries.py +++ b/test/bdd/steps/steps_api_queries.py @@ -59,7 +59,7 @@ def query_cmd(context, query, dups): """ Query directly via PHP script. """ cmd = ['/usr/bin/env', 'php'] - cmd.append(os.path.join(context.nominatim.build_dir, 'utils', 'query.php')) + cmd.append(context.nominatim.src_dir / 'lib' / 'admin' / 'query.php') if query: cmd.extend(['--search', query]) # add more parameters in table form @@ -72,7 +72,8 @@ def query_cmd(context, query, dups): if dups: cmd.extend(('--dedupe', '0')) - outp, err = run_script(cmd, cwd=context.nominatim.build_dir) + outp, err = run_script(cmd, cwd=context.nominatim.website_dir.name, + env=context.nominatim.test_env) context.response = SearchResponse(outp, 'json')