本文整理匯總了Python中blivet.size.Size.humanReadable方法的典型用法代碼示例。如果您正苦於以下問題:Python Size.humanReadable方法的具體用法?Python Size.humanReadable怎麽用?Python Size.humanReadable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類blivet.size.Size
的用法示例。
在下文中一共展示了Size.humanReadable方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testHumanReadableTranslation
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testHumanReadableTranslation(self):
s = Size("56.19 MiB")
size_str = s.humanReadable()
for lang in self.TEST_LANGS:
os.environ['LANG'] = lang
locale.setlocale(locale.LC_ALL, '')
self.assertTrue(s.humanReadable().endswith("%s%s" % (_("Mi"), _("B"))))
self.assertEqual(s.humanReadable(xlate=False), size_str)
示例2: testExceptions
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testExceptions(self):
zero = Size(0)
self.assertEqual(zero, Size("0.0"))
s = Size(500)
with self.assertRaises(SizePlacesError):
s.humanReadable(max_places=-1)
self.assertEqual(s.humanReadable(max_places=0), "500 B")
示例3: testMinValue
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testMinValue(self):
s = Size("9 MiB")
self.assertEqual(s.humanReadable(), "9 MiB")
self.assertEqual(s.humanReadable(min_value=10), "9216 KiB")
s = Size("0.5 GiB")
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")
示例4: testExceptions
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testExceptions(self):
zero = Size(0)
self.assertEqual(zero, 0.0)
s = Size(500)
self.assertRaises(SizePlacesError, s.humanReadable, places=-1)
self.assertEqual(s.humanReadable(places=0), "500 B")
示例5: testExceptions
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testExceptions(self):
self.assertRaises(SizeParamsError, Size)
self.assertRaises(SizeParamsError, Size, bytes=500, spec="45GB")
zero = Size(bytes=0)
self.assertEqual(zero, 0.0)
s = Size(bytes=500)
self.assertRaises(SizePlacesError, s.humanReadable, places=-1)
self.assertEqual(s.humanReadable(places=0), "500 B")
示例6: testHumanReadableFractionalQuantities
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testHumanReadableFractionalQuantities(self):
s = Size(0xfffffffffffff)
self.assertEqual(s.humanReadable(max_places=2), "4 PiB")
s = Size(0xfffff)
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.assertEqual(s.humanReadable(max_places=2), "64 KiB")
# since all significant digits are shown, there are no trailing 0s.
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.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.assertEqual(s.humanReadable(max_places=2), "15.99 KiB")
s = Size(0x10000000000000)
self.assertEqual(s.humanReadable(max_places=2), "4 PiB")
示例7: testHumanReadable
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testHumanReadable(self):
s = Size(58929971)
self.assertEqual(s.humanReadable(), "56.2 MiB")
s = Size(478360371)
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.assertEqual(s.humanReadable(max_places=2), "12.68 TiB")
s = Size("26.55 MiB")
self.assertEqual(s.humanReadable(max_places=2), "26.55 MiB")
s = Size("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.assertEqual(s.humanReadable(max_places=2, min_value=10), "9912.32 GiB")
s = Size("4.29 MiB")
self.assertEqual(s.humanReadable(max_places=2, min_value=10), "4392.96 KiB")
s = Size("7.18 KiB")
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.assertEqual(s.humanReadable(max_places=2), "12.69 TiB")
s = Size("23.7874 TiB")
self.assertEqual(s.humanReadable(max_places=3), "23.787 TiB")
s = Size("12.6998 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.assertEqual(s.humanReadable(max_places=2), "255 B")
s = Size(8193)
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.assertEqual(s.humanReadable(max_places=2), "15.99 KiB")
# if max_places is set to None, all digits are displayed
s = Size(0xfffffffffffff)
self.assertEqual(s.humanReadable(max_places=None), "3.9999999999999991118215803 PiB")
s = Size(0x10000)
self.assertEqual(s.humanReadable(max_places=None), "64 KiB")
s = Size(0x10001)
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.assertEqual(s.humanReadable(max_places=2), "1024 YiB")
s = Size(1024**9 - 1)
self.assertEqual(s.humanReadable(max_places=2), "1024 YiB")
s = Size(1024**9 + 1)
self.assertEqual(s.humanReadable(max_places=2, strip=False), "1024.00 YiB")
s = Size(1024**10)
self.assertEqual(s.humanReadable(max_places=2), "1048576 YiB")
示例8: testNegative
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testNegative(self):
s = Size("-500MiB")
self.assertEqual(s.humanReadable(), "-500 MiB")
self.assertEqual(s.convertTo(B), -524288000)
示例9: testHumanReadable
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testHumanReadable(self):
s = Size(58929971L)
self.assertEquals(s.humanReadable(), "56.2 MiB")
s = Size(478360371L)
self.assertEquals(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")
s = Size("26.55 MiB")
self.assertEquals(s.humanReadable(max_places=2), "26.55 MiB")
s = Size("300 MiB")
self.assertEquals(s.humanReadable(max_places=2), "300 MiB")
# smaller unit should be used for small sizes
s = Size("9.68 TiB")
self.assertEquals(s.humanReadable(max_places=2), "9912.32 GiB")
s = Size("4.29 MiB")
self.assertEquals(s.humanReadable(max_places=2), "4392.96 KiB")
s = Size("7.18 KiB")
self.assertEquals(s.humanReadable(max_places=2), "7352 B")
# rounding should work with max_places limitted
s = Size("12.687 TiB")
self.assertEquals(s.humanReadable(max_places=2), "12.69 TiB")
s = Size("23.7874 TiB")
self.assertEquals(s.humanReadable(max_places=3), "23.787 TiB")
s = Size("12.6998 TiB")
self.assertEquals(s.humanReadable(max_places=2), "12.7 TiB")
示例10: testHumanReadable
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import humanReadable [as 別名]
def testHumanReadable(self):
s = Size(bytes=58929971L)
self.assertEquals(s.humanReadable(), "56.19 MiB")
s = Size(bytes=478360371L)
self.assertEquals(s.humanReadable(), "456.19 MiB")