Moves extend paths from tools to ConfigLoader

This commit is contained in:
Sergi Delgado Segura
2020-03-23 13:04:50 +01:00
parent e2ce7ae1a4
commit 02eefd5807
4 changed files with 37 additions and 41 deletions

View File

@@ -219,3 +219,26 @@ def test_create_config_dict_invalid_type():
with pytest.raises(ValueError):
conf_loader.create_config_dict()
def test_extend_paths():
# Test that only items with the path flag are extended
foo_data_dir = "foo/"
default_conf_copy = deepcopy(DEFAULT_CONF)
conf_loader = ConfigLoader(foo_data_dir, conf_file_name, default_conf_copy, {})
conf_loader.extend_paths()
for k, field in conf_loader.conf_fields.items():
if isinstance(field.get("value"), str):
if field.get("path") is True:
assert conf_loader.data_dir in field.get("value")
else:
assert conf_loader.data_dir not in field.get("value")
# Check that absolute paths are not extended
absolute_path = "/foo/var"
conf_loader.conf_fields["ABSOLUTE_PATH"] = {"value": absolute_path, "type": str, "path": True}
conf_loader.extend_paths()
assert conf_loader.conf_fields["ABSOLUTE_PATH"]["value"] == absolute_path

View File

@@ -7,7 +7,6 @@ from common.tools import (
check_locator_format,
compute_locator,
setup_data_folder,
extend_paths,
setup_logging,
)
from test.common.unit.conftest import get_random_value_hex
@@ -66,23 +65,6 @@ def test_setup_data_folder():
os.rmdir(test_folder)
def test_extend_paths():
# Test that only items with the path flag are extended
config_fields = {
"foo": {"value": "foofoo"},
"var": {"value": "varvar", "path": True},
"foovar": {"value": "foovarfoovar"},
}
base_path = "base_path/"
extend_paths(base_path, config_fields)
for k, field in config_fields.items():
if field.get("path") is True:
assert base_path in field.get("value")
else:
assert base_path not in field.get("value")
def test_setup_logging():
# Check that setup_logging creates two new logs for every prefix
prefix = "foo"