diff options
author | Mike Milner <mike.milner@canonical.com> | 2012-01-12 15:31:19 +0100 |
---|---|---|
committer | Mike Milner <mike.milner@canonical.com> | 2012-01-12 15:31:19 +0100 |
commit | 1079cab71db58b92e43d2b920ae18c05e0ea8cd3 (patch) | |
tree | c1578ddbde12b2af641e20dee99ae3d7ca819aca /tests | |
parent | 40267132dff97d9912670dcf49c065d0e9def437 (diff) | |
download | vyos-cloud-init-1079cab71db58b92e43d2b920ae18c05e0ea8cd3.tar.gz vyos-cloud-init-1079cab71db58b92e43d2b920ae18c05e0ea8cd3.zip |
Add initial unit test framework.
Add initial tests for mergedict.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_util.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py new file mode 100644 index 00000000..34a073d9 --- /dev/null +++ b/tests/unittests/test_util.py @@ -0,0 +1,53 @@ +from unittest import TestCase + +from cloudinit.util import mergedict + +class TestMergeDict(TestCase): + def test_simple_merge(self): + source = {"key1": "value1"} + candidate = {"key2": "value2"} + result = mergedict(source, candidate) + self.assertEqual({"key1": "value1", "key2": "value2"}, result) + + def test_nested_merge(self): + source = {"key1": {"key1.1": "value1.1"}} + candidate = {"key1": {"key1.2": "value1.2"}} + result = mergedict(source, candidate) + self.assertEqual( + {"key1": {"key1.1": "value1.1", "key1.2": "value1.2"}}, result) + + def test_merge_does_not_override(self): + source = {"key1": "value1", "key2": "value2"} + candidate = {"key2": "value2", "key2": "NEW VALUE"} + result = mergedict(source, candidate) + self.assertEqual(source, result) + + def test_empty_candidate(self): + source = {"key": "value"} + candidate = {} + result = mergedict(source, candidate) + self.assertEqual(source, result) + + def test_empty_source(self): + source = {} + candidate = {"key": "value"} + result = mergedict(source, candidate) + self.assertEqual(candidate, result) + + def test_non_dict_candidate(self): + source = {"key": "value"} + candidate = "not a dict" + result = mergedict(source, candidate) + self.assertEqual(source, result) + + def test_non_dict_source(self): + source = "not a dict" + candidate = {"key": "value"} + result = mergedict(source, candidate) + self.assertEqual(source, result) + + def test_neither_dict(self): + source = "source" + candidate = "candidate" + result = mergedict(source, candidate) + self.assertEqual(source, result) |