本文整理匯總了Python中blivet.size.Size.roundToNearest方法的典型用法代碼示例。如果您正苦於以下問題:Python Size.roundToNearest方法的具體用法?Python Size.roundToNearest怎麽用?Python Size.roundToNearest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類blivet.size.Size
的用法示例。
在下文中一共展示了Size.roundToNearest方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testShrink
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import roundToNearest [as 別名]
def testShrink(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.loopDevices[0]
self.assertIsNone(an_fs.create())
an_fs.updateSizeInfo()
TARGET_SIZE = Size("64 MiB")
an_fs.targetSize = TARGET_SIZE
self.assertIsNone(an_fs.doResize())
TARGET_SIZE = TARGET_SIZE / 2
self.assertTrue(TARGET_SIZE > an_fs.minSize)
an_fs.targetSize = TARGET_SIZE
self.assertEqual(an_fs.targetSize, TARGET_SIZE)
self.assertNotEqual(an_fs._size, TARGET_SIZE)
# FIXME:
# doCheck() in updateSizeInfo() in doResize() does not complete tidily
# here, so resizable becomes False and self.targetSize 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.doResize())
ACTUAL_SIZE = TARGET_SIZE.roundToNearest(an_fs._resize.unit, rounding=ROUND_DOWN)
self.assertEqual(an_fs._size, ACTUAL_SIZE)
self._test_sizes(an_fs)
示例2: testResize
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import roundToNearest [as 別名]
def testResize(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.loopDevices[0]
self.assertIsNone(an_fs.create())
an_fs.updateSizeInfo()
self._test_sizes(an_fs)
# CHECKME: target size is still 0 after updatedSizeInfo 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.targetSize = Size("64 MiB")
with self.assertRaises(FSError):
an_fs.doResize()
else:
self.assertTrue(an_fs.resizable)
# Try a reasonable target size
TARGET_SIZE = Size("64 MiB")
an_fs.targetSize = TARGET_SIZE
self.assertEqual(an_fs.targetSize, TARGET_SIZE)
self.assertNotEqual(an_fs._size, TARGET_SIZE)
self.assertIsNone(an_fs.doResize())
ACTUAL_SIZE = TARGET_SIZE.roundToNearest(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.doCheck())
示例3: testRoundToNearest
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import roundToNearest [as 別名]
def testRoundToNearest(self):
self.assertEqual(size.ROUND_DEFAULT, size.ROUND_HALF_UP)
s = Size("10.3 GiB")
self.assertEqual(s.roundToNearest(GiB), Size("10 GiB"))
self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DEFAULT),
Size("10 GiB"))
self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DOWN),
Size("10 GiB"))
self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_UP),
Size("11 GiB"))
# >>> Size("10.3 GiB").convertTo(MiB)
# Decimal('10547.19999980926513671875')
self.assertEqual(s.roundToNearest(MiB), Size("10547 MiB"))
self.assertEqual(s.roundToNearest(MiB, rounding=size.ROUND_UP),
Size("10548 MiB"))
self.assertIsInstance(s.roundToNearest(MiB), Size)
with self.assertRaises(ValueError):
s.roundToNearest(MiB, rounding='abc')
# arbitrary decimal rounding constants are not allowed
from decimal import ROUND_HALF_DOWN
with self.assertRaises(ValueError):
s.roundToNearest(MiB, rounding=ROUND_HALF_DOWN)
s = Size("10.51 GiB")
self.assertEqual(s.roundToNearest(GiB), Size("11 GiB"))
self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DEFAULT),
Size("11 GiB"))
self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_DOWN),
Size("10 GiB"))
self.assertEqual(s.roundToNearest(GiB, rounding=size.ROUND_UP),
Size("11 GiB"))
s = Size("513 GiB")
self.assertEqual(s.roundToNearest(GiB), s)
self.assertEqual(s.roundToNearest(TiB), Size("1 TiB"))
self.assertEqual(s.roundToNearest(TiB, rounding=size.ROUND_DOWN),
Size(0))
# test Size parameters
self.assertEqual(s.roundToNearest(Size("128 GiB")), Size("512 GiB"))
self.assertEqual(s.roundToNearest(Size("1 KiB")), Size("513 GiB"))
self.assertEqual(s.roundToNearest(Size("1 TiB")), Size("1 TiB"))
self.assertEqual(s.roundToNearest(Size("1 TiB"), rounding=size.ROUND_DOWN), Size(0))
self.assertEqual(s.roundToNearest(Size(0)), Size(0))
self.assertEqual(s.roundToNearest(Size("13 GiB")), Size("507 GiB"))
with self.assertRaises(ValueError):
s.roundToNearest(Size("-1 B"))