[blivet] Tidy up tests in devicelibs_test directory.
mulhern
amulhern at redhat.com
Thu Nov 14 13:11:45 UTC 2013
The main change is a refactoring that moves any test that does
not currently require the setup and teardown methods in
devicelibs_test.baseclass.DevicelibsTestCase into a separate class that
just extends unittest.TestCase instead of extending DevicelibsTestCase.
This way, these tests can be run w/out the root privileges that
are required by DevicelibsTestCase.
There are also some small import changes.
Some tests that previously checked for a generic ValueError now check for
MDRaidError.
__init__.py files have been added to encourage unittest discovery to
examine subdirectories.
Signed-off-by: mulhern <amulhern at redhat.com>
---
tests/__init__.py | 0
tests/devicelibs_test/__init__.py | 0
tests/devicelibs_test/crypto_test.py | 2 +-
tests/devicelibs_test/lvm_test.py | 59 +++++++++++++++++-------------------
tests/devicelibs_test/mdraid_test.py | 24 +++++++--------
tests/devicelibs_test/swap_test.py | 3 +-
6 files changed, 42 insertions(+), 46 deletions(-)
create mode 100644 tests/__init__.py
create mode 100644 tests/devicelibs_test/__init__.py
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/devicelibs_test/__init__.py b/tests/devicelibs_test/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/devicelibs_test/crypto_test.py b/tests/devicelibs_test/crypto_test.py
index 0e1422c..7ef49fe 100755
--- a/tests/devicelibs_test/crypto_test.py
+++ b/tests/devicelibs_test/crypto_test.py
@@ -7,7 +7,7 @@ import os
class CryptoTestCase(baseclass.DevicelibsTestCase):
- @skipUnless(os.geteuid() == 0, "requires root privileges")
+ @unittest.skipUnless(os.geteuid() == 0, "requires root privileges")
def testCrypto(self):
_LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
_LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
diff --git a/tests/devicelibs_test/lvm_test.py b/tests/devicelibs_test/lvm_test.py
index 8690ee2..5679118 100755
--- a/tests/devicelibs_test/lvm_test.py
+++ b/tests/devicelibs_test/lvm_test.py
@@ -1,16 +1,40 @@
#!/usr/bin/python
import baseclass
+import os
import unittest
-class LVMTestCase(baseclass.DevicelibsTestCase):
+import blivet.devicelibs.lvm as lvm
- @skipUnless(os.geteuid() == 0, "requires root privileges")
+class LVMTestCase(unittest.TestCase):
+
+ def testGetPossiblePhysicalExtents(self):
+ # pass
+ self.assertEqual(lvm.getPossiblePhysicalExtents(4),
+ filter(lambda pe: pe > 4, map(lambda power: 2**power, xrange(3, 25))))
+ self.assertEqual(lvm.getPossiblePhysicalExtents(100000),
+ filter(lambda pe: pe > 100000, map(lambda power: 2**power, xrange(3, 25))))
+
+ def testClampSize(self):
+ # pass
+ self.assertEqual(lvm.clampSize(10, 4), 8L)
+ self.assertEqual(lvm.clampSize(10, 4, True), 12L)
+
+ #def testVGUsedSpace(self):
+ # TODO
+ pass
+
+ #def testVGFreeSpace(self):
+ # TODO
+ pass
+
+
+class LVMAsRootTestCase(baseclass.DevicelibsTestCase):
+
+ @unittest.skipUnless(os.geteuid() == 0, "requires root privileges")
def testLVM(self):
_LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
_LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
- import storage.devicelibs.lvm as lvm
-
##
## pvcreate
##
@@ -199,33 +223,6 @@ class LVMTestCase(baseclass.DevicelibsTestCase):
# pv already removed
self.assertRaises(lvm.LVMError, lvm.pvremove, _LOOP_DEV0)
- def testGetPossiblePhysicalExtents(self):
- # pass
- self.assertEqual(lvm.getPossiblePhysicalExtents(4),
- filter(lambda pe: pe > 4, map(lambda power: 2**power, xrange(3, 25))))
- self.assertEqual(lvm.getPossiblePhysicalExtents(100000),
- filter(lambda pe: pe > 100000, map(lambda power: 2**power, xrange(3, 25))))
-
- def testGetMaxLVSize(self):
- # pass
- self.assertEqual(lvm.getMaxLVSize(), 16*1024**2)
-
- def testSafeLVMName(self):
- # pass
- self.assertEqual(lvm.safeLvmName("/strange/lv*name5"), "strange_lvname5")
-
- def testClampSize(self):
- # pass
- self.assertEqual(lvm.clampSize(10, 4), 8L)
- self.assertEqual(lvm.clampSize(10, 4, True), 12L)
-
- #def testVGUsedSpace(self):
- # TODO
- pass
-
- #def testVGFreeSpace(self):
- # TODO
- pass
def suite():
diff --git a/tests/devicelibs_test/mdraid_test.py b/tests/devicelibs_test/mdraid_test.py
index 2c2fc0d..bc47b76 100755
--- a/tests/devicelibs_test/mdraid_test.py
+++ b/tests/devicelibs_test/mdraid_test.py
@@ -1,18 +1,15 @@
#!/usr/bin/python
import baseclass
+import os
import unittest
import time
-class MDRaidTestCase(baseclass.DevicelibsTestCase):
+import blivet.devicelibs.mdraid as mdraid
+import blivet.errors as errors
- def testMDRaid(self):
- import blivet.devicelibs.mdraid as mdraid
+class MDRaidTestCase(unittest.TestCase):
- ##
- ## getRaidLevels
- ##
- # pass
- self.assertEqual(mdraid.getRaidLevels(), mdraid.getRaidLevels())
+ def testMDRaid(self):
##
## get_raid_min_members
@@ -26,7 +23,7 @@ class MDRaidTestCase(baseclass.DevicelibsTestCase):
# fail
# unsupported raid
- self.assertRaises(ValueError, mdraid.get_raid_min_members, 8)
+ self.assertRaises(errors.MDRaidError, mdraid.get_raid_min_members, 8)
##
## get_raid_max_spares
@@ -40,15 +37,16 @@ class MDRaidTestCase(baseclass.DevicelibsTestCase):
# fail
# unsupported raid
- self.assertRaises(ValueError, mdraid.get_raid_max_spares, 8, 5)
+ self.assertRaises(errors.MDRaidError, mdraid.get_raid_max_spares, 8, 5)
+
- @skipUnless(os.geteuid() == 0, "requires root privileges")
+class MDRaidAsRootTestCase(baseclass.DevicelibsTestCase):
+
+ @unittest.skipUnless(os.geteuid() == 0, "requires root privileges")
def testMDRaidAsRoot(self):
_LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
_LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
- import blivet.devicelibs.mdraid as mdraid
-
##
## mdcreate
##
diff --git a/tests/devicelibs_test/swap_test.py b/tests/devicelibs_test/swap_test.py
index 1f319d5..a71c1af 100755
--- a/tests/devicelibs_test/swap_test.py
+++ b/tests/devicelibs_test/swap_test.py
@@ -1,10 +1,11 @@
#!/usr/bin/python
import baseclass
+import os
import unittest
class SwapTestCase(baseclass.DevicelibsTestCase):
- @skipUnless(os.geteuid() == 0, "requires root privileges")
+ @unittest.skipUnless(os.geteuid() == 0, "requires root privileges")
def testSwap(self):
_LOOP_DEV0 = self._loopMap[self._LOOP_DEVICES[0]]
_LOOP_DEV1 = self._loopMap[self._LOOP_DEVICES[1]]
--
1.8.3.1
More information about the anaconda-patches
mailing list