"""
Tests for functions to import a new database.
"""
+from pathlib import Path
+
import pytest
import psycopg2
-import sys
-from pathlib import Path
from nominatim.tools import database_import
from nominatim.errors import UsageError
try:
with conn.cursor() as cur:
cur.execute("SELECT distinct partition FROM country_name")
- partitions = set([r[0] for r in list(cur)])
+ partitions = set((r[0] for r in list(cur)))
if no_partitions:
- assert partitions == set([0])
+ assert partitions == set((0, ))
else:
assert len(partitions) > 10
finally:
def test_import_osm_data_simple(table_factory, osm2pgsql_options):
table_factory('place', content=((1, ), ))
- database_import.import_osm_data('file.pdf', osm2pgsql_options)
+ database_import.import_osm_data(Path('file.pbf'), osm2pgsql_options)
+
+
+def test_import_osm_data_multifile(table_factory, tmp_path, osm2pgsql_options):
+ table_factory('place', content=((1, ), ))
+ osm2pgsql_options['osm2pgsql_cache'] = 0
+
+ files = [tmp_path / 'file1.osm', tmp_path / 'file2.osm']
+ for f in files:
+ f.write_text('test')
+
+ database_import.import_osm_data(files, osm2pgsql_options)
def test_import_osm_data_simple_no_data(table_factory, osm2pgsql_options):
table_factory('place')
with pytest.raises(UsageError, match='No data.*'):
- database_import.import_osm_data('file.pdf', osm2pgsql_options)
+ database_import.import_osm_data(Path('file.pbf'), osm2pgsql_options)
def test_import_osm_data_drop(table_factory, temp_db_conn, tmp_path, osm2pgsql_options):
osm2pgsql_options['flatnode_file'] = str(flatfile.resolve())
- database_import.import_osm_data('file.pdf', osm2pgsql_options, drop=True)
+ database_import.import_osm_data(Path('file.pbf'), osm2pgsql_options, drop=True)
assert not flatfile.exists()
assert not temp_db_conn.table_exists('planet_osm_nodes')
@pytest.mark.parametrize("threads", (1, 5))
-def test_load_data(dsn, src_dir, place_row, placex_table, osmline_table,
+def test_load_data(dsn, place_row, placex_table, osmline_table,
word_table, temp_db_cursor, threads):
for func in ('precompute_words', 'getorcreate_housenumber_id', 'make_standard_name'):
temp_db_cursor.execute("""CREATE FUNCTION {} (src TEXT)
assert len(tokenizer.analyser_cache['countries']) == 2
- result_set = {k: set(v) for k, v in tokenizer.analyser_cache['countries']}
+ result_set = {k: set(v.values()) for k, v in tokenizer.analyser_cache['countries']}
if languages:
assert result_set == {'us' : set(('us', 'us1', 'United States')),