[blivet:master 1/2] Add some tests about fractional quantities near whole unit values

mulhern amulhern at redhat.com
Thu Sep 4 14:34:05 UTC 2014


Signed-off-by: mulhern <amulhern at redhat.com>
---
 tests/size_test.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/tests/size_test.py b/tests/size_test.py
index e2288e0..1058968 100644
--- a/tests/size_test.py
+++ b/tests/size_test.py
@@ -104,6 +104,30 @@ class SizeTestCase(unittest.TestCase):
         s = Size("12.6998 TiB")
         self.assertEquals(s.humanReadable(max_places=2), "12.7 TiB")
 
+        # byte values close to multiples of 2 are shown precisely
+        s = Size(0xfff)
+        self.assertEquals(s.humanReadable(max_places=2), "4095 B")
+        s = Size(8193)
+        self.assertEquals(s.humanReadable(max_places=2), "8193 B")
+
+        # a fractional quantity is shown if the value deviates
+        # from the whole number of units by more than 1%
+        s = Size(16384 - (1024/100 + 1))
+        self.assertEquals(s.humanReadable(max_places=2), "15.99 KiB")
+
+    @unittest.expectedFailure
+    def testHumanReadableFractionalQuantities(self):
+        # If the value deviates from the a whole number of units by
+        # less than 1%, but still deviates, a fractional quantity is not shown
+        s = Size(0xfffffffffffff)
+        self.assertEquals(s.humanReadable(max_places=2), "4096.0 TiB")
+        s = Size(0xfffff)
+        self.assertEquals(s.humanReadable(max_places=2), "1024.0 KiB")
+        s = Size(0xffff)
+        self.assertEquals(s.humanReadable(max_places=2), "64.0 KiB")
+        s = Size(16383)
+        self.assertEquals(s.humanReadable(max_places=2), "16.0 KiB")
+
     def testNegative(self):
         s = Size("-500MiB")
         self.assertEquals(s.humanReadable(), "-500 MiB")
-- 
1.9.3



More information about the anaconda-patches mailing list