diff --git a/benedict/dicts/__init__.py b/benedict/dicts/__init__.py index c582149..e3f7928 100644 --- a/benedict/dicts/__init__.py +++ b/benedict/dicts/__init__.py @@ -26,6 +26,7 @@ from benedict.dicts.io import IODict from benedict.dicts.keyattr import KeyattrDict from benedict.dicts.keylist import KeylistDict from benedict.dicts.keypath import KeypathDict +from benedict.dicts.keypath import keypath_util from benedict.dicts.parse import ParseDict from benedict.serializers import JSONSerializer, YAMLSerializer @@ -219,7 +220,10 @@ class benedict(KeyattrDict, KeypathDict, IODict, ParseDict): If overwrite is False, existing values will not be overwritten. If concat is True, list values will be concatenated together. """ - _merge(self, other, *args, **kwargs) + others = [other] + list(args) + for other in others: + keypath_util.check_keys(other, self._keypath_separator) + _merge(self, *others, **kwargs) def move(self, key_src, key_dest): """ diff --git a/tests/github/test_issue_0367.py b/tests/github/test_issue_0367.py new file mode 100644 index 0000000..03fb549 --- /dev/null +++ b/tests/github/test_issue_0367.py @@ -0,0 +1,33 @@ +import unittest + +from benedict import benedict + + +class github_issue_0367_test_case(unittest.TestCase): + """ + This class describes a github issue 0367 test case. + https://github.com/fabiocaccamo/python-benedict/issues/367 + + To run this specific test: + - Run python -m unittest tests.github.test_issue_0367 + """ + + def test_dict_keys_with_separators_with_merge(self): + d = {"foo.bar": 1} + b = benedict() + with self.assertRaises(ValueError): + b.merge(d) + # self.assertEqual(b, {"foo": {"bar": 1}}) + + def test_dict_keys_with_separators_with_nested_merge(self): + d = {"baz": {"foo.bar": 1}} + b = benedict() + with self.assertRaises(ValueError): + b.merge(d) + # self.assertEqual(b, {"baz": {"foo.bar": 1}}) + + def test_dict_keys_with_separators_with_constructor(self): + d = {"foo.bar": 1} + with self.assertRaises(ValueError): + benedict(d) + # self.assertEqual(b, {"foo": {"bar": 1}})