2 Test for tiger data function
4 from pathlib import Path
9 from nominatim.tools import tiger_data, database_import
12 @pytest.mark.parametrize("threads", (1, 5))
13 def test_add_tiger_data(def_config, tmp_path, sql_preprocessor,
14 temp_db_cursor, threads, temp_db_with_extensions):
15 temp_db_cursor.execute('CREATE TABLE place (id INT)')
16 sqlfile = tmp_path / '1010.sql'
17 sqlfile.write_text("""INSERT INTO place values (1);
18 INSERT INTO non_existant_table values (1);""")
19 tiger_data.add_tiger_data(str(tmp_path), def_config, threads)
21 assert temp_db_cursor.table_rows('place') == 1
24 @pytest.mark.parametrize("threads", (1, 5))
25 def test_add_tiger_data_bad_file(def_config, tmp_path, sql_preprocessor,
26 temp_db_cursor, threads, temp_db_with_extensions):
27 temp_db_cursor.execute('CREATE TABLE place (id INT)')
28 sqlfile = tmp_path / '1010.txt'
29 sqlfile.write_text("""Random text""")
30 tiger_data.add_tiger_data(str(tmp_path), def_config, threads)
32 assert temp_db_cursor.table_rows('place') == 0
35 @pytest.mark.parametrize("threads", (1, 5))
36 def test_add_tiger_data_tarfile(def_config, tmp_path, temp_db_cursor,
37 threads, temp_db_with_extensions, sql_preprocessor):
38 temp_db_cursor.execute('CREATE TABLE place (id INT)')
39 sqlfile = tmp_path / '1010.sql'
40 sqlfile.write_text("""INSERT INTO place values (1);
41 INSERT INTO non_existant_table values (1);""")
42 tar = tarfile.open(str(tmp_path / 'sample.tar.gz'), "w:gz")
45 tiger_data.add_tiger_data(str(tmp_path / 'sample.tar.gz'), def_config, threads)
47 assert temp_db_cursor.table_rows('place') == 1
50 @pytest.mark.parametrize("threads", (1, 5))
51 def test_add_tiger_data_bad_tarfile(def_config, tmp_path, temp_db_cursor, threads,
52 temp_db_with_extensions, sql_preprocessor):
53 temp_db_cursor.execute('CREATE TABLE place (id INT)')
54 sqlfile = tmp_path / '1010.txt'
55 sqlfile.write_text("""Random text""")
56 tar = tarfile.open(str(tmp_path / 'sample.tar.gz'), "w:gz")
59 tiger_data.add_tiger_data(str(tmp_path / 'sample.tar.gz'), def_config, threads)
61 assert temp_db_cursor.table_rows('place') == 0