def test_shrink(self): an_fs = self._fs_class() if not can_resize(an_fs): self.skipTest("Not checking resize for this test category.") if not an_fs.formattable: self.skipTest("can not create filesystem %s" % an_fs.name) an_fs.device = self.loop_devices[0] self.assertIsNone(an_fs.create()) an_fs.update_size_info() TARGET_SIZE = Size("64 MiB") an_fs.target_size = TARGET_SIZE self.assertIsNone(an_fs.do_resize()) TARGET_SIZE = TARGET_SIZE / 2 self.assertTrue(TARGET_SIZE > an_fs.min_size) an_fs.target_size = TARGET_SIZE self.assertEqual(an_fs.target_size, TARGET_SIZE) self.assertNotEqual(an_fs._size, TARGET_SIZE) # FIXME: # do_check() in update_size_info() in do_resize() does not complete tidily # here, so resizable becomes False and self.target_size can not be # assigned to. This alerts us to the fact that now min size # and size are both incorrect values. if isinstance(an_fs, fs.NTFS): return self.assertIsNone(an_fs.do_resize()) ACTUAL_SIZE = TARGET_SIZE.round_to_nearest(an_fs._resize.unit, rounding=ROUND_DOWN) self.assertEqual(an_fs._size, ACTUAL_SIZE) self._test_sizes(an_fs)
def test_resize(self): an_fs = self._fs_class() if not an_fs.formattable: self.skipTest("can not create filesystem %s" % an_fs.name) an_fs.device = self.loop_devices[0] self.assertIsNone(an_fs.create()) an_fs.update_size_info() self._test_sizes(an_fs) # CHECKME: target size is still 0 after updated_size_info is called. self.assertEqual(an_fs.size, Size(0) if an_fs.resizable else an_fs._size) if not self.can_resize(an_fs): self.assertFalse(an_fs.resizable) # Not resizable, so can not do resizing actions. with self.assertRaises(DeviceFormatError): an_fs.target_size = Size("64 MiB") with self.assertRaises(DeviceFormatError): an_fs.do_resize() else: self.assertTrue(an_fs.resizable) # Try a reasonable target size TARGET_SIZE = Size("64 MiB") an_fs.target_size = TARGET_SIZE self.assertEqual(an_fs.target_size, TARGET_SIZE) self.assertNotEqual(an_fs._size, TARGET_SIZE) self.assertIsNone(an_fs.do_resize()) ACTUAL_SIZE = TARGET_SIZE.round_to_nearest(an_fs._resize.unit, rounding=ROUND_DOWN) self.assertEqual(an_fs.size, ACTUAL_SIZE) self.assertEqual(an_fs._size, ACTUAL_SIZE) self._test_sizes(an_fs) # and no errors should occur when checking self.assertIsNone(an_fs.do_check())
def test_resize(self): an_fs = self._fs_class() if not an_fs.formattable: self.skipTest("can not create filesystem %s" % an_fs.name) an_fs.device = self.loop_devices[0] self.assertIsNone(an_fs.create()) an_fs.update_size_info() self._test_sizes(an_fs) # CHECKME: target size is still 0 after updated_size_info is called. self.assertEqual(an_fs.size, Size(0) if an_fs.resizable else an_fs._size) if not can_resize(an_fs): self.assertFalse(an_fs.resizable) # Not resizable, so can not do resizing actions. with self.assertRaises(FSError): an_fs.target_size = Size("64 MiB") with self.assertRaises(FSError): an_fs.do_resize() else: self.assertTrue(an_fs.resizable) # Try a reasonable target size TARGET_SIZE = Size("64 MiB") an_fs.target_size = TARGET_SIZE self.assertEqual(an_fs.target_size, TARGET_SIZE) self.assertNotEqual(an_fs._size, TARGET_SIZE) self.assertIsNone(an_fs.do_resize()) ACTUAL_SIZE = TARGET_SIZE.round_to_nearest(an_fs._resize.unit, rounding=ROUND_DOWN) self.assertEqual(an_fs.size, ACTUAL_SIZE) self.assertEqual(an_fs._size, ACTUAL_SIZE) self._test_sizes(an_fs) # and no errors should occur when checking self.assertIsNone(an_fs.do_check())
def test_round_to_nearest(self): self.assertEqual(size.ROUND_DEFAULT, size.ROUND_UP) s = Size("10.3 GiB") self.assertEqual(s.round_to_nearest(GiB), Size("10 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_DEFAULT), Size("10 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_DOWN), Size("10 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_UP), Size("11 GiB")) # >>> Size("10.3 GiB").convert_to(MiB) # Decimal('10547.19999980926513671875') self.assertEqual(s.round_to_nearest(MiB), Size("10547 MiB")) self.assertEqual(s.round_to_nearest(MiB, rounding=size.ROUND_UP), Size("10548 MiB")) self.assertIsInstance(s.round_to_nearest(MiB), Size) with self.assertRaises(ValueError): s.round_to_nearest(MiB, rounding='abc') # arbitrary decimal rounding constants are not allowed from decimal import ROUND_HALF_DOWN with self.assertRaises(ValueError): s.round_to_nearest(MiB, rounding=ROUND_HALF_DOWN) s = Size("10.51 GiB") self.assertEqual(s.round_to_nearest(GiB), Size("11 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_DEFAULT), Size("11 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_DOWN), Size("10 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_UP), Size("11 GiB")) s = Size("513 GiB") self.assertEqual(s.round_to_nearest(GiB), s) self.assertEqual(s.round_to_nearest(TiB), Size("1 TiB")) self.assertEqual(s.round_to_nearest(TiB, rounding=size.ROUND_DOWN), Size(0)) # test Size parameters self.assertEqual(s.round_to_nearest(Size("128 GiB")), Size("512 GiB")) self.assertEqual(s.round_to_nearest(Size("1 KiB")), Size("513 GiB")) self.assertEqual(s.round_to_nearest(Size("1 TiB")), Size("1 TiB")) self.assertEqual( s.round_to_nearest(Size("1 TiB"), rounding=size.ROUND_DOWN), Size(0)) self.assertEqual(s.round_to_nearest(Size(0)), Size(0)) self.assertEqual(s.round_to_nearest(Size("13 GiB")), Size("507 GiB")) with self.assertRaises(ValueError): s.round_to_nearest(Size("-1 B"))
def test_round_to_nearest(self): s = Size("10.3 GiB") self.assertEqual(s.round_to_nearest(GiB, size.ROUND_HALF_UP), Size("10 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_DOWN), Size("10 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_UP), Size("11 GiB")) # >>> Size("10.3 GiB").convert_to(MiB) # Decimal('10547.19999980926513671875') self.assertEqual(s.round_to_nearest(MiB, size.ROUND_HALF_UP), Size("10547 MiB")) self.assertEqual(s.round_to_nearest(MiB, rounding=size.ROUND_UP), Size("10548 MiB")) self.assertIsInstance(s.round_to_nearest(MiB, size.ROUND_HALF_UP), Size) with self.assertRaises(ValueError): s.round_to_nearest(MiB, rounding='abc') # arbitrary decimal rounding constants are not allowed from decimal import ROUND_HALF_DOWN with self.assertRaises(ValueError): s.round_to_nearest(MiB, rounding=ROUND_HALF_DOWN) s = Size("10.51 GiB") self.assertEqual(s.round_to_nearest(GiB, size.ROUND_HALF_UP), Size("11 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_DOWN), Size("10 GiB")) self.assertEqual(s.round_to_nearest(GiB, rounding=size.ROUND_UP), Size("11 GiB")) s = Size("513 GiB") self.assertEqual(s.round_to_nearest(GiB, size.ROUND_HALF_UP), s) self.assertEqual(s.round_to_nearest(TiB, size.ROUND_HALF_UP), Size("1 TiB")) self.assertEqual(s.round_to_nearest(TiB, rounding=size.ROUND_DOWN), Size(0)) # test Size parameters self.assertEqual(s.round_to_nearest(Size("128 GiB"), size.ROUND_HALF_UP), Size("512 GiB")) self.assertEqual(s.round_to_nearest(Size("1 KiB"), size.ROUND_HALF_UP), Size("513 GiB")) self.assertEqual(s.round_to_nearest(Size("1 TiB"), size.ROUND_HALF_UP), Size("1 TiB")) self.assertEqual(s.round_to_nearest(Size("1 TiB"), rounding=size.ROUND_DOWN), Size(0)) self.assertEqual(s.round_to_nearest(Size(0), size.ROUND_HALF_UP), Size(0)) self.assertEqual(s.round_to_nearest(Size("13 GiB"), size.ROUND_HALF_UP), Size("507 GiB")) with self.assertRaises(ValueError): s.round_to_nearest(Size("-1 B"), size.ROUND_HALF_UP)