X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/9db13aac72f6a023375bbc306ff1ba88ff3dd959..9411c14fd221ac079c5d0977b39ef5d268f25053:/test/python/tools/test_country_info.py diff --git a/test/python/tools/test_country_info.py b/test/python/tools/test_country_info.py index ae3432e7..2651ebd3 100644 --- a/test/python/tools/test_country_info.py +++ b/test/python/tools/test_country_info.py @@ -13,7 +13,9 @@ import pytest from nominatim.tools import country_info @pytest.fixture(autouse=True) -def read_config(def_config): +def read_config(def_config, request): + if 'custom_country_config' in request.keywords: + return country_info.setup_country_config(def_config) @pytest.mark.parametrize("no_partitions", (True, False)) @@ -60,38 +62,41 @@ def test_create_country_names(temp_db_with_extensions, temp_db_conn, temp_db_cur assert result_set == {'us' : set(('us', 'us1', 'us2', 'United States')), 'fr' : set(('fr', 'Fra', 'Fren'))} -@pytest.mark.parametrize("yaml_file_content", ( -""" +@pytest.mark.custom_country_config +def test_setup_country_config_languages_not_loaded(project_env): + (project_env.project_dir / 'country_settings.yaml').write_text(""" de: partition: 3 - names: - name: + names: + name: default: Deutschland -""", -""" +""") + country_info._COUNTRY_INFO._info = None + country_info.setup_country_config(project_env) + assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3, + 'languages': [], 'names': {'name': {'default': 'Deutschland'}}}} + +@pytest.mark.custom_country_config +def test_setup_country_config_name_not_loaded(project_env): + (project_env.project_dir / 'country_settings.yaml').write_text(""" de: partition: 3 languages: de names: -""", -""" +""") + country_info._COUNTRY_INFO._info = None + country_info.setup_country_config(project_env) + assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3, + 'languages': ['de'], 'names': {'name': {}}}} + +@pytest.mark.custom_country_config +def test_setup_country_config_names_not_loaded(project_env): + (project_env.project_dir / 'country_settings.yaml').write_text(""" de: partition: 3 languages: de -""" -)) -def test_load(project_env, def_config, yaml_file_content): - (project_env.project_dir / 'country_settings.yaml').write_text(yaml_file_content) - - country_info._COUNTRY_INFO._info = def_config.load_sub_configuration( - (project_env.project_dir / 'country_settings.yaml')) - - for prop in country_info._COUNTRY_INFO._info.values(): - if 'languages' not in prop: - prop['languages'] = [] - assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3, - 'languages': [], 'names': {'name': {'default': 'Deutschland'}}}} - if 'names' not in prop or prop['names'] is None: - prop['names'] = {'name': {}} - assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3, - 'languages': 'de', 'names': {'name': {}}}} \ No newline at end of file +""") + country_info._COUNTRY_INFO._info = None + country_info.setup_country_config(project_env) + assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3, + 'languages': ['de'], 'names': {'name': {}}}}