diff options
author | Sahina Bose <sabose@redhat.com> | 2014-03-19 19:25:16 +0530 |
---|---|---|
committer | Bala.FA <barumuga@redhat.com> | 2014-04-28 16:20:46 +0530 |
commit | 7750d910bb7047c0c24f2e93dd302a445b5068ec (patch) | |
tree | 21153270f087afd912f99778b3a728d30a93f65a /tests/utilsTests.py | |
parent | 576d7248699f8017f2909f548ef80df7217b57a4 (diff) |
utils: Added utils method to convert size
The method converts a value from a given
unit to another.
Example usage: convertSize (value, 'KB', 'MB)
Change-Id: If8e004076493006234be81e656eabde7d3bf9a6a
Signed-off-by: Sahina Bose <sabose@redhat.com>
Reviewed-on: https://cuckoo.blr.redhat.com:8443/32
Reviewed-by: Shubhendu Tripathi <shtripat@redhat.com>
Reviewed-by: Nishanth Thomas <nishusemail@gmail.com>
Diffstat (limited to 'tests/utilsTests.py')
-rw-r--r-- | tests/utilsTests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/utilsTests.py b/tests/utilsTests.py index 69da659..fdf1ec3 100644 --- a/tests/utilsTests.py +++ b/tests/utilsTests.py @@ -146,3 +146,21 @@ class xml2dictTests(TestCaseBase): utils.xml2dict("not an etree object") self.assertRaises(AttributeError, _xml2dict) + + +class convertsizeTests(TestCaseBase): + def testBytesToMB(self): + retVal = utils.convertSize(778999, 'B', 'MB') + assert (round(retVal, 2) == 0.74) + + def testPBtoMB(self): + retVal = utils.convertSize(8, 'PB', 'MB') + assert (round(retVal, 0) == 8589934592) + + def testInvalidInput(self): + with self.assertRaises(ValueError): + utils.convertSize(89, 'P', 'M') + + def testMBToMB(self): + retVal = utils.convertSize(900, 'MB', 'MB') + assert (retVal == 900) |