[PATCH 2/2] Add some more tests for the Size.humanReadable method
Vratislav Podzimek
vpodzime at redhat.com
Tue Apr 22 14:44:17 UTC 2014
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
tests/size_test.py | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tests/size_test.py b/tests/size_test.py
index a523c1d..96df521 100644
--- a/tests/size_test.py
+++ b/tests/size_test.py
@@ -76,6 +76,29 @@ class SizeTestCase(unittest.TestCase):
s = Size(bytes=478360371L)
self.assertEquals(s.humanReadable(), "456.2 MiB")
+ # humanReable output should be the same as input for big enough sizes
+ # and enough places
+ s = Size(spec="12.68 TiB")
+ self.assertEquals(s.humanReadable(max_places=2), "12.68 TiB")
+ s = Size(spec="26.55 MiB")
+ self.assertEquals(s.humanReadable(max_places=2), "26.55 MiB")
+
+ # smaller unit should be used for small sizes
+ s = Size(spec="9.68 TiB")
+ self.assertEquals(s.humanReadable(max_places=2), "9912.32 GiB")
+ s = Size(spec="4.29 MiB")
+ self.assertEquals(s.humanReadable(max_places=2), "4392.96 KiB")
+ s = Size(spec="7.18 KiB")
+ self.assertEquals(s.humanReadable(max_places=2), "7352 B")
+
+ # rounding should work with max_places limitted
+ s = Size(spec="12.687 TiB")
+ self.assertEquals(s.humanReadable(max_places=2), "12.69 TiB")
+ s = Size(spec="23.7874 TiB")
+ self.assertEquals(s.humanReadable(max_places=3), "23.787 TiB")
+ s = Size(spec="12.6998 TiB")
+ self.assertEquals(s.humanReadable(max_places=2), "12.7 TiB")
+
def testNegative(self):
s = Size(spec="-500MiB")
self.assertEquals(s.humanReadable(), "-500 MiB")
--
1.9.0
More information about the anaconda-patches
mailing list