1
from unittest import TestCase
3
from cloudinit.util import mergedict
5
class TestMergeDict(TestCase):
6
def test_simple_merge(self):
7
source = {"key1": "value1"}
8
candidate = {"key2": "value2"}
9
result = mergedict(source, candidate)
10
self.assertEqual({"key1": "value1", "key2": "value2"}, result)
12
def test_nested_merge(self):
13
source = {"key1": {"key1.1": "value1.1"}}
14
candidate = {"key1": {"key1.2": "value1.2"}}
15
result = mergedict(source, candidate)
17
{"key1": {"key1.1": "value1.1", "key1.2": "value1.2"}}, result)
19
def test_merge_does_not_override(self):
20
source = {"key1": "value1", "key2": "value2"}
21
candidate = {"key2": "value2", "key2": "NEW VALUE"}
22
result = mergedict(source, candidate)
23
self.assertEqual(source, result)
25
def test_empty_candidate(self):
26
source = {"key": "value"}
28
result = mergedict(source, candidate)
29
self.assertEqual(source, result)
31
def test_empty_source(self):
33
candidate = {"key": "value"}
34
result = mergedict(source, candidate)
35
self.assertEqual(candidate, result)
37
def test_non_dict_candidate(self):
38
source = {"key": "value"}
39
candidate = "not a dict"
40
result = mergedict(source, candidate)
41
self.assertEqual(source, result)
43
def test_non_dict_source(self):
45
candidate = {"key": "value"}
46
result = mergedict(source, candidate)
47
self.assertEqual(source, result)
49
def test_neither_dict(self):
51
candidate = "candidate"
52
result = mergedict(source, candidate)
53
self.assertEqual(source, result)