2 Tests for function that handle country properties.
 
   7 from nominatim.tools import country_info
 
   9 @pytest.fixture(autouse=True)
 
  10 def read_config(def_config):
 
  11     country_info.setup_country_config(def_config)
 
  13 @pytest.mark.parametrize("no_partitions", (True, False))
 
  14 def test_setup_country_tables(src_dir, temp_db_with_extensions, dsn, temp_db_cursor,
 
  15                               def_config, no_partitions):
 
  16     country_info.setup_country_tables(dsn, src_dir / 'data', no_partitions)
 
  18     assert temp_db_cursor.table_exists('country_name')
 
  19     assert temp_db_cursor.table_rows('country_name') == \
 
  20              temp_db_cursor.scalar('SELECT count(DISTINCT country_code) FROM country_name')
 
  22     partitions = temp_db_cursor.row_set("SELECT DISTINCT partition FROM country_name")
 
  24         assert partitions == {(0, )}
 
  26         assert len(partitions) > 10
 
  28     assert temp_db_cursor.table_exists('country_osm_grid')
 
  29     assert temp_db_cursor.table_rows('country_osm_grid') > 100
 
  32 @pytest.mark.parametrize("languages", (None, ' fr,en'))
 
  33 def test_create_country_names(temp_db_with_extensions, temp_db_conn, temp_db_cursor,
 
  34                               table_factory, tokenizer_mock, languages):
 
  36     table_factory('country_name', 'country_code varchar(2), name hstore',
 
  37                   content=(('us', '"name"=>"us1","name:af"=>"us2"'),
 
  38                            ('fr', '"name"=>"Fra", "name:en"=>"Fren"')))
 
  40     assert temp_db_cursor.scalar("SELECT count(*) FROM country_name") == 2
 
  42     tokenizer = tokenizer_mock()
 
  44     country_info.create_country_names(temp_db_conn, tokenizer, languages)
 
  46     assert len(tokenizer.analyser_cache['countries']) == 2
 
  48     result_set = {k: set(v.values()) for k, v in tokenizer.analyser_cache['countries']}
 
  51         assert result_set == {'us' : set(('us', 'us1', 'United States')),
 
  52                               'fr' : set(('fr', 'Fra', 'Fren'))}
 
  54         assert result_set == {'us' : set(('us', 'us1', 'us2', 'United States')),
 
  55                               'fr' : set(('fr', 'Fra', 'Fren'))}