diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 516: Allow image sizes to be specified as floating point values. Fixes #997344. Patch by Michael Hope.

Message ID 20120514123017.18968.24416.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Данило Шеган May 14, 2012, 12:30 p.m. UTC
Merge authors:
  Michael Hope (michaelh1)
Related merge proposals:
  https://code.launchpad.net/~michaelh1/linaro-image-tools/float-image-size/+merge/105270
  proposed by: Michael Hope (michaelh1)
  review: Approve - Данило Шеган (danilo)
------------------------------------------------------------
revno: 516 [merge]
committer: Danilo Šegan <danilo@segan.org>
branch nick: trunk
timestamp: Mon 2012-05-14 14:27:10 +0200
message:
  Allow image sizes to be specified as floating point values. Fixes #997344. Patch by Michael Hope.
modified:
  linaro_image_tools/media_create/partitions.py
  linaro_image_tools/media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/media_create/partitions.py'
--- linaro_image_tools/media_create/partitions.py	2012-04-18 14:18:34 +0000
+++ linaro_image_tools/media_create/partitions.py	2012-05-09 21:25:20 +0000
@@ -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'
--- linaro_image_tools/media_create/tests/test_media_create.py	2012-04-20 13:09:03 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2012-05-09 21:25:20 +0000
@@ -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 = (