cryptonas-branches/pythonrewrite/bin/unittests.CryptoBoxTools.py
lars 0d41663ec3 fixed language selection bug
added unittest to CryptoBoxPlugin
2006-10-26 12:28:50 +00:00

48 lines
1.4 KiB
Python
Executable file

#!/usr/bin/env python2.4
import unittest
import CryptoBoxTools
import os
class CryptoBoxToolsTests(unittest.TestCase):
def testGetAbsoluteDeviceName(self):
func = CryptoBoxTools.getAbsoluteDeviceName
self.assertTrue(func("hda") == "/dev/hda")
self.assertTrue(func("loop0") == "/dev/loop0")
self.assertTrue(func(os.path.devnull) == os.path.devnull)
def testFindMajorMinorOfDevice(self):
func = CryptoBoxTools.findMajorMinorOfDevice
self.assertTrue(func("/dev/hda") == (3,0))
self.assertTrue(func("/dev/hda1") == (3,1))
self.assertTrue(func(os.path.devnull) == (1,3))
self.assertTrue(func("/dev/nothere") is None)
def testFindMajorMinorDeviceName(self):
func = CryptoBoxTools.findMajorMinorDeviceName
dir = os.path.join(os.path.sep, "dev")
self.assertTrue(os.path.join(dir,"hda") in func(dir,3,0))
self.assertTrue(os.path.devnull in func(dir,1,3))
self.assertFalse(os.path.devnull in func(dir,2,3))
def testIsPartOfBlockDevice(self):
func = CryptoBoxTools.isPartOfBlockDevice
self.assertTrue(func("/dev/hda", "/dev/hda1"))
self.assertFalse(func("/dev/hda", "/dev/hda"))
self.assertFalse(func("/dev/hda1", "/dev/hda"))
self.assertFalse(func("/dev/hda1", "/dev/hda1"))
self.assertFalse(func("/dev/hda", "/dev/hdb1"))
self.assertFalse(func(None, "/dev/hdb1"))
self.assertFalse(func("/dev/hda", None))
self.assertFalse(func(None, ""))
self.assertFalse(func("loop0", "loop1"))
if __name__ == "__main__":
unittest.main()