[blivet 04/13] A few small tests for MDFactory class.

mulhern amulhern at redhat.com
Tue Nov 26 18:47:09 UTC 2013


These tests are added mostly to detect regressions during an anticipated
refactoring.

These tests are very much after the fact and capture the current
behavior, not necessarily the intended or correct behavior.

Therefore, it is fairly likely that if some change to the code causes
a failure, it may be that the test itself, and the code previously, have
been shown to be wrong.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 tests/devicefactory_test.py | 59 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 tests/devicefactory_test.py

diff --git a/tests/devicefactory_test.py b/tests/devicefactory_test.py
new file mode 100644
index 0000000..67f8c1a
--- /dev/null
+++ b/tests/devicefactory_test.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+import unittest
+
+import blivet
+
+from blivet import devicefactory
+from blivet import devices
+from blivet.devicelibs import mdraid
+
+class MDFactoryTestCase(unittest.TestCase):
+    """Note that these tests postdate the code that they test.
+       Therefore, they capture the behavior of the code as it is now,
+       not necessarily its intended or its correct behavior. See the
+       initial commit message for this file for further details.
+    """
+    def setUp(self):
+        self.b = blivet.Blivet()
+        self.factory1 = devicefactory.get_device_factory(self.b,
+           devicefactory.DEVICE_TYPE_MD,
+           1024)
+
+        self.factory2 = devicefactory.get_device_factory(self.b,
+           devicefactory.DEVICE_TYPE_MD,
+           1024,
+           raid_level=0)
+
+    def testMDFactory(self):
+        self.assertRaisesRegexp(mdraid.MDRaidError,
+           "invalid raid level",
+           self.factory1._get_device_space)
+
+        self.assertRaisesRegexp(mdraid.MDRaidError,
+           "invalid raid level",
+           self.factory1._set_raid_level)
+
+        self.assertEqual(self.factory1.container_list, [])
+
+        self.assertIsNone(self.factory1.get_container())
+
+        self.assertRaisesRegexp(mdraid.MDRaidError,
+           "invalid raid level",
+           self.factory1._get_new_device,
+           parents=[])
+
+        self.assertRaisesRegexp(mdraid.MDRaidError,
+           "requires at least",
+           self.factory2._get_device_space)
+
+        self.assertEqual(self.factory2.container_list, [])
+
+        self.assertIsNone(self.factory2.get_container())
+
+def suite():
+    return unittest.TestLoader().loadTestsFromTestCase(MDFactoryTestCase)
+
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.8.3.1



More information about the anaconda-patches mailing list