def testCustomPrecision(self): self.assertEqual(format_utils.BytesToHumanReadable(5000, precision=3), '4.882 KiB') self.assertEqual(format_utils.BytesToHumanReadable(500000, precision=0), '488 KiB') self.assertEqual(format_utils.BytesToHumanReadable(5000000, precision=5), '4.76837 MiB')
def testBaseTwo(self): self.assertEqual(format_utils.BytesToHumanReadable(0x1000), '4 KiB') self.assertEqual(format_utils.BytesToHumanReadable(0x400000), '4 MiB') self.assertEqual(format_utils.BytesToHumanReadable(0x100000000), '4 GiB') self.assertEqual(format_utils.BytesToHumanReadable(0x40000000000), '4 TiB')
def testDecimal(self): self.assertEqual(format_utils.BytesToHumanReadable(5000, decimal=True), '5 kB') self.assertEqual(format_utils.BytesToHumanReadable(5000000, decimal=True), '5 MB') self.assertEqual(format_utils.BytesToHumanReadable(5000000000, decimal=True), '5 GB')
def testDefaultPrecision(self): self.assertEqual(format_utils.BytesToHumanReadable(5000), '4.8 KiB') self.assertEqual(format_utils.BytesToHumanReadable(500000), '488.2 KiB') self.assertEqual(format_utils.BytesToHumanReadable(5000000), '4.7 MiB')
def AddHumanReadableSize(size): fmt = format_utils.BytesToHumanReadable(size) return '%s (%s)' % (size, fmt) if fmt else str(size)