~oddbloke/cloud-init/lp1506187

« back to all changes in this revision

Viewing changes to tests/unittests/test_util.py

  • Committer: Scott Moser
  • Date: 2012-01-12 15:42:47 UTC
  • mfrom: (499.1.3 unit-test-framework)
  • Revision ID: smoser@ubuntu.com-20120112154247-1jyza5lfrpcuaf0p
add unit test framework (LP: #890851)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from unittest import TestCase
 
2
 
 
3
from cloudinit.util import mergedict
 
4
 
 
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)
 
11
 
 
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)
 
16
        self.assertEqual(
 
17
            {"key1": {"key1.1": "value1.1", "key1.2": "value1.2"}}, result)
 
18
 
 
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)
 
24
 
 
25
    def test_empty_candidate(self):
 
26
        source = {"key": "value"}
 
27
        candidate = {}
 
28
        result = mergedict(source, candidate)
 
29
        self.assertEqual(source, result)
 
30
 
 
31
    def test_empty_source(self):
 
32
        source = {}
 
33
        candidate = {"key": "value"}
 
34
        result = mergedict(source, candidate)
 
35
        self.assertEqual(candidate, result)
 
36
 
 
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)
 
42
 
 
43
    def test_non_dict_source(self):
 
44
        source = "not a dict"
 
45
        candidate = {"key": "value"}
 
46
        result = mergedict(source, candidate)
 
47
        self.assertEqual(source, result)
 
48
 
 
49
    def test_neither_dict(self):
 
50
        source = "source"
 
51
        candidate = "candidate"
 
52
        result = mergedict(source, candidate)
 
53
        self.assertEqual(source, result)