From ccfad57fcab0559ad780f9c703c6e059e7e359ad Mon Sep 17 00:00:00 2001 From: Darkshredder Date: Wed, 10 Mar 2021 17:18:12 +0530 Subject: [PATCH] Added test and removed runlegacyscript --- nominatim/cli.py | 8 ++++++-- test/python/test_cli.py | 1 - test/python/test_tools_tiger_data.py | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/python/test_tools_tiger_data.py diff --git a/nominatim/cli.py b/nominatim/cli.py index 7459711f..b3d9eee6 100644 --- a/nominatim/cli.py +++ b/nominatim/cli.py @@ -13,6 +13,7 @@ from .tools.exec_utils import run_legacy_script, run_php_server from .errors import UsageError from . import clicmd from .clicmd.args import NominatimArgs +from .tools import tiger_data LOG = logging.getLogger() @@ -166,8 +167,11 @@ class UpdateAddData: @staticmethod def run(args): if args.tiger_data: - os.environ['NOMINATIM_TIGER_DATA_PATH'] = args.tiger_data - return run_legacy_script('setup.php', '--import-tiger-data', nominatim_env=args) + return tiger_data.add_tiger_data(args.config.get_libpq_dsn(), + args.tiger_data, + args.threads or 1, + args.config, + args.sqllib_dir) params = ['update.php'] if args.file: diff --git a/test/python/test_cli.py b/test/python/test_cli.py index 418f4bcf..1f9cd06d 100644 --- a/test/python/test_cli.py +++ b/test/python/test_cli.py @@ -65,7 +65,6 @@ def test_cli_help(capsys): @pytest.mark.parametrize("command,script", [ (('special-phrases',), 'specialphrases'), - (('add-data', '--tiger-data', 'tiger'), 'setup'), (('add-data', '--file', 'foo.osm'), 'update'), (('export',), 'export') ]) diff --git a/test/python/test_tools_tiger_data.py b/test/python/test_tools_tiger_data.py new file mode 100644 index 00000000..63e72e16 --- /dev/null +++ b/test/python/test_tools_tiger_data.py @@ -0,0 +1,25 @@ +""" +Test for tiger data function +""" +from pathlib import Path + +import pytest + +from nominatim.tools import tiger_data, database_import + + +@pytest.mark.parametrize("threads", (1, 5)) +def test_add_tiger_data(dsn, src_dir, def_config, monkeypatch,tmp_path, + temp_db_cursor, threads, temp_db): + monkeypatch.setenv('NOMINATIM_DATABASE_MODULE_PATH', '.') + temp_db_cursor.execute('CREATE EXTENSION hstore') + temp_db_cursor.execute('CREATE EXTENSION postgis') + temp_db_cursor.execute('CREATE TABLE place (id INT)') + + database_import.import_base_data('dbname=' + temp_db, src_dir / 'data', + ignore_partitions=False) + sqlfile = tmp_path / '1010.sql' + sqlfile.write_text("""INSERT INTO place values (1)""") + tiger_data.add_tiger_data(dsn, str(tmp_path), threads, def_config, src_dir / 'lib-sql') + + assert temp_db_cursor.table_rows('place') == 1 \ No newline at end of file