diff --git a/borgmatic/config/load.py b/borgmatic/config/load.py index e379537..3218112 100644 --- a/borgmatic/config/load.py +++ b/borgmatic/config/load.py @@ -1,4 +1,5 @@ import functools +import json import logging import os @@ -104,7 +105,8 @@ def load_configuration(filename): config = yaml.load(file_contents) if config and 'constants' in config: for key, value in config['constants'].items(): - file_contents = file_contents.replace(f'{{{key}}}', str(value)) + value = json.dumps(value) + file_contents = file_contents.replace(f'{{{key}}}', value) config = yaml.load(file_contents) del config['constants'] return config diff --git a/tests/integration/config/test_load.py b/tests/integration/config/test_load.py index 5b8ee9b..3382d73 100644 --- a/tests/integration/config/test_load.py +++ b/tests/integration/config/test_load.py @@ -30,6 +30,21 @@ def test_load_configuration_replaces_constants(): assert module.load_configuration('config.yaml') == {'key': 'value'} +def test_load_configuration_replaces_complex_constants(): + builtins = flexmock(sys.modules['builtins']) + config_file = io.StringIO( + ''' + constants: + key: + subkey: value + key: {key} + ''' + ) + config_file.name = 'config.yaml' + builtins.should_receive('open').with_args('config.yaml').and_return(config_file) + assert module.load_configuration('config.yaml') == {'key': {'subkey': 'value'}} + + def test_load_configuration_inlines_include_relative_to_current_directory(): builtins = flexmock(sys.modules['builtins']) flexmock(module.os).should_receive('getcwd').and_return('/tmp')