diff --git a/bumblebee/util.py b/bumblebee/util.py index f35ce89..730ed87 100644 --- a/bumblebee/util.py +++ b/bumblebee/util.py @@ -23,7 +23,7 @@ def bytefmt(num): if num < 1024.0: return "{:.2f}{}B".format(num, unit) num /= 1024.0 - return "{:05.2f%}{}GiB".format(num) + return "{:.2f}GiB".format(num*1024.0) def durationfmt(duration): minutes, seconds = divmod(duration, 60) diff --git a/tests/test_util.py b/tests/test_util.py new file mode 100644 index 0000000..b9b04c4 --- /dev/null +++ b/tests/test_util.py @@ -0,0 +1,25 @@ +# pylint: disable=C0103,C0111 + +import unittest + +from bumblebee.util import * + +class TestUtil(unittest.TestCase): + def test_bytefmt(self): + value = 10 + display = 10 + units = [ "B", "KiB", "MiB", "GiB" ] + for unit in units: + self.assertEquals(bytefmt(value), "{:.2f}{}".format(display, unit)) + value *= 1024 + self.assertEquals(bytefmt(value), "{:.2f}GiB".format(display*1024)) + + def test_durationfmt(self): + self.assertEquals(durationfmt(00), "00:00") + self.assertEquals(durationfmt(25), "00:25") + self.assertEquals(durationfmt(60), "01:00") + self.assertEquals(durationfmt(119), "01:59") + self.assertEquals(durationfmt(3600), "01:00:00") + self.assertEquals(durationfmt(7265), "02:01:05") + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4