本文整理匯總了Python中blivet.size.Size.human_readable方法的典型用法代碼示例。如果您正苦於以下問題:Python Size.human_readable方法的具體用法?Python Size.human_readable怎麽用?Python Size.human_readable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類blivet.size.Size
的用法示例。
在下文中一共展示了Size.human_readable方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_exceptions
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import human_readable [as 別名]
def test_exceptions(self):
zero = Size(0)
self.assertEqual(zero, Size("0.0"))
s = Size(500)
with self.assertRaises(ValueError):
s.human_readable(max_places="2")
self.assertEqual(s.human_readable(max_places=0), "500 B")
示例2: test_human_readable_translation
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import human_readable [as 別名]
def test_human_readable_translation(self):
s = Size("56.19 MiB")
size_str = s.human_readable()
for lang in TEST_LANGS:
os.environ['LANG'] = lang
locale.setlocale(locale.LC_ALL, '')
self.assertTrue(s.human_readable().endswith("%s" % (_BS("MiB"))))
self.assertEqual(s.human_readable(xlate=False), size_str)
示例3: test_human_readable_fractional_quantities
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import human_readable [as 別名]
def test_human_readable_fractional_quantities(self):
s = Size(0xfffffffffffff)
self.assertEqual(s.human_readable(max_places=2), "4 PiB")
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.human_readable(max_places=2), "64 KiB")
# since all significant digits are shown, there are no trailing 0s.
self.assertEqual(s.human_readable(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.human_readable(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.human_readable(max_places=2), "15.99 KiB")
s = Size(0x10000000000000)
self.assertEqual(s.human_readable(max_places=2), "4 PiB")
示例4: test_human_readable
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import human_readable [as 別名]
def test_human_readable(self):
s = Size(58929971)
self.assertEqual(s.human_readable(), "56.2 MiB")
s = Size(478360371)
self.assertEqual(s.human_readable(), "456.2 MiB")
# human_reable 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.human_readable(max_places=2), "12.68 TiB")
s = Size("26.55 MiB")
self.assertEqual(s.human_readable(max_places=2), "26.55 MiB")
s = Size("300 MiB")
self.assertEqual(s.human_readable(max_places=2), "300 MiB")
# rounding should work with max_places limitted
s = Size("12.687 TiB")
self.assertEqual(s.human_readable(max_places=2), "12.69 TiB")
s = Size("23.7874 TiB")
self.assertEqual(s.human_readable(max_places=3), "23.787 TiB")
s = Size("12.6998 TiB")
self.assertEqual(s.human_readable(max_places=2), "12.7 TiB")
# byte values close to multiples of 2 are shown without trailing zeros
s = Size(0xff)
self.assertEqual(s.human_readable(max_places=2), "255 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.human_readable(max_places=2), "15.99 KiB")
# if max_places is set to None, all digits are displayed
s = Size(0xfffffffffffff)
self.assertEqual(s.human_readable(max_places=None), "3.99999999999999911182158029987476766109466552734375 PiB")
s = Size(0x10000)
self.assertEqual(s.human_readable(max_places=None), "64 KiB")
s = Size(0x10001)
self.assertEqual(s.human_readable(max_places=None), "64.0009765625 KiB")
# test a very large quantity with no associated abbreviation or prefix
s = Size(1024 ** 9)
self.assertEqual(s.human_readable(max_places=2), "1024 YiB")
s = Size(1024 ** 9 - 1)
self.assertEqual(s.human_readable(max_places=2), "1024 YiB")
s = Size(1024 ** 10)
self.assertEqual(s.human_readable(max_places=2), "1048576 YiB")
示例5: test_segative
# 需要導入模塊: from blivet.size import Size [as 別名]
# 或者: from blivet.size.Size import human_readable [as 別名]
def test_segative(self):
s = Size("-500MiB")
self.assertEqual(s.human_readable(), "-500 MiB")
self.assertEqual(s.convert_to(B), -524288000)