Esempio n. 1
0
def pretty_bytes(num_bytes):
    format_string = "{} {}"
    if num_bytes < 1000:
        unit = "B"
    elif num_bytes < 1000000:
        unit = "kB"
        num_bytes = num_bytes / 1000
    elif num_bytes < 1000000000:
        unit = "MB"
        num_bytes = num_bytes / 1000000
    elif num_bytes < 1000000000000:
        unit = "GB"
        num_bytes = num_bytes / 1000000000
    else:
        unit = "TB"
        num_bytes = num_bytes / 1000000000000
    return "{} {}".format(truncate(num_bytes, 3),  unit)
Esempio n. 2
0
 def test_truncate_100(self):
     actual = utils.truncate(100.444, decimals=100)
     expected = 100.444
     self.assertEqual(expected, actual)
     self.assertIsInstance(actual, float)
Esempio n. 3
0
 def test_truncate_3(self):
     actual = utils.truncate(1.002, decimals=3)
     expected = 1.002
     self.assertEqual(expected, actual)
     self.assertIsInstance(actual, float)
Esempio n. 4
0
 def test_truncate_0(self):
     actual = utils.truncate(100.444)
     expected = 100
     self.assertEqual(expected, actual)
     self.assertIsInstance(actual, int)