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
=== added file 'Makefile'
--- Makefile 1970-01-01 00:00:00 +0000
+++ Makefile 2012-01-12 15:12:28 +0000
@@ -0,0 +1,14 @@
1
2all: test
3
4pylint:
5 pylint cloudinit
6
7pyflakes:
8 pyflakes .
9
10test:
11 nosetests tests/unittests/
12
13.PHONY: test pylint pyflakes
14
015
=== modified file 'debian.trunk/control'
--- debian.trunk/control 2011-12-20 21:27:33 +0000
+++ debian.trunk/control 2012-01-12 15:12:28 +0000
@@ -5,6 +5,9 @@
5Build-Depends: cdbs, 5Build-Depends: cdbs,
6 debhelper (>= 5.0.38), 6 debhelper (>= 5.0.38),
7 python (>= 2.6.6-3~),7 python (>= 2.6.6-3~),
8 python-nose,
9 pyflakes,
10 pylint,
8XS-Python-Version: all11XS-Python-Version: all
9Standards-Version: 3.9.112Standards-Version: 3.9.1
1013
1114
=== added directory 'tests'
=== added directory 'tests/unittests'
=== added file 'tests/unittests/test_util.py'
--- tests/unittests/test_util.py 1970-01-01 00:00:00 +0000
+++ tests/unittests/test_util.py 2012-01-12 15:12:28 +0000
@@ -0,0 +1,53 @@
1from unittest import TestCase
2
3from cloudinit.util import mergedict
4
5class 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)