summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorMike Milner <mike.milner@canonical.com>2012-01-12 16:10:03 +0100
committerMike Milner <mike.milner@canonical.com>2012-01-12 16:10:03 +0100
commit6ceb460199720335e70ed6965a0f393563ba730d (patch)
tree734e0f3483761617e60ebe1f89cd95e716b232e3 /tests/unittests
parenteea65faf117d6d3e8566d419477e7e54209100c1 (diff)
parentdc6fa5f447599ea097ecf31023ba30aa5de5accf (diff)
downloadvyos-cloud-init-6ceb460199720335e70ed6965a0f393563ba730d.tar.gz
vyos-cloud-init-6ceb460199720335e70ed6965a0f393563ba730d.zip
Merge from unittest branch.
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_util.py53
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)