summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--Makefile14
-rw-r--r--debian.trunk/control3
-rw-r--r--tests/unittests/test_util.py53
4 files changed, 71 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 3dad0f09..a278a514 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,7 @@
- support configuration of landscape-client via cloud-config (LP: #857366)
- part-handlers now get base64 decoded content rather than 2xbase64 encoded
in the payload parameter. (LP: #874342)
+ - add test case framework [Mike Milner] (LP: #890851)
0.6.2:
- fix bug where update was not done unless update was explicitly set.
It would not be run if 'upgrade' or packages were set to be installed
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..0fc6c46b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+
+all: test
+
+pylint:
+ pylint cloudinit
+
+pyflakes:
+ pyflakes .
+
+test:
+ nosetests tests/unittests/
+
+.PHONY: test pylint pyflakes
+
diff --git a/debian.trunk/control b/debian.trunk/control
index 76d0db0d..c877f673 100644
--- a/debian.trunk/control
+++ b/debian.trunk/control
@@ -5,6 +5,9 @@ Maintainer: Scott Moser <smoser@ubuntu.com>
Build-Depends: cdbs,
debhelper (>= 5.0.38),
python (>= 2.6.6-3~),
+ python-nose,
+ pyflakes,
+ pylint,
XS-Python-Version: all
Standards-Version: 3.9.1
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)