Merge "Fix human readable when size is None"

This commit is contained in:
Jenkins
2015-09-28 11:49:14 +00:00
committed by Gerrit Code Review
2 changed files with 4 additions and 1 deletions

View File

@@ -307,8 +307,10 @@ def save_image(data, path):
def make_size_human_readable(size): def make_size_human_readable(size):
suffix = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'] suffix = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']
base = 1024.0 base = 1024.0
index = 0 index = 0
if size is None:
size = 0
while size >= base: while size >= base:
index = index + 1 index = index + 1
size = size / base size = size / base

View File

@@ -33,6 +33,7 @@ class TestUtils(testtools.TestCase):
self.assertEqual("1MB", utils.make_size_human_readable(1048576)) self.assertEqual("1MB", utils.make_size_human_readable(1048576))
self.assertEqual("1.4GB", utils.make_size_human_readable(1476395008)) self.assertEqual("1.4GB", utils.make_size_human_readable(1476395008))
self.assertEqual("9.3MB", utils.make_size_human_readable(9761280)) self.assertEqual("9.3MB", utils.make_size_human_readable(9761280))
self.assertEqual("0B", utils.make_size_human_readable(None))
def test_get_new_file_size(self): def test_get_new_file_size(self):
size = 98304 size = 98304