]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/helper.py
1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
5 from typing
import Dict
, Any
10 def update_dict(data
, update_data
):
11 # type: (Dict[Any, Any], Dict[Any, Any]) -> Dict[Any]
12 """ Update a dictionary recursively.
14 Eases doing so by providing the option to separate the key to be updated by dot characters. If
15 a key provided does not exist, it will raise an KeyError instead of just updating the
20 Please note that the functionality provided by this method can only be used if the dictionary to
21 be updated (`data`) does not contain dot characters in its keys.
25 >>> update_dict({'foo': {'bar': 5}}, {'foo.bar': 10})
28 >>> update_dict({'foo': {'bar': 5}}, {'xyz': 10})
29 Traceback (most recent call last):
33 >>> update_dict({'foo': {'bar': 5}}, {'foo.xyz': 10})
34 Traceback (most recent call last):
38 for k
, v
in update_data
.items():
41 for i
, key
in enumerate(keys
):
43 if len(keys
) == i
+ 1:
49 element
= element
[key
] # pylint: disable=unsubscriptable-object
52 if key
not in element
: