[master 3/3] fix deprecation warnings in a backward compatible way

atodorov installerbot-noreply at redhat.com
Mon May 25 09:53:31 UTC 2015


From: Alexander Todorov <atodorov at redhat.com>

---
 tests/__init__.py                            |  11 +++
 tests/action_test.py                         |  22 +++---
 tests/devicefactory_test.py                  |  11 +--
 tests/devicelibs_test/raid_test.py           |  11 +--
 tests/devices_test/device_properties_test.py |  42 +++++-----
 tests/devices_test/lvm_test.py               |  22 +++---
 tests/devices_test/partition_test.py         |  12 +--
 tests/partitioning_test.py                   |  12 +--
 tests/size_test.py                           | 110 +++++++++++++--------------
 tests/tsort_test.py                          |   9 +--
 10 files changed, 141 insertions(+), 121 deletions(-)

diff --git a/tests/__init__.py b/tests/__init__.py
index e69de29..3ddb100 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -0,0 +1,11 @@
+import sys
+import unittest
+
+class BlivetTestCase(unittest.TestCase):
+    def  __init__(self, methodName='runTest'):
+        # deprecation compatibility b/w python 2 and 3
+        if sys.version_info[0] == 2:
+            self.assertRaisesRegex = self.assertRaisesRegexp
+            self.assertRegex = self.assertRegexpMatches
+
+        super(BlivetTestCase, self).__init__(methodName)
diff --git a/tests/action_test.py b/tests/action_test.py
index c1559f7..ec52836 100644
--- a/tests/action_test.py
+++ b/tests/action_test.py
@@ -201,7 +201,7 @@ def testActionCreation(self):
         sdd = self.storage.devicetree.getDeviceByName("sdd")
         p = self.newDevice(device_class=PartitionDevice,
                            name="sdd1", size=Size("32 GiB"), parents=[sdd])
