#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for loading dotenv configuration.
from nominatim_db.config import Configuration, flatten_config_list
from nominatim_db.errors import UsageError
+
@pytest.fixture
def make_config():
""" Create a configuration object from the given project directory.
return _mk_config
+
@pytest.fixture
def make_config_path(tmp_path):
""" Create a configuration object with project and config directories
@pytest.mark.parametrize("val,expect", [('foo bar', "'foo bar'"),
("xy'z", "xy\\'z"),
- ])
+ ])
def test_get_libpq_dsn_convert_php_special_chars(make_config, monkeypatch, val, expect):
config = make_config()
assert config.get_bool('FOOBAR') == result
+
def test_get_bool_empty(make_config):
config = make_config()
(config.config_dir / 'test.yaml').write_text('cow: muh\ncat: miau\n')
with pytest.raises(UsageError, match='Config file not found.'):
- rules = config.load_sub_configuration('test.yaml', config='MY_CONFIG')
+ config.load_sub_configuration('test.yaml', config='MY_CONFIG')
@pytest.mark.parametrize("location", ['project_dir', 'config_dir'])
(config.config_dir / 'test.yaml').write_text('cow: muh\ncat: miau\n')
with pytest.raises(UsageError, match='Config file not found.'):
- rules = config.load_sub_configuration('test.yaml', config='MY_CONFIG')
+ config.load_sub_configuration('test.yaml', config='MY_CONFIG')
def test_load_subconf_json(make_config_path):
assert rules == dict(cow='muh', cat='miau')
+
def test_load_subconf_not_found(make_config_path):
config = make_config_path()
config = make_config_path()
testfile = config.config_dir / 'test.yaml'
- testfile.write_text(f'base: !include inc.yaml\n')
+ testfile.write_text('base: !include inc.yaml\n')
(getattr(config, location) / 'inc.yaml').write_text('first: 1\nsecond: 2\n')
rules = config.load_sub_configuration('test.yaml')
config = make_config_path()
testfile = config.config_dir / 'test.yaml'
- testfile.write_text(f'base: !include inc.txt\n')
+ testfile.write_text('base: !include inc.txt\n')
(config.config_dir / 'inc.txt').write_text('first: 1\nsecond: 2\n')
with pytest.raises(UsageError, match='Cannot handle config file format.'):
- rules = config.load_sub_configuration('test.yaml')
+ config.load_sub_configuration('test.yaml')
def test_load_subconf_include_not_found(make_config_path):
config = make_config_path()
testfile = config.config_dir / 'test.yaml'
- testfile.write_text(f'base: !include inc.txt\n')
+ testfile.write_text('base: !include inc.txt\n')
with pytest.raises(UsageError, match='Config file not found.'):
- rules = config.load_sub_configuration('test.yaml')
+ config.load_sub_configuration('test.yaml')
def test_load_subconf_include_recursive(make_config_path):
config = make_config_path()
testfile = config.config_dir / 'test.yaml'
- testfile.write_text(f'base: !include inc.yaml\n')
+ testfile.write_text('base: !include inc.yaml\n')
(config.config_dir / 'inc.yaml').write_text('- !include more.yaml\n- upper\n')
(config.config_dir / 'more.yaml').write_text('- the end\n')
[[2, 3], [45, [56, 78], 66]],
'end'
]
+
assert flatten_config_list(content) == \
- [34, {'first': '1st', 'second': '2nd'}, {},
- 2, 3, 45, 56, 78, 66, 'end']
+ [34, {'first': '1st', 'second': '2nd'}, {}, 2, 3, 45, 56, 78, 66, 'end']