]> git.openstreetmap.org Git - nominatim.git/blob - test/python/test_tools_tiger_data.py
Added fixture for sql_preprocessor and fixed some issues
[nominatim.git] / test / python / test_tools_tiger_data.py
1 """
2 Test for tiger data function
3 """
4 from pathlib import Path
5
6 import pytest
7 import tarfile
8
9 from nominatim.tools import tiger_data, database_import
10
11
12 @pytest.mark.parametrize("threads", (1, 5))
13 def test_add_tiger_data(dsn, src_dir, def_config, tmp_path, sql_preprocessor,
14                         temp_db_cursor, threads, temp_db):
15     temp_db_cursor.execute('CREATE EXTENSION hstore')
16     temp_db_cursor.execute('CREATE EXTENSION postgis')
17     temp_db_cursor.execute('CREATE TABLE place (id INT)')
18     sqlfile = tmp_path / '1010.sql'
19     sqlfile.write_text("""INSERT INTO place values (1)""")
20     tiger_data.add_tiger_data(dsn, str(tmp_path), threads, def_config, src_dir / 'lib-sql')
21
22     assert temp_db_cursor.table_rows('place') == 1
23
24 @pytest.mark.parametrize("threads", (1, 5))
25 def test_add_tiger_data_tarfile(dsn, src_dir, def_config, tmp_path,
26                         temp_db_cursor, threads, temp_db, sql_preprocessor):
27     temp_db_cursor.execute('CREATE EXTENSION hstore')
28     temp_db_cursor.execute('CREATE EXTENSION postgis')
29     temp_db_cursor.execute('CREATE TABLE place (id INT)')
30     sqlfile = tmp_path / '1010.sql'
31     sqlfile.write_text("""INSERT INTO place values (1)""")
32     tar = tarfile.open("sample.tar.gz", "w:gz")
33     tar.add(sqlfile)
34     tar.close()
35     tiger_data.add_tiger_data(dsn, str(src_dir / 'sample.tar.gz'), threads, def_config, src_dir / 'lib-sql')
36     
37     assert temp_db_cursor.table_rows('place') == 1