Merge lp:~milner/cloud-init/unit-test-framework into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Mike Milner
Status: Merged
Merged at revision: 501
Proposed branch: lp:~milner/cloud-init/unit-test-framework
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 92 lines (+70/-0)
3 files modified
Makefile (+14/-0)
debian.trunk/control (+3/-0)
tests/unittests/test_util.py (+53/-0)
To merge this branch: bzr merge lp:~milner/cloud-init/unit-test-framework
Reviewer Review Type Date Requested Status
Scott Moser Pending
Review via email: mp+88390@code.launchpad.net

Description of the change

Add a basic unit test framework and example tests for cloudinit.util.mergedict

To run tests type "make test"
To check code you can use "make lint" and "make pyflakes"

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'Makefile'
2--- Makefile 1970-01-01 00:00:00 +0000
3+++ Makefile 2012-01-12 15:12:28 +0000
4@@ -0,0 +1,14 @@
5+
6+all: test
7+
8+pylint:
9+ pylint cloudinit
10+
11+pyflakes:
12+ pyflakes .
13+
14+test:
15+ nosetests tests/unittests/
16+
17+.PHONY: test pylint pyflakes
18+
19
20=== modified file 'debian.trunk/control'
21--- debian.trunk/control 2011-12-20 21:27:33 +0000
22+++ debian.trunk/control 2012-01-12 15:12:28 +0000
23@@ -5,6 +5,9 @@
24 Build-Depends: cdbs,
25 debhelper (>= 5.0.38),
26 python (>= 2.6.6-3~),
27+ python-nose,
28+ pyflakes,
29+ pylint,
30 XS-Python-Version: all
31 Standards-Version: 3.9.1
32
33
34=== added directory 'tests'
35=== added directory 'tests/unittests'
36=== added file 'tests/unittests/test_util.py'
37--- tests/unittests/test_util.py 1970-01-01 00:00:00 +0000
38+++ tests/unittests/test_util.py 2012-01-12 15:12:28 +0000
39@@ -0,0 +1,53 @@
40+from unittest import TestCase
41+
42+from cloudinit.util import mergedict
43+
44+class TestMergeDict(TestCase):
45+ def test_simple_merge(self):
46+ source = {"key1": "value1"}
47+ candidate = {"key2": "value2"}
48+ result = mergedict(source, candidate)
49+ self.assertEqual({"key1": "value1", "key2": "value2"}, result)
50+
51+ def test_nested_merge(self):
52+ source = {"key1": {"key1.1": "value1.1"}}
53+ candidate = {"key1": {"key1.2": "value1.2"}}
54+ result = mergedict(source, candidate)
55+ self.assertEqual(
56+ {"key1": {"key1.1": "value1.1", "key1.2": "value1.2"}}, result)
57+
58+ def test_merge_does_not_override(self):
59+ source = {"key1": "value1", "key2": "value2"}
60+ candidate = {"key2": "value2", "key2": "NEW VALUE"}
61+ result = mergedict(source, candidate)
62+ self.assertEqual(source, result)
63+
64+ def test_empty_candidate(self):
65+ source = {"key": "value"}
66+ candidate = {}
67+ result = mergedict(source, candidate)
68+ self.assertEqual(source, result)
69+
70+ def test_empty_source(self):
71+ source = {}
72+ candidate = {"key": "value"}
73+ result = mergedict(source, candidate)
74+ self.assertEqual(candidate, result)
75+
76+ def test_non_dict_candidate(self):
77+ source = {"key": "value"}
78+ candidate = "not a dict"
79+ result = mergedict(source, candidate)
80+ self.assertEqual(source, result)
81+
82+ def test_non_dict_source(self):
83+ source = "not a dict"
84+ candidate = {"key": "value"}
85+ result = mergedict(source, candidate)
86+ self.assertEqual(source, result)
87+
88+ def test_neither_dict(self):
89+ source = "source"
90+ candidate = "candidate"
91+ result = mergedict(source, candidate)
92+ self.assertEqual(source, result)