Addressed PR comment.

This commit is contained in:
Julio-Oliveira-Encora 2024-05-30 14:42:43 -03:00
parent 3c8b184fdf
commit 1d21cd4f8a
2 changed files with 7 additions and 7 deletions

View File

@ -98,15 +98,15 @@ def humanize_megabytes(mb):
# Factors in bytes
factors = {
"mega": 1024 ** 2,
"giga": 1024 ** 3,
"tera": 1024 ** 4,
"mega": 1000 ** 2,
"giga": 1000 ** 3,
"tera": 1000 ** 4,
}
if not mb:
return ""
bytes = int(mb * 1024**2)
bytes = int(mb * 1000**2)
if bytes >= factors["tera"]:
return f"{bytes / factors['tera']:.2f} TB"

View File

@ -10,11 +10,11 @@ class TestConvertByteSize(TestCase):
def test_humanize_megabytes_converts_to_gigabytes(self):
"""Test that humanize_megabytes converts megabytes to gigabytes."""
self.assertEqual(humanize_megabytes(1024), "1.00 GB")
self.assertEqual(humanize_megabytes(1000), "1.00 GB")
def test_humanize_megabytes_converts_to_terabytes(self):
"""Test that humanize_megabytes converts megabytes to terabytes."""
self.assertEqual(humanize_megabytes(1048576), "1.00 TB")
self.assertEqual(humanize_megabytes(1000000), "1.00 TB")
def test_humanize_megabytes_returns_empty_for_none(self):
"""Test that humanize_megabytes returns empty for None."""
@ -22,4 +22,4 @@ class TestConvertByteSize(TestCase):
def test_humanize_megabytes_without_unit(self):
"""Test that humanize_megabytes returns the value without unit."""
self.assertEqual(humanize_megabytes(123456789), "117.74 TB")
self.assertEqual(humanize_megabytes(123456789), "123.46 TB")