add test for complex constant
This commit is contained in:
parent
6f300b0079
commit
af95134cd2
2 changed files with 18 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue