Some small changes to test cases were needed. Added suite() function to them and changed the class names. Also __init__.py files were added to the directories. --- run_test.py | 24 +++++++++++ tests/__init__.py | 19 +++++++++ tests/storage/devicelibs/baseclass.py | 72 ++++++++++++++++----------------- tests/storage/devicelibs/crypto.py | 11 +++-- tests/storage/devicelibs/lvm.py | 18 +++++---- tests/storage/devicelibs/mdraid.py | 12 +++-- tests/storage/devicelibs/swap.py | 11 +++-- 7 files changed, 109 insertions(+), 58 deletions(-) create mode 100644 run_test.py create mode 100644 tests/__init__.py create mode 100644 tests/storage/__init__.py create mode 100644 tests/storage/devicelibs/__init__.py diff --git a/run_test.py b/run_test.py new file mode 100644 index 0000000..ddc838c --- /dev/null +++ b/run_test.py @@ -0,0 +1,24 @@ +import sys + +REQUIRED_PATHS = ["/usr/lib/anaconda", + "/usr/share/system-config-date"] +sys.path.extend(REQUIRED_PATHS) + +import unittest +import tests + +if __name__ == "__main__": + test_names = tests.available_suites.keys() + test_names.sort() + + print "Available tests:" + num = 0 + for name in test_names: + print "[%2d] %s" % (num, name) + num += 1 + print + + input = raw_input("Type in the number of test you want to run: ") + num = int(input) + + unittest.TextTestRunner(verbosity=2).run(tests.available_suites[test_names[num]]) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..7cd24cf --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,19 @@ +import os + +# this has to be imported before running anything +import anaconda_log +import upgrade + +root, tests_dir = os.path.split(os.path.dirname(__file__)) +modules = [] +for root, dirs, files in os.walk(tests_dir): + for filename in files: + if filename.endswith(".py") and filename != "__init__.py": + basename, extension = os.path.splitext(filename) + modules.append(os.path.join(root, basename).replace("/", ".")) + +available_suites = {} +for module in modules: + imported = __import__(module, globals(), locals(), [module], -1) + if hasattr(imported, "suite"): + available_suites[module] = imported.suite() diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/storage/devicelibs/__init__.py b/tests/storage/devicelibs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/storage/devicelibs/baseclass.py b/tests/storage/devicelibs/baseclass.py index 01fe6c7..97d6003 100644 --- a/tests/storage/devicelibs/baseclass.py +++ b/tests/storage/devicelibs/baseclass.py @@ -2,11 +2,40 @@ import unittest import os import subprocess -# need to import these first before doing anything -import anaconda_log -import upgrade -class TestDevicelibs(unittest.TestCase): +def makeLoopDev(device_name, file_name): + proc = subprocess.Popen(["dd", "if=/dev/zero", "of=%s" % file_name, "bs=1024", "count=102400"]) + while True: + proc.communicate() + if proc.returncode is not None: + rc = proc.returncode + break + if rc: + raise OSError, "dd failed creating the file %s" % file_name + + proc = subprocess.Popen(["losetup", device_name, file_name]) + while True: + proc.communicate() + if proc.returncode is not None: + rc = proc.returncode + break + if rc: + raise OSError, "losetup failed setting up the loop device %s" % device_name + +def removeLoopDev(device_name, file_name): + proc = subprocess.Popen(["losetup", "-d", device_name]) + while True: + proc.communicate() + if proc.returncode is not None: + rc = proc.returncode + break + if rc: + raise OSError, "losetup failed removing the loop device %s" % device_name + + os.unlink(file_name) + + +class DevicelibsTestCase(unittest.TestCase): _LOOP_DEVICES = (("/dev/loop0", "/tmp/test-virtdev0"), ("/dev/loop1", "/tmp/test-virtdev1")) @@ -15,39 +44,8 @@ class TestDevicelibs(unittest.TestCase): def setUp(self): for dev, file in self._LOOP_DEVICES: - self.makeLoopDev(dev, file) + makeLoopDev(dev, file) def tearDown(self): for dev, file in self._LOOP_DEVICES: - self.removeLoopDev(dev, file) - - def makeLoopDev(self, device_name, file_name): - proc = subprocess.Popen(["dd", "if=/dev/zero", "of=%s" % file_name, "bs=1024", "count=102400"]) - while True: - proc.communicate() - if proc.returncode is not None: - rc = proc.returncode - break - if rc: - raise OSError, "dd failed creating the file %s" % file_name - - proc = subprocess.Popen(["losetup", device_name, file_name]) - while True: - proc.communicate() - if proc.returncode is not None: - rc = proc.returncode - break - if rc: - raise OSError, "losetup failed setting up the loop device %s" % device_name - - def removeLoopDev(self, device_name, file_name): - proc = subprocess.Popen(["losetup", "-d", device_name]) - while True: - proc.communicate() - if proc.returncode is not None: - rc = proc.returncode - break - if rc: - raise OSError, "losetup failed removing the loop device %s" % device_name - - os.remove(file_name) + removeLoopDev(dev, file) diff --git a/tests/storage/devicelibs/crypto.py b/tests/storage/devicelibs/crypto.py index 6a76569..0f9f7bd 100644 --- a/tests/storage/devicelibs/crypto.py +++ b/tests/storage/devicelibs/crypto.py @@ -5,9 +5,9 @@ import storage.devicelibs.crypto as crypto import tempfile import os -class TestCrypto(baseclass.TestDevicelibs): +class CryptoTestCase(baseclass.DevicelibsTestCase): - def runTest(self): + def testCrypto(self): ## ## is_luks ## @@ -118,6 +118,9 @@ class TestCrypto(baseclass.TestDevicelibs): os.unlink(new_keyfile) +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(CryptoTestCase) + + if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(TestCrypto) - unittest.TextTestRunner(verbosity=2).run(suite) + unittest.main() diff --git a/tests/storage/devicelibs/lvm.py b/tests/storage/devicelibs/lvm.py index 62c52d1..e6ba1a6 100644 --- a/tests/storage/devicelibs/lvm.py +++ b/tests/storage/devicelibs/lvm.py @@ -2,9 +2,9 @@ import baseclass import unittest import storage.devicelibs.lvm as lvm -class TestLVM(baseclass.TestDevicelibs): +class LVMTestCase(baseclass.DevicelibsTestCase): - def testLVMStuff(self): + def testLVM(self): ## ## pvcreate ## @@ -154,7 +154,7 @@ class TestLVM(baseclass.TestDevicelibs): self.assertEqual(lvm.has_lvm(), True) # fail - #TODO + # TODO ## ## lvremove @@ -214,15 +214,17 @@ class TestLVM(baseclass.TestDevicelibs): self.assertEqual(lvm.clampSize(10, 4, True), 12L) #def testVGUsedSpace(self): - #TODO + # TODO pass #def testVGFreeSpace(self): - #TODO + # TODO pass -if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(TestLVM) - unittest.TextTestRunner(verbosity=2).run(suite) +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(LVMTestCase) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/storage/devicelibs/mdraid.py b/tests/storage/devicelibs/mdraid.py index 6e49e55..3c0ee72 100644 --- a/tests/storage/devicelibs/mdraid.py +++ b/tests/storage/devicelibs/mdraid.py @@ -4,9 +4,9 @@ import storage.devicelibs.mdraid as mdraid import time -class TestMDRaid(baseclass.TestDevicelibs): +class MDRaidTestCase(baseclass.DevicelibsTestCase): - def testMDRaidStuff(self): + def testMDRaid(self): ## ## getRaidLevels ## @@ -99,7 +99,9 @@ class TestMDRaid(baseclass.TestDevicelibs): self.assertRaises(mdraid.MDRaidError, mdraid.mddestroy, "/not/existing/device") -if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(TestMDRaid) - unittest.TextTestRunner(verbosity=2).run(suite) +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(MDRaidTestCase) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/storage/devicelibs/swap.py b/tests/storage/devicelibs/swap.py index b1e9bd3..b99d1f6 100644 --- a/tests/storage/devicelibs/swap.py +++ b/tests/storage/devicelibs/swap.py @@ -2,9 +2,9 @@ import baseclass import unittest import storage.devicelibs.swap as swap -class TestSwap(baseclass.TestDevicelibs): +class SwapTestCase(baseclass.DevicelibsTestCase): - def runTest(self): + def testSwap(self): ## ## mkswap ## @@ -58,6 +58,9 @@ class TestSwap(baseclass.TestDevicelibs): self.assertRaises(swap.SwapError, swap.swapoff, self._LOOP_DEV0) +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(SwapTestCase) + + if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(TestSwap) - unittest.TextTestRunner(verbosity=2).run(suite) + unittest.main() -- 1.6.0.6 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list