コード例 #1
0
 def test_base_2(self):
     self.assertEqual(format_bytes(1000000, binary=True), '977KiB')
     self.assertEqual(format_bytes(7000, binary=True), '7KiB')
     self.assertEqual(format_bytes(37500000, binary=True), '36MiB')
     self.assertEqual(format_bytes(1000000000000, binary=True), '931GiB')
     self.assertEqual(format_bytes(2000000000000, binary=True), '2TiB')
     self.assertEqual(format_bytes(123000000, binary=True), '117MiB')
     self.assertEqual(format_bytes(123456789, binary=True), '118MiB')
     self.assertEqual(format_bytes(1, binary=True), '1B')
     self.assertEqual(format_bytes(37500000, binary=False), '38MB')
コード例 #2
0
 def test_bits(self):
     self.assertEqual(format_bytes(1000000, bits=True), '8Mb')
     self.assertEqual(format_bytes(1, bits=True), '8b')
     self.assertEqual(format_bytes(7000, bits=True), '56Kb')
     self.assertEqual(format_bytes(37500000, bits=True), '300Mb')
     self.assertEqual(format_bytes(123000000, bits=True), '984Mb')
     self.assertEqual(format_bytes(123456789, bits=True), '988Mb')
     self.assertEqual(format_bytes(123456789, bits=False), '123MB')
コード例 #3
0
 def test_bytes(self):
     self.assertEqual(format_bytes(0), '0B')
     self.assertEqual(format_bytes(95), '95B')
コード例 #4
0
 def test_error_for_negative_bytes(self):
     with self.assertRaises(ValueError):
         format_bytes(-100)
コード例 #5
0
 def test_terabytes(self):
     self.assertEqual(format_bytes(7500000002000), '8TB')
コード例 #6
0
 def test_gigabytes(self):
     self.assertEqual(format_bytes(1234567890), '1GB')
     self.assertEqual(format_bytes(75000000020), '75GB')
コード例 #7
0
 def test_megabytes(self):
     self.assertEqual(format_bytes(1000000), '1MB')
     self.assertEqual(format_bytes(9800004), '10MB')
     self.assertEqual(format_bytes(98000040), '98MB')
     self.assertEqual(format_bytes(123456789), '123MB')
コード例 #8
0
 def test_kilobytes(self):
     self.assertEqual(format_bytes(1000), '1KB')
     self.assertEqual(format_bytes(15000), '15KB')
     self.assertEqual(format_bytes(12345), '12KB')