@@ -0,0 +1,3089 @@
+%0Aimport unittest%0A%0Afrom blivet.devices import StorageDevice%0Afrom blivet import errors%0Afrom blivet.formats import getFormat%0Afrom blivet.size import Size%0A%0Aclass StorageDeviceSizeTest(unittest.TestCase):%0A    def _getDevice(self, *args, **kwargs):%0A        return StorageDevice(*args, **kwargs)%0A%0A    def testSizeSetter(self):%0A        initial_size = Size('10 GiB')%0A        new_size = Size('2 GiB')%0A%0A        ##%0A        ## setter sets the size%0A        ##%0A        dev = self._getDevice('sizetest', size=initial_size)%0A        self.assertEqual(dev.size, initial_size)%0A%0A        dev.size = new_size%0A        self.assertEqual(dev.size, new_size)%0A%0A        ##%0A        ## setter raises exn if size outside of format limits%0A        ##%0A        dev.format._maxSize = Size(%225 GiB%22)%0A        with self.assertRaises(errors.DeviceError):%0A            dev.size = Size(%226 GiB%22)%0A%0A        ##%0A        ## new formats' min size is checked against device size%0A        ##%0A        fmt = getFormat(None)%0A        fmt._minSize = Size(%2210 GiB%22)%0A        with self.assertRaises(errors.DeviceError):%0A            dev.format = fmt%0A%0A        # the format assignment should succeed without the min size conflict%0A        fmt._minSize = Size(0)%0A        dev.format = fmt%0A%0A        ##%0A        ## new formats' max size is checked against device size%0A        ##%0A        fmt = getFormat(None)%0A        fmt._maxSize = Size(%2210 MiB%22)%0A        with self.assertRaises(errors.DeviceError):%0A            dev.format = fmt%0A%0A        # the format assignment should succeed without the min size conflict%0A        fmt._maxSize = Size(0)%0A        dev.format = fmt%0A%0A    def testSizeGetter(self):%0A        initial_size = Size(%2210 GiB%22)%0A        new_size = Size(%225 GiB%22)%0A        dev = self._getDevice('sizetest', size=initial_size)%0A%0A        ##%0A        ## getter returns the size in the basic case for non-existing devices%0A        ##%0A        self.assertEqual(dev.size, initial_size)%0A%0A        # create a new device that exists%0A        dev = self._getDevice('sizetest', size=initial_size, exists=True)%0A%0A        ##%0A        ## getter returns the size in the basic case for existing devices%0A        ##%0A        self.assertEqual(dev.size, initial_size)%0A%0A        ##%0A        ## size does not reflect target size for non-resizable devices%0A        ##%0A        # bypass the setter since the min/max will be the current size for a%0A        # non-resizable device%0A        dev._targetSize = new_size%0A        self.assertEqual(dev.size, initial_size)%0A%0A        ##%0A        ## getter returns target size when device is resizable and target size%0A        ## is non-zero%0A        ##%0A        dev._resizable = True%0A        dev.targetSize = new_size # verify that the target size setter works%0A        self.assertEqual(dev.size, new_size)%0A        self.assertEqual(dev.size, dev.targetSize)%0A        self.assertNotEqual(dev._size, dev.targetSize)%0A%0A        ##%0A        ## getter returns current size when device is resizable and target size%0A        ## is zero%0A        ##%0A        dev.targetSize = Size(0)%0A        self.assertEqual(dev.size, initial_size)%0A        self.assertEqual(dev.size, dev.currentSize)%0A

Add unit tests for device size setters and getters.