forked from hans/Nominatim
'read_config' is no longer a fixture
add 'read_config' to test cases that need it
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
markers =
|
markers =
|
||||||
sanitizer_params,
|
sanitizer_params
|
||||||
custom_country_config
|
|
||||||
@@ -12,22 +12,24 @@ import pytest
|
|||||||
|
|
||||||
from nominatim.tools import country_info
|
from nominatim.tools import country_info
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def read_config(def_config, request):
|
def read_config(def_config):
|
||||||
if 'custom_country_config' in request.keywords:
|
|
||||||
return
|
|
||||||
country_info.setup_country_config(def_config)
|
country_info.setup_country_config(def_config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("no_partitions", (True, False))
|
@pytest.mark.parametrize("no_partitions", (True, False))
|
||||||
def test_setup_country_tables(src_dir, temp_db_with_extensions, dsn, temp_db_cursor,
|
def test_setup_country_tables(src_dir, temp_db_with_extensions, dsn, temp_db_cursor,
|
||||||
def_config, no_partitions):
|
def_config, no_partitions):
|
||||||
|
read_config(def_config)
|
||||||
country_info.setup_country_tables(dsn, src_dir / 'data', no_partitions)
|
country_info.setup_country_tables(dsn, src_dir / 'data', no_partitions)
|
||||||
|
|
||||||
assert temp_db_cursor.table_exists('country_name')
|
assert temp_db_cursor.table_exists('country_name')
|
||||||
assert temp_db_cursor.table_rows('country_name') == \
|
assert temp_db_cursor.table_rows('country_name') == \
|
||||||
temp_db_cursor.scalar('SELECT count(DISTINCT country_code) FROM country_name')
|
temp_db_cursor.scalar(
|
||||||
|
'SELECT count(DISTINCT country_code) FROM country_name')
|
||||||
|
|
||||||
partitions = temp_db_cursor.row_set("SELECT DISTINCT partition FROM country_name")
|
partitions = temp_db_cursor.row_set(
|
||||||
|
"SELECT DISTINCT partition FROM country_name")
|
||||||
if no_partitions:
|
if no_partitions:
|
||||||
assert partitions == {(0, )}
|
assert partitions == {(0, )}
|
||||||
else:
|
else:
|
||||||
@@ -39,7 +41,8 @@ def test_setup_country_tables(src_dir, temp_db_with_extensions, dsn, temp_db_cur
|
|||||||
|
|
||||||
@pytest.mark.parametrize("languages", (None, ' fr,en'))
|
@pytest.mark.parametrize("languages", (None, ' fr,en'))
|
||||||
def test_create_country_names(temp_db_with_extensions, temp_db_conn, temp_db_cursor,
|
def test_create_country_names(temp_db_with_extensions, temp_db_conn, temp_db_cursor,
|
||||||
table_factory, tokenizer_mock, languages):
|
table_factory, tokenizer_mock, languages, def_config):
|
||||||
|
read_config(def_config)
|
||||||
|
|
||||||
table_factory('country_name', 'country_code varchar(2), name hstore',
|
table_factory('country_name', 'country_code varchar(2), name hstore',
|
||||||
content=(('us', '"name"=>"us1","name:af"=>"us2"'),
|
content=(('us', '"name"=>"us1","name:af"=>"us2"'),
|
||||||
@@ -53,16 +56,17 @@ def test_create_country_names(temp_db_with_extensions, temp_db_conn, temp_db_cur
|
|||||||
|
|
||||||
assert len(tokenizer.analyser_cache['countries']) == 2
|
assert len(tokenizer.analyser_cache['countries']) == 2
|
||||||
|
|
||||||
result_set = {k: set(v.values()) for k, v in tokenizer.analyser_cache['countries']}
|
result_set = {k: set(v.values())
|
||||||
|
for k, v in tokenizer.analyser_cache['countries']}
|
||||||
|
|
||||||
if languages:
|
if languages:
|
||||||
assert result_set == {'us' : set(('us', 'us1', 'United States')),
|
assert result_set == {'us': set(('us', 'us1', 'United States')),
|
||||||
'fr' : set(('fr', 'Fra', 'Fren'))}
|
'fr': set(('fr', 'Fra', 'Fren'))}
|
||||||
else:
|
else:
|
||||||
assert result_set == {'us' : set(('us', 'us1', 'us2', 'United States')),
|
assert result_set == {'us': set(('us', 'us1', 'us2', 'United States')),
|
||||||
'fr' : set(('fr', 'Fra', 'Fren'))}
|
'fr': set(('fr', 'Fra', 'Fren'))}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.custom_country_config
|
|
||||||
def test_setup_country_config_languages_not_loaded(project_env):
|
def test_setup_country_config_languages_not_loaded(project_env):
|
||||||
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
||||||
de:
|
de:
|
||||||
@@ -74,9 +78,9 @@ de:
|
|||||||
country_info._COUNTRY_INFO._info = None
|
country_info._COUNTRY_INFO._info = None
|
||||||
country_info.setup_country_config(project_env)
|
country_info.setup_country_config(project_env)
|
||||||
assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3,
|
assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3,
|
||||||
'languages': [], 'names': {'name': {'default': 'Deutschland'}}}}
|
'languages': [], 'names': {'name': {'default': 'Deutschland'}}}}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.custom_country_config
|
|
||||||
def test_setup_country_config_name_not_loaded(project_env):
|
def test_setup_country_config_name_not_loaded(project_env):
|
||||||
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
||||||
de:
|
de:
|
||||||
@@ -87,9 +91,9 @@ de:
|
|||||||
country_info._COUNTRY_INFO._info = None
|
country_info._COUNTRY_INFO._info = None
|
||||||
country_info.setup_country_config(project_env)
|
country_info.setup_country_config(project_env)
|
||||||
assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3,
|
assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3,
|
||||||
'languages': ['de'], 'names': {'name': {}}}}
|
'languages': ['de'], 'names': {'name': {}}}}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.custom_country_config
|
|
||||||
def test_setup_country_config_names_not_loaded(project_env):
|
def test_setup_country_config_names_not_loaded(project_env):
|
||||||
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
||||||
de:
|
de:
|
||||||
@@ -99,9 +103,9 @@ de:
|
|||||||
country_info._COUNTRY_INFO._info = None
|
country_info._COUNTRY_INFO._info = None
|
||||||
country_info.setup_country_config(project_env)
|
country_info.setup_country_config(project_env)
|
||||||
assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3,
|
assert country_info._COUNTRY_INFO._info == {'de': {'partition': 3,
|
||||||
'languages': ['de'], 'names': {'name': {}}}}
|
'languages': ['de'], 'names': {'name': {}}}}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.custom_country_config
|
|
||||||
def test_setup_country_config_special_character(project_env):
|
def test_setup_country_config_special_character(project_env):
|
||||||
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
(project_env.project_dir / 'country_settings.yaml').write_text("""
|
||||||
bq:
|
bq:
|
||||||
@@ -114,4 +118,4 @@ bq:
|
|||||||
country_info._COUNTRY_INFO._info = None
|
country_info._COUNTRY_INFO._info = None
|
||||||
country_info.setup_country_config(project_env)
|
country_info.setup_country_config(project_env)
|
||||||
assert country_info._COUNTRY_INFO._info == {'bq': {'partition': 250,
|
assert country_info._COUNTRY_INFO._info == {'bq': {'partition': 250,
|
||||||
'languages': ['nl'], 'names': {'name': {'default': '\x85'}}}}
|
'languages': ['nl'], 'names': {'name': {'default': '\x85'}}}}
|
||||||
|
|||||||
Reference in New Issue
Block a user