[tests] Add tests for bumblebee.util
Add tests for the utility functions and fix a few embarrassing bugs in the process.
This commit is contained in:
parent
672413c238
commit
846d28714a
2 changed files with 26 additions and 1 deletions
|
@ -23,7 +23,7 @@ def bytefmt(num):
|
||||||
if num < 1024.0:
|
if num < 1024.0:
|
||||||
return "{:.2f}{}B".format(num, unit)
|
return "{:.2f}{}B".format(num, unit)
|
||||||
num /= 1024.0
|
num /= 1024.0
|
||||||
return "{:05.2f%}{}GiB".format(num)
|
return "{:.2f}GiB".format(num*1024.0)
|
||||||
|
|
||||||
def durationfmt(duration):
|
def durationfmt(duration):
|
||||||
minutes, seconds = divmod(duration, 60)
|
minutes, seconds = divmod(duration, 60)
|
||||||
|
|
25
tests/test_util.py
Normal file
25
tests/test_util.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue