Merge lp:~ilowe/vmbuilder/unittest-coverage into lp:vmbuilder/trunk

Proposed by Iain Lowe
Status: Merged
Merge reported by: Iain Lowe
Merged at revision: not available
Proposed branch: lp:~ilowe/vmbuilder/unittest-coverage
Merge into: lp:vmbuilder/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~ilowe/vmbuilder/unittest-coverage
Reviewer Review Type Date Requested Status
Soren Hansen Needs Information
Review via email: mp+11657@code.launchpad.net
To post a comment you must log in.
342. By Iain Lowe

Added 'interface_implements' decorator to test suite

Revision history for this message
Soren Hansen (soren) wrote :

I don't think I see the purpose of the the interface_implements decorator.

a) You don't use it anywhere.
b) I don't understand why you do this as a decorator rather than a simple function?

I'm renaming a bunch of the unit test methods from e.g. test_parseSizeRoundsToNearestMB to test_rounds_size_to_nearest_megabyte as this is more in line with the rest of the project. Don't worry about this, I already have a patch ready for it.

Other than that, it looks really good. My experience with unit tests is rather limited, so I didn't know about these tools. Very handy indeed. Thanks!

review: Needs Information
Revision history for this message
Soren Hansen (soren) wrote :

I merged up until r341, deferring r342 until we've discussed the decorator thing.

Revision history for this message
Iain Lowe (ilowe) wrote :

