=== modified file 'linaro_image_tools/media_create/partitions.py'
@@ -483,8 +483,8 @@
unit = size[-1].upper()
# no unit? (ends with a digit)
if unit in '0123456789':
- return int(size)
- real_size = int(size[:-1])
+ return int(round(float(size)))
+ real_size = float(size[:-1])
if unit == 'K':
real_size = real_size * 1024
elif unit == 'M':
@@ -495,7 +495,7 @@
raise ValueError("Unknown size format: %s. Use K[bytes], M[bytes] "
"or G[bytes]" % size)
- return real_size
+ return int(round(real_size))
def run_sfdisk_commands(commands, heads, sectors, cylinders, device,
=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
@@ -2408,6 +2408,21 @@
def test_convert_size_in_gbytes_to_bytes(self):
self.assertEqual(12 * 1024**3, convert_size_to_bytes('12G'))
+ def test_convert_size_float_no_suffix(self):
+ self.assertEqual(1539, convert_size_to_bytes('1539.49'))
+
+ def test_convert_size_float_round_up(self):
+ self.assertEqual(1540, convert_size_to_bytes('1539.50'))
+
+ def test_convert_size_float_in_kbytes_to_bytes(self):
+ self.assertEqual(int(round(234.8 * 1024)), convert_size_to_bytes('234.8K'))
+
+ def test_convert_size_float_in_mbytes_to_bytes(self):
+ self.assertEqual(int(round(876.123 * 1024**2)), convert_size_to_bytes('876.123M'))
+
+ def test_convert_size_float_in_gbytes_to_bytes(self):
+ self.assertEqual(int(round(1.9 * 1024**3)), convert_size_to_bytes('1.9G'))
+
def test_calculate_partition_size_and_offset(self):
tmpfile = self._create_tmpfile()
vfat_size, vfat_offset, linux_size, linux_offset = (