1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for function that handle country properties.
13 from nominatim.tools import country_info
15 @pytest.fixture(autouse=True)
16 def read_config(def_config):
17 country_info.setup_country_config(def_config)
19 @pytest.mark.parametrize("no_partitions", (True, False))
20 def test_setup_country_tables(src_dir, temp_db_with_extensions, dsn, temp_db_cursor,
21 def_config, no_partitions):
22 country_info.setup_country_tables(dsn, src_dir / 'data', no_partitions)
24 assert temp_db_cursor.table_exists('country_name')
25 assert temp_db_cursor.table_rows('country_name') == \
26 temp_db_cursor.scalar('SELECT count(DISTINCT country_code) FROM country_name')
28 partitions = temp_db_cursor.row_set("SELECT DISTINCT partition FROM country_name")
30 assert partitions == {(0, )}
32 assert len(partitions) > 10
34 assert temp_db_cursor.table_exists('country_osm_grid')
35 assert temp_db_cursor.table_rows('country_osm_grid') > 100
38 @pytest.mark.parametrize("languages", (None, ' fr,en'))
39 def test_create_country_names(temp_db_with_extensions, temp_db_conn, temp_db_cursor,
40 table_factory, tokenizer_mock, languages):
42 table_factory('country_name', 'country_code varchar(2), name hstore',
43 content=(('us', '"name"=>"us1","name:af"=>"us2"'),
44 ('fr', '"name"=>"Fra", "name:en"=>"Fren"')))
46 assert temp_db_cursor.scalar("SELECT count(*) FROM country_name") == 2
48 tokenizer = tokenizer_mock()
50 country_info.create_country_names(temp_db_conn, tokenizer, languages)
52 assert len(tokenizer.analyser_cache['countries']) == 2
54 result_set = {k: set(v.values()) for k, v in tokenizer.analyser_cache['countries']}
57 assert result_set == {'us' : set(('us', 'us1', 'United States')),
58 'fr' : set(('fr', 'Fra', 'Fren'))}
60 assert result_set == {'us' : set(('us', 'us1', 'us2', 'United States')),
61 'fr' : set(('fr', 'Fra', 'Fren'))}