92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
|
#!/usr/bin/env python
|
||
|
#
|
||
|
# Copyright 2006 sense.lab e.V.
|
||
|
#
|
||
|
# This file is part of the CryptoBox.
|
||
|
#
|
||
|
# The CryptoBox is free software; you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation; either version 2 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# The CryptoBox 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 the CryptoBox; if not, write to the Free Software
|
||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
#
|
||
|
|
||
|
"""Unittests for cryptobox.core.tools
|
||
|
"""
|
||
|
|
||
|
__revision__ = "$Id"
|
||
|
|
||
|
|
||
|
import unittest
|
||
|
import cryptobox.core.tools as cbx_tools
|
||
|
import os
|
||
|
|
||
|
## use /dev/ubd? if possible - otherwise /dev/hd?
|
||
|
## so it will be possible to use these tests inside of an uml
|
||
|
for d in ["ubdb", "ubda", "udbc", "ubdd", "hdb", "hda", "hdc", "hdd"]:
|
||
|
if os.path.exists("/dev/%s1" % d):
|
||
|
device = d
|
||
|
break
|
||
|
else:
|
||
|
device = "hda"
|
||
|
|
||
|
|
||
|
|
||
|
class CryptoBoxToolsTests(unittest.TestCase):
|
||
|
"""All unittests for cryptoboxtools
|
||
|
"""
|
||
|
|
||
|
def test_get_absolute_devicename(self):
|
||
|
"""check the get_absolute_devicename function
|
||
|
"""
|
||
|
func = cbx_tools.get_absolute_devicename
|
||
|
self.assertTrue(func(device) == "/dev/%s" % device)
|
||
|
self.assertTrue(func("loop0") == "/dev/loop0")
|
||
|
self.assertTrue(func(os.path.devnull) == os.path.devnull)
|
||
|
|
||
|
|
||
|
def test_find_major_minor_of_device(self):
|
||
|
"""check the find_major_minor_of_device function
|
||
|
"""
|
||
|
func = cbx_tools.find_major_minor_of_device
|
||
|
self.assertTrue(func(os.path.devnull) == (1, 3))
|
||
|
self.assertTrue(func("/dev/nothere") is None)
|
||
|
|
||
|
|
||
|
def test_find_major_minor_device(self):
|
||
|
"""check the find_major_minor_device function
|
||
|
"""
|
||
|
func = cbx_tools.find_major_minor_device
|
||
|
path = os.path.join(os.path.sep, "dev")
|
||
|
self.assertTrue(os.path.devnull in func(path, 1, 3))
|
||
|
self.assertFalse(os.path.devnull in func(path, 2, 3))
|
||
|
self.assertFalse(None in func(path, 17, 23))
|
||
|
|
||
|
|
||
|
def test_is_part_of_blockdevice(self):
|
||
|
"""check the is_part_of_blockdevice function
|
||
|
"""
|
||
|
func = cbx_tools.is_part_of_blockdevice
|
||
|
self.assertTrue(func("/dev/%s" % device, "/dev/%s1" % device))
|
||
|
self.assertFalse(func("/dev/%s" % device, "/dev/%s" % device))
|
||
|
self.assertFalse(func("/dev/%s1" % device, "/dev/%s" % device))
|
||
|
self.assertFalse(func("/dev/%s1" % device, "/dev/%s1" % device))
|
||
|
self.assertFalse(func("/dev/%s" % device, "/dev/hde1"))
|
||
|
self.assertFalse(func(None, "/dev/%s1" % device))
|
||
|
self.assertFalse(func("/dev/%s" % device, None))
|
||
|
self.assertFalse(func(None, ""))
|
||
|
self.assertFalse(func("loop0", "loop1"))
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
unittest.main()
|
||
|
|