Fix for unclear error message for invalid YAML merge include (#196).

This commit is contained in:
Dan Helfman 2019-06-16 21:33:40 -07:00
parent eaa5eb4174
commit 6c136ebbf1
5 changed files with 31 additions and 4 deletions

3
NEWS
View file

@ -1,3 +1,6 @@
1.3.7.dev0
* #196: Fix for unclear error message for invalid YAML merge include.
1.3.6
* #53: Log to syslog in addition to existing console logging. Add --syslog-verbosity flag to
customize the log level. See the documentation for more information:

View file

@ -54,9 +54,7 @@ class Include_constructor(ruamel.yaml.SafeConstructor):
for index, (key_node, value_node) in enumerate(node.value):
if key_node.tag == u'tag:yaml.org,2002:merge' and value_node.tag == '!include':
included_value = representer.represent_mapping(
tag='tag:yaml.org,2002:map', mapping=self.construct_object(value_node)
)
included_value = representer.represent_data(self.construct_object(value_node))
node.value[index] = (key_node, included_value)
super(Include_constructor, self).flatten_mapping(node)

View file

@ -105,6 +105,10 @@ include, the local file's option takes precedent. And note that this is a
shallow merge rather than a deep merge, so the merging does not descend into
nested values.
Note that this `<<` include merging syntax is only for merging in mappings
(keys/values). If you'd like to include other types like scalars or lists
directly, please see the section above about standard includes.
## Related documentation

View file

@ -1,6 +1,6 @@
from setuptools import find_packages, setup
VERSION = '1.3.6'
VERSION = '1.3.7.dev0'
setup(

View file

@ -1,5 +1,7 @@
import sys
import pytest
import ruamel.yaml
from flexmock import flexmock
from borgmatic.config import load as module
@ -38,3 +40,23 @@ def test_load_configuration_merges_include():
)
assert module.load_configuration('config.yaml') == {'foo': 'override', 'baz': 'quux'}
def test_load_configuration_does_not_merge_include_list():
builtins = flexmock(sys.modules['builtins'])
builtins.should_receive('open').with_args('include.yaml').and_return(
'''
- one
- two
'''
)
builtins.should_receive('open').with_args('config.yaml').and_return(
'''
foo: bar
repositories:
<<: !include include.yaml
'''
)
with pytest.raises(ruamel.yaml.error.YAMLError):
assert module.load_configuration('config.yaml')