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
=== modified file '.bzrignore'
--- .bzrignore 2009-02-01 00:21:17 +0000
+++ .bzrignore 2009-09-12 18:27:38 +0000
@@ -1,3 +1,9 @@
1Doxyfile1Doxyfile
2doc2doc
3.bzrignore3.bzrignore
4.coverage
5coverage-report
6VMBuilder.egg-info
7build
8stamp
9VMBuilder/vcsversion.py
410
=== added file 'Makefile'
--- Makefile 1970-01-01 00:00:00 +0000
+++ Makefile 2009-09-12 18:28:24 +0000
@@ -0,0 +1,19 @@
1#!/usr/bin/make -f
2
3test: clean stamp
4 @nosetests --verbose
5
6stamp:
7 @touch $@
8
9build:
10 @python setup.py bdist_egg sdist
11
12coverage:
13 @nosetests --quiet --with-coverage --cover-package VMBuilder
14
15report:
16 @nosetests --quiet --with-coverage --cover-package VMBuilder --cover-html --cover-html-dir coverage-report
17
18clean:
19 @rm -rf stamp .coverage coverage-report
020
=== added directory 'test'
=== renamed file 'tests.py' => 'test/__init__.py'
--- tests.py 2009-06-10 13:40:41 +0000
+++ test/__init__.py 2009-09-12 18:43:24 +0000
@@ -15,57 +15,3 @@
15#15#
16# You should have received a copy of the GNU General Public License16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19# Tests, tests, tests, and more tests
20import unittest
21import VMBuilder.disk
22
23class TestSequenceFunctions(unittest.TestCase):
24 def test_parse_size(self):
25 self.assertEqual(VMBuilder.disk.parse_size(10), 10)
26 self.assertEqual(VMBuilder.disk.parse_size('10'), 10)
27 self.assertEqual(VMBuilder.disk.parse_size('10m'), 10)
28 self.assertEqual(VMBuilder.disk.parse_size('10M'), 10)
29 self.assertEqual(VMBuilder.disk.parse_size('10G'), 10240)
30 self.assertEqual(VMBuilder.disk.parse_size('10g'), 10240)
31 self.assertEqual(VMBuilder.disk.parse_size('10240K'), 10)
32 self.assertEqual(VMBuilder.disk.parse_size('10240k'), 10)
33 self.assertEqual(VMBuilder.disk.parse_size('10250K'), 10)
34
35 def test_index_to_devname(self):
36 self.assertEqual(VMBuilder.disk.index_to_devname(0), 'a')
37 self.assertEqual(VMBuilder.disk.index_to_devname(26), 'aa')
38 self.assertEqual(VMBuilder.disk.index_to_devname(18277), 'zzz')
39
40 def test_devname_to_index(self):
41 self.assertEqual(VMBuilder.disk.devname_to_index('a'), 0)
42 self.assertEqual(VMBuilder.disk.devname_to_index('b'), 1)
43 self.assertEqual(VMBuilder.disk.devname_to_index('aa'), 26)
44 self.assertEqual(VMBuilder.disk.devname_to_index('z'), 25)
45 self.assertEqual(VMBuilder.disk.devname_to_index('zz'), 701)
46 self.assertEqual(VMBuilder.disk.devname_to_index('zzz'), 18277)
47
48class TestUbuntuPlugin(unittest.TestCase):
49 def test_preflight_check_failed(self):
50 import VMBuilder
51 from VMBuilder.plugins.ubuntu.distro import Ubuntu
52 from VMBuilder.exception import VMBuilderUserError
53
54 vm = VMBuilder.VM()
55 vm.suite = 'foo'
56 ubuntu = Ubuntu(vm)
57 self.assertRaises(VMBuilderUserError, ubuntu.preflight_check)
58
59
60class TestUtils(unittest.TestCase):
61 def test_run_cmd(self):
62 import VMBuilder
63 from VMBuilder.util import run_cmd
64 self.assertTrue("foobarbaztest" in
65 run_cmd("env", env={'foobarbaztest' : 'bar' }))
66
67
68
69if __name__ == '__main__':
70 unittest.main()
71
7218
=== added file 'test/log_tests.py'
--- test/log_tests.py 1970-01-01 00:00:00 +0000
+++ test/log_tests.py 2009-09-12 18:28:24 +0000
@@ -0,0 +1,19 @@
1import unittest
2
3from VMBuilder.log import console, set_verbosity
4import logging
5
6class LogTestSuite(unittest.TestCase):
7 def test_verbosityOptions(self):
8 'Using --debug, --verbose and --quiet flags set proper log levels'
9
10 checks = [
11 ('--debug', logging.DEBUG),
12 ('--verbose', logging.INFO),
13 ('--quiet', logging.CRITICAL),
14 ]
15
16 for opt, level in checks:
17 set_verbosity(None, opt, None, None)
18 self.assertEquals(level, console.level, 'Found wrong logging level after setting flag "%s"' % opt)
19
020
=== added file 'test/ubuntu_tests.py'
--- test/ubuntu_tests.py 1970-01-01 00:00:00 +0000
+++ test/ubuntu_tests.py 2009-09-12 18:28:24 +0000
@@ -0,0 +1,38 @@
1#
2# Uncomplicated VM Builder
3# Copyright (C) 2007-2009 Canonical Ltd.
4#
5# See AUTHORS for list of contributors
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 3, as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19# Tests, tests, tests, and more tests
20
21import unittest
22
23import VMBuilder
24
25from VMBuilder.plugins.ubuntu.distro import Ubuntu
26from VMBuilder.exception import VMBuilderUserError
27from VMBuilder.log import set_verbosity
28
29class TestUbuntuPlugin(unittest.TestCase):
30 def setUp(self):
31 set_verbosity(None, '--quiet', None, None)
32
33 def test_invalidSuiteRaisesUserError(self):
34 'Building Ubuntu VMs with an invalid suite raises UserError'
35 vm = VMBuilder.VM()
36 vm.suite = 'foo'
37 ubuntu = Ubuntu(vm)
38 self.assertRaises(VMBuilderUserError, ubuntu.preflight_check)
039
=== added file 'test/util_tests.py'
--- test/util_tests.py 1970-01-01 00:00:00 +0000
+++ test/util_tests.py 2009-09-12 19:01:53 +0000
@@ -0,0 +1,9 @@
1import unittest
2
3import VMBuilder
4from VMBuilder.util import run_cmd
5
6class TestUtils(unittest.TestCase):
7 def test_run_cmd(self):
8 self.assertTrue("foobarbaztest" in run_cmd("env", env={'foobarbaztest' : 'bar' }))
9

Subscribers

People subscribed via source and target branches