fixed two unittests
This commit is contained in:
parent
87289af11a
commit
3e79c98545
|
@ -31,6 +31,14 @@ from cryptobox.core.exceptions import CBInternalError
|
|||
import os
|
||||
|
||||
|
||||
# different commonly available block devices - used for testing major/minor
|
||||
COMMON_DEV_INFOS = [
|
||||
('/sys/block/hda/hda1', '/dev/hda1', '/dev/hda', (3,1)),
|
||||
('/sys/block/sda/sda1', '/dev/sda1', '/dev/sda', (8,1)),
|
||||
('/sys/block/ubda/ubda', '/dev/ubda1', '/dev/ubda', (98,1)),
|
||||
('/sys/block/ubdb/ubdb1', '/dev/ubdb1', '/dev/ubdb', (98,17)),
|
||||
]
|
||||
|
||||
class CoreBlockDevice(CommonTestClass):
|
||||
"""All unittests for cryptoboxtools
|
||||
"""
|
||||
|
@ -39,7 +47,14 @@ class CoreBlockDevice(CommonTestClass):
|
|||
"""check the find_major_minor_of_device function
|
||||
"""
|
||||
func = blockdevice.get_blockdevice
|
||||
self.assertTrue(func('/dev/ram0').devnum == (1, 0))
|
||||
# check if any of the common block devices is available
|
||||
blockdevice_found = False
|
||||
for sys_dir, dev_node, parent, major_minor in COMMON_DEV_INFOS:
|
||||
if os.path.isdir(sys_dir):
|
||||
self.assertTrue(func(dev_node).devnum == major_minor)
|
||||
blockdevice_found = True
|
||||
# we assume, that we found at least one blockdevice
|
||||
self.assertTrue(blockdevice_found)
|
||||
self.assertTrue(func("/dev/nothere") is None)
|
||||
|
||||
|
||||
|
@ -47,13 +62,20 @@ class CoreBlockDevice(CommonTestClass):
|
|||
"""check the is_part_of_blockdevice function
|
||||
"""
|
||||
get_device = lambda devname: blockdevice.get_blockdevice(devname)
|
||||
func = lambda parent, child: get_device(parent).is_parent_of(get_device(child))
|
||||
func = lambda parent, child: get_device(parent) and get_device(parent).is_parent_of(get_device(child))
|
||||
func_raw = lambda parent: get_device(parent).is_parent_of
|
||||
self.assertTrue(func(self.blockdevice, self.device))
|
||||
self.assertFalse(func(self.blockdevice, self.blockdevice))
|
||||
self.assertFalse(func(self.device, self.blockdevice))
|
||||
self.assertFalse(func(self.device, self.device))
|
||||
self.assertFalse(func(self.blockdevice, "/dev/hde1"))
|
||||
# check if any of the common block devices is available
|
||||
blockdevice_found = False
|
||||
for sys_dir, dev_node, parent, major_minor in COMMON_DEV_INFOS:
|
||||
if os.path.isdir(sys_dir):
|
||||
self.assertFalse(func(dev_node, parent))
|
||||
self.assertTrue(func(parent, dev_node))
|
||||
blockdevice_found = True
|
||||
self.assertFalse(func("ram0", "ram1"))
|
||||
self.assertFalse(func_raw(self.blockdevice)(None))
|
||||
self.assertRaises(CBInternalError, func_raw(self.blockdevice), "")
|
||||
|
|
Loading…
Reference in a new issue