-        self.failUnlessRaises(ValueError,
+        self.assertRaises(ValueError,
                               ActionResizeDevice,
                               p,
                               p.size + Size("7232 MiB"))
@@ -210,7 +210,7 @@ def testActionCreation(self):
         # should fail
         vg = self.storage.devicetree.getDeviceByName("VolGroup")
         self.assertNotEqual(vg, None)
-        self.failUnlessRaises(ValueError,
+        self.assertRaises(ValueError,
                               ActionResizeDevice,
                               vg,
                               vg.size + Size("32 MiB"))
@@ -219,7 +219,7 @@ def testActionCreation(self):
         # should fail
         lv_swap = self.storage.devicetree.getDeviceByName("VolGroup-lv_swap")
         self.assertNotEqual(lv_swap, None)
-        self.failUnlessRaises(ValueError,
+        self.assertRaises(ValueError,
                               ActionResizeFormat,
                               lv_swap,
                               lv_swap.size + Size("32 MiB"))
@@ -229,7 +229,7 @@ def testActionCreation(self):
         lv_root = self.storage.devicetree.getDeviceByName("VolGroup-lv_root")
         self.assertNotEqual(lv_root, None)
         lv_root.format.exists = False
-        self.failUnlessRaises(ValueError,
+        self.assertRaises(ValueError,
                               ActionResizeFormat,
                               lv_root,
                               lv_root.size - Size("1000 MiB"))
@@ -240,7 +240,7 @@ def testActionCreation(self):
         lv_swap = self.storage.devicetree.getDeviceByName("VolGroup-lv_swap")
         self.assertNotEqual(lv_swap, None)
         self.assertEqual(lv_swap.exists, True)
-        self.failUnlessRaises(ValueError,
+        self.assertRaises(ValueError,
                               ActionCreateDevice,
                               lv_swap)
 
@@ -274,7 +274,7 @@ def testActionRegistration(self):
         self.assertNotEqual(vg, None)
         self.assertEqual(vg.isleaf, False)
         a = ActionDestroyDevice(vg)
-        self.failUnlessRaises(ValueError,
+        self.assertRaises(ValueError,
                               self.storage.devicetree.registerAction,
 			      a)
 
@@ -289,7 +289,7 @@ def testActionRegistration(self):
         sdc1_format = self.newFormat("ext2", device=sdc1.path, mountpoint="/")
         create_sdc1_format = ActionCreateFormat(sdc1, sdc1_format)
         create_sdc1_format.apply()
-        self.failUnlessRaises(blivet.errors.DeviceTreeError,
+        self.assertRaises(blivet.errors.DeviceTreeError,
                               self.storage.devicetree.registerAction,
                               create_sdc1_format)
 
@@ -298,13 +298,13 @@ def testActionRegistration(self):
         resize_sdc1_format = ActionResizeFormat(sdc1,
                                                 sdc1.size - Size("10 GiB"))
         resize_sdc1_format.apply()
-        self.failUnlessRaises(blivet.errors.DeviceTreeError,
+        self.assertRaises(blivet.errors.DeviceTreeError,
                               self.storage.devicetree.registerAction,
                               resize_sdc1_format)
 
         resize_sdc1 = ActionResizeDevice(sdc1, sdc1.size - Size("10 GiB"))
         resize_sdc1.apply()
-        self.failUnlessRaises(blivet.errors.DeviceTreeError,
+        self.assertRaises(blivet.errors.DeviceTreeError,
                               self.storage.devicetree.registerAction,
                               resize_sdc1)
 
@@ -312,13 +312,13 @@ def testActionRegistration(self):
         resize_sdc1_format.cancel()
 
         destroy_sdc1_format = ActionDestroyFormat(sdc1)
-        self.failUnlessRaises(blivet.errors.DeviceTreeError,
+        self.assertRaises(blivet.errors.DeviceTreeError,
                               self.storage.devicetree.registerAction,
                               destroy_sdc1_format)
 
 
         destroy_sdc1 = ActionDestroyDevice(sdc1)
-        self.failUnlessRaises(blivet.errors.DeviceTreeError,
+        self.assertRaises(blivet.errors.DeviceTreeError,
                               self.storage.devicetree.registerAction,
                               destroy_sdc1)
 
diff --git a/tests/devicefactory_test.py b/tests/devicefactory_test.py
index 824734e..705a1e3 100644
--- a/tests/devicefactory_test.py
+++ b/tests/devicefactory_test.py
@@ -10,8 +10,9 @@
 from blivet.errors import RaidError
 from blivet.formats import getFormat
 from blivet.size import Size
+from tests import BlivetTestCase
 
-class MDFactoryTestCase(unittest.TestCase):
+class MDFactoryTestCase(BlivetTestCase):
     """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
@@ -30,16 +31,16 @@ def setUp(self):
            raid_level=0)
 
     def testMDFactory(self):
-        with self.assertRaisesRegexp(devicefactory.DeviceFactoryError, "must have some RAID level"):
+        with self.assertRaisesRegex(devicefactory.DeviceFactoryError, "must have some RAID level"):
             devicefactory.get_device_factory(
                self.b,
                devicefactory.DEVICE_TYPE_MD,
                Size("1 GiB"))
 
-        with self.assertRaisesRegexp(RaidError, "requires at least"):
+        with self.assertRaisesRegex(RaidError, "requires at least"):
             self.factory1._get_device_space()
 
-        with self.assertRaisesRegexp(RaidError, "requires at least"):
+        with self.assertRaisesRegex(RaidError, "requires at least"):
             self.factory1._configure()
 
         self.assertEqual(self.factory1.container_list, [])
@@ -52,7 +53,7 @@ def testMDFactory(self):
         ]
         self.assertIsNotNone(self.factory1._get_new_device(parents=parents))
 
-        with self.assertRaisesRegexp(RaidError, "requires at least"):
+        with self.assertRaisesRegex(RaidError, "requires at least"):
             self.factory2._get_device_space()
 
         self.assertEqual(self.factory2.container_list, [])
diff --git a/tests/devicelibs_test/raid_test.py b/tests/devicelibs_test/raid_test.py
index d0cb29e..504e634 100644
--- a/tests/devicelibs_test/raid_test.py
+++ b/tests/devicelibs_test/raid_test.py
@@ -4,8 +4,9 @@
 import blivet.devicelibs.raid as raid
 import blivet.errors as errors
 from blivet.size import Size
+from tests import BlivetTestCase
 
-class RaidTestCase(unittest.TestCase):
+class RaidTestCase(BlivetTestCase):
 
     def setUp(self):
         self.levels = raid.RAIDLevels(["raid0", "raid1", "raid4", "raid5", "raid6", "raid10"])
@@ -14,7 +15,7 @@ def setUp(self):
 
     def testRaid(self):
 
-        with self.assertRaisesRegexp(TypeError, "Can't instantiate abstract class"):
+        with self.assertRaisesRegex(TypeError, "Can't instantiate abstract class"):
             raid.ErsatzRAID()
 
         ##
@@ -146,13 +147,13 @@ def testRaid(self):
         ##
         ## __init__
         ##
-        with self.assertRaisesRegexp(errors.RaidError, "invalid RAID level"):
+        with self.assertRaisesRegex(errors.RaidError, "invalid RAID level"):
             self.levels_none.raidLevel(10)
 
-        with self.assertRaisesRegexp(errors.RaidError, "invalid RAID level"):
+        with self.assertRaisesRegex(errors.RaidError, "invalid RAID level"):
             self.levels_some.raidLevel(10)
 
-        with self.assertRaisesRegexp(errors.RaidError, "invalid standard RAID level descriptor"):
+        with self.assertRaisesRegex(errors.RaidError, "invalid standard RAID level descriptor"):
             raid.RAIDLevels(["raid3.1415"])
 
 if __name__ == "__main__":
diff --git a/tests/devices_test/device_properties_test.py b/tests/devices_test/device_properties_test.py
index 5dbcb12..a7fc3bc 100644
--- a/tests/devices_test/device_properties_test.py
+++ b/tests/devices_test/device_properties_test.py
@@ -26,6 +26,8 @@
 
 from blivet.formats import getFormat
 
+from tests import BlivetTestCase
+
 def xform(func):
     """ Simple wrapper function that transforms a function that takes
         a precalculated value and a message to a function that takes
@@ -40,7 +42,7 @@ def xform(func):
     """
     return lambda d, a: func(getattr(d, a), a)
 
-class DeviceStateTestCase(unittest.TestCase):
+class DeviceStateTestCase(BlivetTestCase):
     """A class which implements a simple method of checking the state
        of a device object.
     """
@@ -61,7 +63,7 @@ def __init__(self, methodName='runTest'):
            "parents" : xform(lambda x, m: self.assertEqual(len(x), 0, m) and
                                     self.assertIsInstance(x, ParentList, m)),
            "partitionable" : xform(self.assertFalse),
-           "path" : xform(lambda x, m: self.assertRegexpMatches(x, "^/dev", m)),
+           "path" : xform(lambda x, m: self.assertRegex(x, "^/dev", m)),
            "raw_device" : xform(self.assertIsNotNone),
            "resizable" : xform(self.assertFalse),
            "size" : xform(lambda x, m: self.assertEqual(x, Size(0), m)),
@@ -517,35 +519,35 @@ def testMDRaidArrayDeviceInit(self):
                         parents=xform(lambda x, m: self.assertEqual(len(x), 2, m)),
                         uuid=xform(lambda x, m: self.assertEqual(x, self.dev20.uuid, m)))
 
-        with self.assertRaisesRegexp(DeviceError, "invalid"):
+        with self.assertRaisesRegex(DeviceError, "invalid"):
             MDRaidArrayDevice("dev")
 
-        with self.assertRaisesRegexp(DeviceError, "invalid"):
+        with self.assertRaisesRegex(DeviceError, "invalid"):
             MDRaidArrayDevice("dev", level="raid2")
 
-        with self.assertRaisesRegexp(DeviceError, "invalid"):
+        with self.assertRaisesRegex(DeviceError, "invalid"):
             MDRaidArrayDevice(
                "dev",
                parents=[StorageDevice("parent", fmt=getFormat("mdmember"))])
 
-        with self.assertRaisesRegexp(DeviceError, "at least 2 members"):
+        with self.assertRaisesRegex(DeviceError, "at least 2 members"):
             MDRaidArrayDevice(
                "dev",
                level="raid0",
                parents=[StorageDevice("parent", fmt=getFormat("mdmember"))])
 
-        with self.assertRaisesRegexp(DeviceError, "invalid"):
+        with self.assertRaisesRegex(DeviceError, "invalid"):
             MDRaidArrayDevice("dev", level="junk")
 
-        with self.assertRaisesRegexp(DeviceError, "at least 2 members"):
+        with self.assertRaisesRegex(DeviceError, "at least 2 members"):
             MDRaidArrayDevice("dev", level=0, memberDevices=2)
 
     def testMDRaidArrayDeviceMethods(self):
         """Test for method calls on initialized MDRaidDevices."""
-        with self.assertRaisesRegexp(DeviceError, "invalid" ):
+        with self.assertRaisesRegex(DeviceError, "invalid" ):
             self.dev7.level = "junk"
 
-        with self.assertRaisesRegexp(DeviceError, "invalid" ):
+        with self.assertRaisesRegex(DeviceError, "invalid" ):
             self.dev7.level = None
 
 class BTRFSDeviceTestCase(DeviceStateTestCase):
@@ -615,26 +617,26 @@ def testBTRFSDeviceInit(self):
            size=xform(lambda x, m: self.assertEqual(x, Size("32 MiB"), m)),
            type=xform(lambda x, m: self.assertEqual(x, "btrfs volume", m)))
 
-        with self.assertRaisesRegexp(ValueError, "BTRFSDevice.*must have at least one parent"):
+        with self.assertRaisesRegex(ValueError, "BTRFSDevice.*must have at least one parent"):
             BTRFSVolumeDevice("dev")
 
-        with self.assertRaisesRegexp(ValueError, "format"):
+        with self.assertRaisesRegex(ValueError, "format"):
             BTRFSVolumeDevice("dev", parents=[StorageDevice("deva", size=btrfs.MIN_MEMBER_SIZE)])
 
-        with self.assertRaisesRegexp(DeviceError, "btrfs subvolume.*must be a btrfs volume"):
+        with self.assertRaisesRegex(DeviceError, "btrfs subvolume.*must be a btrfs volume"):
             fmt = blivet.formats.getFormat("btrfs")
             device = StorageDevice("deva", fmt=fmt, size=btrfs.MIN_MEMBER_SIZE)
             BTRFSSubVolumeDevice("dev1", parents=[device])
 
         deva = OpticalDevice("deva", fmt=blivet.formats.getFormat("btrfs"))
-        with self.assertRaisesRegexp(BTRFSValueError, "at least"):
+        with self.assertRaisesRegex(BTRFSValueError, "at least"):
             BTRFSVolumeDevice("dev1", dataLevel="raid1", parents=[deva])
 
         deva = StorageDevice("deva", fmt=blivet.formats.getFormat("btrfs"), size=btrfs.MIN_MEMBER_SIZE)
         self.assertIsNotNone(BTRFSVolumeDevice("dev1", metaDataLevel="dup", parents=[deva]))
 
         deva = StorageDevice("deva", fmt=blivet.formats.getFormat("btrfs"), size=btrfs.MIN_MEMBER_SIZE)
-        with self.assertRaisesRegexp(BTRFSValueError, "invalid"):
+        with self.assertRaisesRegex(BTRFSValueError, "invalid"):
             BTRFSVolumeDevice("dev1", dataLevel="dup", parents=[deva])
 
         self.assertEqual(self.dev1.isleaf, False)
@@ -659,24 +661,24 @@ def testBTRFSDeviceMethods(self):
         self.assertIsNotNone(self.dev2.volume)
 
         # size
-        with self.assertRaisesRegexp(RuntimeError, "cannot directly set size of btrfs volume"):
+        with self.assertRaisesRegex(RuntimeError, "cannot directly set size of btrfs volume"):
             self.dev1.size = 32
 
     def testBTRFSSnapShotDeviceInit(self):
         parents = [StorageDevice("p1", fmt=blivet.formats.getFormat("btrfs"), size=btrfs.MIN_MEMBER_SIZE)]
         vol = BTRFSVolumeDevice("test", parents=parents)
-        with self.assertRaisesRegexp(ValueError, "non-existent btrfs snapshots must have a source"):
+        with self.assertRaisesRegex(ValueError, "non-existent btrfs snapshots must have a source"):
             BTRFSSnapShotDevice("snap1", parents=[vol])
 
-        with self.assertRaisesRegexp(ValueError, "btrfs snapshot source must already exist"):
+        with self.assertRaisesRegex(ValueError, "btrfs snapshot source must already exist"):
             BTRFSSnapShotDevice("snap1", parents=[vol], source=vol)
 
-        with self.assertRaisesRegexp(ValueError, "btrfs snapshot source must be a btrfs subvolume"):
+        with self.assertRaisesRegex(ValueError, "btrfs snapshot source must be a btrfs subvolume"):
             BTRFSSnapShotDevice("snap1", parents=[vol], source=parents[0])
 
         parents2 = [StorageDevice("p1", fmt=blivet.formats.getFormat("btrfs"), size=btrfs.MIN_MEMBER_SIZE)]
         vol2 = BTRFSVolumeDevice("test2", parents=parents2, exists=True)
-        with self.assertRaisesRegexp(ValueError, ".*snapshot and source must be in the same volume"):
+        with self.assertRaisesRegex(ValueError, ".*snapshot and source must be in the same volume"):
             BTRFSSnapShotDevice("snap1", parents=[vol], source=vol2)
 
         vol.exists = True
diff --git a/tests/devices_test/lvm_test.py b/tests/devices_test/lvm_test.py
index f2dac38..08e9ce8 100644
--- a/tests/devices_test/lvm_test.py
+++ b/tests/devices_test/lvm_test.py
@@ -14,6 +14,8 @@
 from blivet.devices import LVMVolumeGroupDevice
 from blivet.size import Size
 
+from tests import BlivetTestCase
+
 DEVICE_CLASSES = [
    LVMLogicalVolumeDevice,
    LVMSnapShotDevice,
@@ -25,7 +27,7 @@
 ]
 
 @unittest.skipUnless(not any(x.unavailableTypeDependencies() for x in DEVICE_CLASSES), "some unsupported device classes required for this test")
-class LVMDeviceTest(unittest.TestCase):
+class LVMDeviceTest(BlivetTestCase):
     def testLVMSnapShotDeviceInit(self):
         pv = StorageDevice("pv1", fmt=blivet.formats.getFormat("lvmpv"),
                            size=Size("1 GiB"))
@@ -33,16 +35,16 @@ def testLVMSnapShotDeviceInit(self):
         lv = LVMLogicalVolumeDevice("testlv", parents=[vg],
                                     fmt=blivet.formats.getFormat("xfs"))
 
-        with self.assertRaisesRegexp(ValueError, "lvm snapshot devices require an origin lv"):
+        with self.assertRaisesRegex(ValueError, "lvm snapshot devices require an origin lv"):
             LVMSnapShotDevice("snap1", parents=[vg])
 
-        with self.assertRaisesRegexp(ValueError, "lvm snapshot origin volume must already exist"):
+        with self.assertRaisesRegex(ValueError, "lvm snapshot origin volume must already exist"):
             LVMSnapShotDevice("snap1", parents=[vg], origin=lv)
 
-        with self.assertRaisesRegexp(ValueError, "lvm snapshot origin must be a logical volume"):
+        with self.assertRaisesRegex(ValueError, "lvm snapshot origin must be a logical volume"):
             LVMSnapShotDevice("snap1", parents=[vg], origin=pv)
 
-        with self.assertRaisesRegexp(ValueError, "only existing vorigin snapshots are supported"):
+        with self.assertRaisesRegex(ValueError, "only existing vorigin snapshots are supported"):
             LVMSnapShotDevice("snap1", parents=[vg], vorigin=True)
 
         lv.exists = True
@@ -68,13 +70,13 @@ def testLVMThinSnapShotDeviceInit(self):
         thinlv = LVMThinLogicalVolumeDevice("thinlv", parents=[pool],
                                             size=Size("200 MiB"))
 
-        with self.assertRaisesRegexp(ValueError, "lvm thin snapshots require an origin"):
+        with self.assertRaisesRegex(ValueError, "lvm thin snapshots require an origin"):
             LVMThinSnapShotDevice("snap1", parents=[pool])
 
-        with self.assertRaisesRegexp(ValueError, "lvm snapshot origin volume must already exist"):
+        with self.assertRaisesRegex(ValueError, "lvm snapshot origin volume must already exist"):
             LVMThinSnapShotDevice("snap1", parents=[pool], origin=thinlv)
 
-        with self.assertRaisesRegexp(ValueError, "lvm snapshot origin must be a logical volume"):
+        with self.assertRaisesRegex(ValueError, "lvm snapshot origin must be a logical volume"):
             LVMThinSnapShotDevice("snap1", parents=[pool], origin=pv)
 
         # now make the constructor succeed so we can test some properties
@@ -112,7 +114,7 @@ def testTargetSize(self):
         self.assertEqual(lv.size, orig_size)
 
         # ValueError if size smaller than minSize
-        with self.assertRaisesRegexp(ValueError,
+        with self.assertRaisesRegex(ValueError,
                                      "size.*smaller than the minimum"):
             lv.targetSize = Size("1 MiB")
 
@@ -120,7 +122,7 @@ def testTargetSize(self):
         self.assertEqual(lv.targetSize, orig_size)
 
         # ValueError if size larger than maxSize
-        with self.assertRaisesRegexp(ValueError,
+        with self.assertRaisesRegex(ValueError,
                                      "size.*larger than the maximum"):
             lv.targetSize = Size("1 GiB")
 
diff --git a/tests/devices_test/partition_test.py b/tests/devices_test/partition_test.py
index b882c46..b9d4c24 100644
--- a/tests/devices_test/partition_test.py
+++ b/tests/devices_test/partition_test.py
@@ -10,7 +10,9 @@
 from blivet.size import Size
 from blivet.util import sparsetmpfile
 
-class PartitionDeviceTestCase(unittest.TestCase):
+from tests import BlivetTestCase
+
+class PartitionDeviceTestCase(BlivetTestCase):
 
     def testTargetSize(self):
         with sparsetmpfile("targetsizetest", Size("10 MiB")) as disk_file:
@@ -45,28 +47,28 @@ def testTargetSize(self):
             self.assertEqual(device.maxSize, Size("9 MiB"))
 
             # ValueError if not Size
-            with self.assertRaisesRegexp(ValueError,
+            with self.assertRaisesRegex(ValueError,
                                          "new size must.*type Size"):
                 device.targetSize = 22
 
             self.assertEqual(device.targetSize, orig_size)
 
             # ValueError if size smaller than minSize
-            with self.assertRaisesRegexp(ValueError,
+            with self.assertRaisesRegex(ValueError,
                                          "size.*smaller than the minimum"):
                 device.targetSize = Size("1 MiB")
 
             self.assertEqual(device.targetSize, orig_size)
 
             # ValueError if size larger than maxSize
-            with self.assertRaisesRegexp(ValueError,
+            with self.assertRaisesRegex(ValueError,
                                          "size.*larger than the maximum"):
                 device.targetSize = Size("11 MiB")
 
             self.assertEqual(device.targetSize, orig_size)
 
             # ValueError if unaligned
-            with self.assertRaisesRegexp(ValueError, "new size.*not.*aligned"):
+            with self.assertRaisesRegex(ValueError, "new size.*not.*aligned"):
                 device.targetSize = Size("3.1 MiB")
 
             self.assertEqual(device.targetSize, orig_size)
diff --git a/tests/partitioning_test.py b/tests/partitioning_test.py
index 2d17024..1b41b07 100644
--- a/tests/partitioning_test.py
+++ b/tests/partitioning_test.py
@@ -29,6 +29,8 @@
 from blivet.size import Size
 from blivet.flags import flags
 
+from tests import BlivetTestCase
+
 # disklabel-type-specific constants
 # keys: disklabel type string
 # values: 3-tuple of (max_primary_count, supports_extended, max_logical_count)
@@ -36,7 +38,7 @@
                    'gpt': (128, False, 0),
                    'mac': (62, False, 0)}
 
-class PartitioningTestCase(unittest.TestCase):
+class PartitioningTestCase(BlivetTestCase):
     def getDisk(self, disk_type, primary_count=0,
                 has_extended=False, logical_count=0):
         """ Return a mock representing a parted.Disk. """
@@ -185,7 +187,7 @@ def testAddPartition(self):
             #
             # fail: add a logical partition to a primary free region
             #
-            with self.assertRaisesRegexp(parted.PartitionException,
+            with self.assertRaisesRegex(parted.PartitionException,
                                          "no extended partition"):
                 part = addPartition(disk.format, free, parted.PARTITION_LOGICAL,
                                     Size("10 MiB"))
@@ -217,7 +219,7 @@ def testAddPartition(self):
             #
             # fail: add a primary partition to an extended free region
             #
-            with self.assertRaisesRegexp(parted.PartitionException, "overlap"):
+            with self.assertRaisesRegex(parted.PartitionException, "overlap"):
                 part = addPartition(disk.format, all_free[1],
                                     parted.PARTITION_NORMAL,
                                     Size("10 MiB"), all_free[1].start)
@@ -297,7 +299,7 @@ def testDiskChunk1(self):
             disks = [disk]
             partitions = [p1, p2]
             free = getFreeRegions([disk])
-            self.assertEquals(len(free), 1,
+            self.assertEqual(len(free), 1,
                               "free region count %d not expected" % len(free))
 
             b = Mock()
@@ -360,7 +362,7 @@ def testDiskChunk2(self):
             disks = [disk]
             partitions = [p1, p2, p3, p4, p5]
             free = getFreeRegions([disk])
-            self.assertEquals(len(free), 1,
+            self.assertEqual(len(free), 1,
                               "free region count %d not expected" % len(free))
 
             b = Mock()
diff --git a/tests/size_test.py b/tests/size_test.py
index 3a7c01c..032ec35 100644
--- a/tests/size_test.py
+++ b/tests/size_test.py
@@ -60,17 +60,17 @@ def _prefixTestHelper(self, numunits, unit):
         c = numunits * unit.factor
 
         s = Size(c)
-        self.assertEquals(s, Size(c))
+        self.assertEqual(s, Size(c))
 
         u = size._makeSpec(unit.prefix, size._BYTES_WORDS[0], False)
         s = Size("%ld %s" % (numunits, u))
-        self.assertEquals(s, c)
-        self.assertEquals(s.convertTo(unit), numunits)
+        self.assertEqual(s, c)
+        self.assertEqual(s.convertTo(unit), numunits)
 
         u = size._makeSpec(unit.abbr, size._BYTES_SYMBOL, False)
         s = Size("%ld %s" % (numunits, u))
-        self.assertEquals(s, c)
-        self.assertEquals(s.convertTo(unit), numunits)
+        self.assertEqual(s, c)
+        self.assertEqual(s.convertTo(unit), numunits)
 
     def testPrefixes(self):
         numbytes = 47
@@ -80,115 +80,115 @@ def testPrefixes(self):
 
     def testHumanReadable(self):
         s = Size(58929971)
-        self.assertEquals(s.humanReadable(), "56.2 MiB")
+        self.assertEqual(s.humanReadable(), "56.2 MiB")
 
         s = Size(478360371)
-        self.assertEquals(s.humanReadable(), "456.2 MiB")
+        self.assertEqual(s.humanReadable(), "456.2 MiB")
 
         # humanReable output should be the same as input for big enough sizes
         # and enough places and integer values
         s = Size("12.68 TiB")
-        self.assertEquals(s.humanReadable(max_places=2), "12.68 TiB")
+        self.assertEqual(s.humanReadable(max_places=2), "12.68 TiB")
         s = Size("26.55 MiB")
-        self.assertEquals(s.humanReadable(max_places=2), "26.55 MiB")
+        self.assertEqual(s.humanReadable(max_places=2), "26.55 MiB")
         s = Size("300 MiB")
-        self.assertEquals(s.humanReadable(max_places=2), "300 MiB")
+        self.assertEqual(s.humanReadable(max_places=2), "300 MiB")
 
         # when min_value is 10 and single digit on left of decimal, display
         # with smaller unit.
         s = Size("9.68 TiB")
-        self.assertEquals(s.humanReadable(max_places=2, min_value=10), "9912.32 GiB")
+        self.assertEqual(s.humanReadable(max_places=2, min_value=10), "9912.32 GiB")
         s = Size("4.29 MiB")
-        self.assertEquals(s.humanReadable(max_places=2, min_value=10), "4392.96 KiB")
+        self.assertEqual(s.humanReadable(max_places=2, min_value=10), "4392.96 KiB")
         s = Size("7.18 KiB")
-        self.assertEquals(s.humanReadable(max_places=2, min_value=10), "7352 B")
+        self.assertEqual(s.humanReadable(max_places=2, min_value=10), "7352 B")
 
         # rounding should work with max_places limitted
         s = Size("12.687 TiB")
-        self.assertEquals(s.humanReadable(max_places=2), "12.69 TiB")
+        self.assertEqual(s.humanReadable(max_places=2), "12.69 TiB")
         s = Size("23.7874 TiB")
-        self.assertEquals(s.humanReadable(max_places=3), "23.787 TiB")
+        self.assertEqual(s.humanReadable(max_places=3), "23.787 TiB")
         s = Size("12.6998 TiB")
-        self.assertEquals(s.humanReadable(max_places=2), "12.7 TiB")
+        self.assertEqual(s.humanReadable(max_places=2), "12.7 TiB")
 
         # byte values close to multiples of 2 are shown without trailing zeros
         s = Size(0xff)
-        self.assertEquals(s.humanReadable(max_places=2), "255 B")
+        self.assertEqual(s.humanReadable(max_places=2), "255 B")
         s = Size(8193)
-        self.assertEquals(s.humanReadable(max_places=2, min_value=10), "8193 B")
+        self.assertEqual(s.humanReadable(max_places=2, min_value=10), "8193 B")
 
         # a fractional quantity is shown if the value deviates
         # from the whole number of units by more than 1%
         s = Size(16384 - (1024/100 + 1))
-        self.assertEquals(s.humanReadable(max_places=2), "15.99 KiB")
+        self.assertEqual(s.humanReadable(max_places=2), "15.99 KiB")
 
         # if max_places is set to None, all digits are displayed
         s = Size(0xfffffffffffff)
-        self.assertEquals(s.humanReadable(max_places=None), "3.9999999999999991118215803 PiB")
+        self.assertEqual(s.humanReadable(max_places=None), "3.9999999999999991118215803 PiB")
         s = Size(0x10000)
-        self.assertEquals(s.humanReadable(max_places=None), "64 KiB")
+        self.assertEqual(s.humanReadable(max_places=None), "64 KiB")
         s = Size(0x10001)
-        self.assertEquals(s.humanReadable(max_places=None), "64.0009765625 KiB")
+        self.assertEqual(s.humanReadable(max_places=None), "64.0009765625 KiB")
 
         # test a very large quantity with no associated abbreviation or prefix
         s = Size(1024**9)
-        self.assertEquals(s.humanReadable(max_places=2), "1024 YiB")
+        self.assertEqual(s.humanReadable(max_places=2), "1024 YiB")
         s = Size(1024**9 - 1)
-        self.assertEquals(s.humanReadable(max_places=2), "1024 YiB")
+        self.assertEqual(s.humanReadable(max_places=2), "1024 YiB")
         s = Size(1024**9 + 1)
-        self.assertEquals(s.humanReadable(max_places=2, strip=False), "1024.00 YiB")
+        self.assertEqual(s.humanReadable(max_places=2, strip=False), "1024.00 YiB")
         s = Size(1024**10)
-        self.assertEquals(s.humanReadable(max_places=2), "1048576 YiB")
+        self.assertEqual(s.humanReadable(max_places=2), "1048576 YiB")
 
     def testHumanReadableFractionalQuantities(self):
         s = Size(0xfffffffffffff)
-        self.assertEquals(s.humanReadable(max_places=2), "4 PiB")
+        self.assertEqual(s.humanReadable(max_places=2), "4 PiB")
         s = Size(0xfffff)
-        self.assertEquals(s.humanReadable(max_places=2, strip=False), "1024.00 KiB")
+        self.assertEqual(s.humanReadable(max_places=2, strip=False), "1024.00 KiB")
         s = Size(0xffff)
         # value is not exactly 64 KiB, but w/ 2 places, value is 64.00 KiB
         # so the trailing 0s are stripped.
-        self.assertEquals(s.humanReadable(max_places=2), "64 KiB")
+        self.assertEqual(s.humanReadable(max_places=2), "64 KiB")
         # since all significant digits are shown, there are no trailing 0s.
-        self.assertEquals(s.humanReadable(max_places=None), "63.9990234375 KiB")
+        self.assertEqual(s.humanReadable(max_places=None), "63.9990234375 KiB")
 
         # deviation is less than 1/2 of 1% of 1024
         s = Size(16384 - (1024/100//2))
-        self.assertEquals(s.humanReadable(max_places=2), "16 KiB")
+        self.assertEqual(s.humanReadable(max_places=2), "16 KiB")
         # deviation is greater than 1/2 of 1% of 1024
         s = Size(16384 - ((1024/100//2) + 1))
-        self.assertEquals(s.humanReadable(max_places=2), "15.99 KiB")
+        self.assertEqual(s.humanReadable(max_places=2), "15.99 KiB")
 
         s = Size(0x10000000000000)
-        self.assertEquals(s.humanReadable(max_places=2), "4 PiB")
+        self.assertEqual(s.humanReadable(max_places=2), "4 PiB")
 
 
     def testMinValue(self):
         s = Size("9 MiB")
-        self.assertEquals(s.humanReadable(), "9 MiB")
-        self.assertEquals(s.humanReadable(min_value=10), "9216 KiB")
+        self.assertEqual(s.humanReadable(), "9 MiB")
+        self.assertEqual(s.humanReadable(min_value=10), "9216 KiB")
 
         s = Size("0.5 GiB")
-        self.assertEquals(s.humanReadable(max_places=2, min_value=1), "512 MiB")
-        self.assertEquals(s.humanReadable(max_places=2, min_value=Decimal(0.1)), "0.5 GiB")
-        self.assertEquals(s.humanReadable(max_places=2, min_value=Decimal(1)), "512 MiB")
+        self.assertEqual(s.humanReadable(max_places=2, min_value=1), "512 MiB")
+        self.assertEqual(s.humanReadable(max_places=2, min_value=Decimal(0.1)), "0.5 GiB")
+        self.assertEqual(s.humanReadable(max_places=2, min_value=Decimal(1)), "512 MiB")
 
     def testConvertToPrecision(self):
         s = Size(1835008)
-        self.assertEquals(s.convertTo(None), 1835008)
-        self.assertEquals(s.convertTo(B), 1835008)
-        self.assertEquals(s.convertTo(KiB), 1792)
-        self.assertEquals(s.convertTo(MiB), 1.75)
+        self.assertEqual(s.convertTo(None), 1835008)
+        self.assertEqual(s.convertTo(B), 1835008)
+        self.assertEqual(s.convertTo(KiB), 1792)
+        self.assertEqual(s.convertTo(MiB), 1.75)
 
     def testNegative(self):
         s = Size("-500MiB")
-        self.assertEquals(s.humanReadable(), "-500 MiB")
-        self.assertEquals(s.convertTo(B), -524288000)
+        self.assertEqual(s.humanReadable(), "-500 MiB")
+        self.assertEqual(s.convertTo(B), -524288000)
 
     def testPartialBytes(self):
-        self.assertEquals(Size(1024.6), Size(1024))
-        self.assertEquals(Size("%s KiB" % (1/1025.0,)), Size(0))
-        self.assertEquals(Size("%s KiB" % (1/1023.0,)), Size(1))
+        self.assertEqual(Size(1024.6), Size(1024))
+        self.assertEqual(Size("%s KiB" % (1/1025.0,)), Size(0))
+        self.assertEqual(Size("%s KiB" % (1/1023.0,)), Size(1))
 
     def testNoUnitsInString(self):
         self.assertEqual(Size("1024"), Size("1 KiB"))
@@ -282,25 +282,25 @@ def testTranslated(self):
             locale.setlocale(locale.LC_ALL, '')
 
             # Check English parsing
-            self.assertEquals(s, Size("56.19 MiB"))
+            self.assertEqual(s, Size("56.19 MiB"))
 
             # Check native parsing
-            self.assertEquals(s, Size("56.19 %s%s" % (_("Mi"), _("B"))))
+            self.assertEqual(s, Size("56.19 %s%s" % (_("Mi"), _("B"))))
 
             # Check native parsing, all lowercase
-            self.assertEquals(s, Size(("56.19 %s%s" % (_("Mi"), _("B"))).lower()))
+            self.assertEqual(s, Size(("56.19 %s%s" % (_("Mi"), _("B"))).lower()))
 
             # Check native parsing, all uppercase
-            self.assertEquals(s, Size(("56.19 %s%s" % (_("Mi"), _("B"))).upper()))
+            self.assertEqual(s, Size(("56.19 %s%s" % (_("Mi"), _("B"))).upper()))
 
             # If the radix separator is not a period, repeat the tests with the
             # native separator
             radix = locale.nl_langinfo(locale.RADIXCHAR)
             if radix != '.':
-                self.assertEquals(s, Size("56%s19 MiB" % radix))
-                self.assertEquals(s, Size("56%s19 %s%s" % (radix, _("Mi"), _("B"))))
-                self.assertEquals(s, Size(("56%s19 %s%s" % (radix, _("Mi"), _("B"))).lower()))
-                self.assertEquals(s, Size(("56%s19 %s%s" % (radix, _("Mi"), _("B"))).upper()))
+                self.assertEqual(s, Size("56%s19 MiB" % radix))
+                self.assertEqual(s, Size("56%s19 %s%s" % (radix, _("Mi"), _("B"))))
+                self.assertEqual(s, Size(("56%s19 %s%s" % (radix, _("Mi"), _("B"))).lower()))
+                self.assertEqual(s, Size(("56%s19 %s%s" % (radix, _("Mi"), _("B"))).upper()))
 
     def testHumanReadableTranslation(self):
         s = Size("56.19 MiB")
diff --git a/tests/tsort_test.py b/tests/tsort_test.py
index ee06509..e4902de 100644
--- a/tests/tsort_test.py
+++ b/tests/tsort_test.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 
 import unittest
 import blivet.tsort
@@ -16,13 +15,13 @@ def runTest(self):
 
         edges = [(5, 4), (4, 3), (3, 2), (2, 1), (3, 5)]
         graph = blivet.tsort.create_graph(items, edges)
-        self.failUnlessRaises(blivet.tsort.CyclicGraphError,
+        self.assertRaises(blivet.tsort.CyclicGraphError,
                               blivet.tsort.tsort,
                               graph)
 
         edges = [(5, 4), (4, 3), (3, 2), (2, 1), (2, 3)]
         graph = blivet.tsort.create_graph(items, edges)
-        self.failUnlessRaises(blivet.tsort.CyclicGraphError,
+        self.assertRaises(blivet.tsort.CyclicGraphError,
                               blivet.tsort.tsort,
                               graph)
 
@@ -46,11 +45,11 @@ def check_order(order, graph):
             self.fail(e)
 
         # verify output list is of the correct length
-        self.failIf(len(order) != len(graph['items']),
+        self.assertFalse(len(order) != len(graph['items']),
                     "sorted list length is incorrect")
 
         # verify that all ordering constraints are satisfied
-        self.failUnless(check_order(order, graph),
+        self.assertTrue(check_order(order, graph),
                         "ordering constraints not satisfied")
 
 if __name__ == "__main__":


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/54815f8aec38bb399de361f0041246dcc092fc3a


More information about the anaconda-patches mailing list