-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
71 lines (60 loc) · 2.77 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# Uncomplicated VM Builder
# Copyright (C) 2007-2009 Canonical Ltd.
#
# See AUTHORS for list of contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Tests, tests, tests, and more tests
import unittest
import VMBuilder.disk
class TestSequenceFunctions(unittest.TestCase):
def test_parse_size(self):
self.assertEqual(VMBuilder.disk.parse_size(10), 10)
self.assertEqual(VMBuilder.disk.parse_size('10'), 10)
self.assertEqual(VMBuilder.disk.parse_size('10m'), 10)
self.assertEqual(VMBuilder.disk.parse_size('10M'), 10)
self.assertEqual(VMBuilder.disk.parse_size('10G'), 10240)
self.assertEqual(VMBuilder.disk.parse_size('10g'), 10240)
self.assertEqual(VMBuilder.disk.parse_size('10240K'), 10)
self.assertEqual(VMBuilder.disk.parse_size('10240k'), 10)
self.assertEqual(VMBuilder.disk.parse_size('10250K'), 10)
def test_index_to_devname(self):
self.assertEqual(VMBuilder.disk.index_to_devname(0), 'a')
self.assertEqual(VMBuilder.disk.index_to_devname(26), 'aa')
self.assertEqual(VMBuilder.disk.index_to_devname(18277), 'zzz')
def test_devname_to_index(self):
self.assertEqual(VMBuilder.disk.devname_to_index('a'), 0)
self.assertEqual(VMBuilder.disk.devname_to_index('b'), 1)
self.assertEqual(VMBuilder.disk.devname_to_index('aa'), 26)
self.assertEqual(VMBuilder.disk.devname_to_index('z'), 25)
self.assertEqual(VMBuilder.disk.devname_to_index('zz'), 701)
self.assertEqual(VMBuilder.disk.devname_to_index('zzz'), 18277)
class TestUbuntuPlugin(unittest.TestCase):
def test_preflight_check_failed(self):
import VMBuilder
from VMBuilder.plugins.ubuntu.distro import Ubuntu
from VMBuilder.exception import VMBuilderUserError
vm = VMBuilder.VM()
vm.suite = 'foo'
ubuntu = Ubuntu(vm)
self.assertRaises(VMBuilderUserError, ubuntu.preflight_check)
class TestUtils(unittest.TestCase):
def test_run_cmd(self):
import VMBuilder
from VMBuilder.util import run_cmd
self.assertTrue("foobarbaztest" in
run_cmd("env", env={'foobarbaztest' : 'bar' }))
if __name__ == '__main__':
unittest.main()