I think something in the other branch must depend on the decorator;
IIRC there are a couple of "interface detecting" tests that I factored
out of somewhere. Don't worry about it, leave r342 and I'll just grab
the other branch and clean it up so they go in together. I think the
"why" of the decorator is clearer when paired with the code that uses
it (or at least I *hope* it is).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2009-02-01 00:21:17 +0000
3+++ .bzrignore 2009-09-12 18:27:38 +0000
4@@ -1,3 +1,9 @@
5 Doxyfile
6 doc
7 .bzrignore
8+.coverage
9+coverage-report
10+VMBuilder.egg-info
11+build
12+stamp
13+VMBuilder/vcsversion.py
14
15=== added file 'Makefile'
16--- Makefile 1970-01-01 00:00:00 +0000
17+++ Makefile 2009-09-12 18:28:24 +0000
18@@ -0,0 +1,19 @@
19+#!/usr/bin/make -f
20+
21+test: clean stamp
22+ @nosetests --verbose
23+
24+stamp:
25+ @touch $@
26+
27+build:
28+ @python setup.py bdist_egg sdist
29+
30+coverage:
31+ @nosetests --quiet --with-coverage --cover-package VMBuilder
32+
33+report:
34+ @nosetests --quiet --with-coverage --cover-package VMBuilder --cover-html --cover-html-dir coverage-report
35+
36+clean:
37+ @rm -rf stamp .coverage coverage-report
38
39=== added directory 'test'
40=== renamed file 'tests.py' => 'test/__init__.py'
41--- tests.py 2009-06-10 13:40:41 +0000
42+++ test/__init__.py 2009-09-12 18:43:24 +0000
43@@ -15,57 +15,3 @@
44 #
45 # You should have received a copy of the GNU General Public License
46 # along with this program. If not, see <http://www.gnu.org/licenses/>.
47-#
48-# Tests, tests, tests, and more tests
49-import unittest
50-import VMBuilder.disk
51-
52-class TestSequenceFunctions(unittest.TestCase):
53- def test_parse_size(self):
54- self.assertEqual(VMBuilder.disk.parse_size(10), 10)
55- self.assertEqual(VMBuilder.disk.parse_size('10'), 10)
56- self.assertEqual(VMBuilder.disk.parse_size('10m'), 10)
57- self.assertEqual(VMBuilder.disk.parse_size('10M'), 10)
58- self.assertEqual(VMBuilder.disk.parse_size('10G'), 10240)
59- self.assertEqual(VMBuilder.disk.parse_size('10g'), 10240)
60- self.assertEqual(VMBuilder.disk.parse_size('10240K'), 10)
61- self.assertEqual(VMBuilder.disk.parse_size('10240k'), 10)
62- self.assertEqual(VMBuilder.disk.parse_size('10250K'), 10)
63-
64- def test_index_to_devname(self):
65- self.assertEqual(VMBuilder.disk.index_to_devname(0), 'a')
66- self.assertEqual(VMBuilder.disk.index_to_devname(26), 'aa')
67- self.assertEqual(VMBuilder.disk.index_to_devname(18277), 'zzz')
68-
69- def test_devname_to_index(self):
70- self.assertEqual(VMBuilder.disk.devname_to_index('a'), 0)
71- self.assertEqual(VMBuilder.disk.devname_to_index('b'), 1)
72- self.assertEqual(VMBuilder.disk.devname_to_index('aa'), 26)
73- self.assertEqual(VMBuilder.disk.devname_to_index('z'), 25)
74- self.assertEqual(VMBuilder.disk.devname_to_index('zz'), 701)
75- self.assertEqual(VMBuilder.disk.devname_to_index('zzz'), 18277)
76-
77-class TestUbuntuPlugin(unittest.TestCase):
78- def test_preflight_check_failed(self):
79- import VMBuilder
80- from VMBuilder.plugins.ubuntu.distro import Ubuntu
81- from VMBuilder.exception import VMBuilderUserError
82-
83- vm = VMBuilder.VM()
84- vm.suite = 'foo'
85- ubuntu = Ubuntu(vm)
86- self.assertRaises(VMBuilderUserError, ubuntu.preflight_check)
87-
88-
89-class TestUtils(unittest.TestCase):
90- def test_run_cmd(self):
91- import VMBuilder
92- from VMBuilder.util import run_cmd
93- self.assertTrue("foobarbaztest" in
94- run_cmd("env", env={'foobarbaztest' : 'bar' }))
95-
96-
97-
98-if __name__ == '__main__':
99- unittest.main()
100-
101
102=== added file 'test/log_tests.py'
103--- test/log_tests.py 1970-01-01 00:00:00 +0000
104+++ test/log_tests.py 2009-09-12 18:28:24 +0000
105@@ -0,0 +1,19 @@
106+import unittest
107+
108+from VMBuilder.log import console, set_verbosity
109+import logging
110+
111+class LogTestSuite(unittest.TestCase):
112+ def test_verbosityOptions(self):
113+ 'Using --debug, --verbose and --quiet flags set proper log levels'
114+
115+ checks = [
116+ ('--debug', logging.DEBUG),
117+ ('--verbose', logging.INFO),
118+ ('--quiet', logging.CRITICAL),
119+ ]
120+
121+ for opt, level in checks:
122+ set_verbosity(None, opt, None, None)
123+ self.assertEquals(level, console.level, 'Found wrong logging level after setting flag "%s"' % opt)
124+
125
126=== added file 'test/ubuntu_tests.py'
127--- test/ubuntu_tests.py 1970-01-01 00:00:00 +0000
128+++ test/ubuntu_tests.py 2009-09-12 18:28:24 +0000
129@@ -0,0 +1,38 @@
130+#
131+# Uncomplicated VM Builder
132+# Copyright (C) 2007-2009 Canonical Ltd.
133+#
134+# See AUTHORS for list of contributors
135+#
136+# This program is free software: you can redistribute it and/or modify
137+# it under the terms of the GNU General Public License version 3, as
138+# published by the Free Software Foundation.
139+#
140+# This program is distributed in the hope that it will be useful,
141+# but WITHOUT ANY WARRANTY; without even the implied warranty of
142+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
143+# GNU General Public License for more details.
144+#
145+# You should have received a copy of the GNU General Public License
146+# along with this program. If not, see <http://www.gnu.org/licenses/>.
147+#
148+# Tests, tests, tests, and more tests
149+
150+import unittest
151+
152+import VMBuilder
153+
154+from VMBuilder.plugins.ubuntu.distro import Ubuntu
155+from VMBuilder.exception import VMBuilderUserError
156+from VMBuilder.log import set_verbosity
157+
158+class TestUbuntuPlugin(unittest.TestCase):
159+ def setUp(self):
160+ set_verbosity(None, '--quiet', None, None)
161+
162+ def test_invalidSuiteRaisesUserError(self):
163+ 'Building Ubuntu VMs with an invalid suite raises UserError'
164+ vm = VMBuilder.VM()
165+ vm.suite = 'foo'
166+ ubuntu = Ubuntu(vm)
167+ self.assertRaises(VMBuilderUserError, ubuntu.preflight_check)
168
169=== added file 'test/util_tests.py'
170--- test/util_tests.py 1970-01-01 00:00:00 +0000
171+++ test/util_tests.py 2009-09-12 19:01:53 +0000
172@@ -0,0 +1,9 @@
173+import unittest
174+
175+import VMBuilder
176+from VMBuilder.util import run_cmd
177+
178+class TestUtils(unittest.TestCase):
179+ def test_run_cmd(self):
180+ self.assertTrue("foobarbaztest" in run_cmd("env", env={'foobarbaztest' : 'bar' }))
181+

Subscribers

People subscribed via source and target branches