本文整理匯總了Python中blivet.size.Size.round_to_nearest方法的典型用法代碼示例。如果您正苦於以下問題:Python Size.round_to_nearest方法的具體用法?Python Size.round_to_nearest怎麽用?Python Size.round_to_nearest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類blivet.size.Size
的用法示例。
在下文中一共展示了Size.round_to_nearest方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_resize
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import round_to_nearest [as 別名]
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())
示例2: test_shrink
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import round_to_nearest [as 別名]
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)
示例3: test_round_to_nearest
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import round_to_nearest [as 別名]
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)