From: Brian Warner Date: Tue, 20 May 2008 22:21:46 +0000 (-0700) Subject: test_web: improve test coverage of web.common utility code X-Git-Tag: allmydata-tahoe-1.1.0~92 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/file/URI:LIT:krugkidfnzsc4/%3C?a=commitdiff_plain;h=9c992c0d06090ea491ef25b9127a49545dcdfd4d;p=tahoe-lafs%2Ftahoe-lafs.git test_web: improve test coverage of web.common utility code --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 754b42ec..2df1cdd7 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -6,7 +6,7 @@ from twisted.internet import defer, reactor from twisted.web import client, error, http from twisted.python import failure, log from allmydata import interfaces, provisioning, uri, webish, upload, download -from allmydata.web import status +from allmydata.web import status, common from allmydata.util import fileutil from allmydata.test.common import FakeDirectoryNode, FakeCHKFileNode, \ FakeMutableFileNode, create_chk_filenode @@ -1804,3 +1804,25 @@ class Web(WebMixin, unittest.TestCase): "I don't know how to treat a DELETE request.", client.getPage, url, method="DELETE") return d + +class Util(unittest.TestCase): + def test_abbreviate_time(self): + self.failUnlessEqual(common.abbreviate_time(None), "") + self.failUnlessEqual(common.abbreviate_time(1.234), "1.23s") + self.failUnlessEqual(common.abbreviate_time(0.123), "123ms") + self.failUnlessEqual(common.abbreviate_time(0.00123), "1.2ms") + self.failUnlessEqual(common.abbreviate_time(0.000123), "123us") + + def test_abbreviate_rate(self): + self.failUnlessEqual(common.abbreviate_rate(None), "") + self.failUnlessEqual(common.abbreviate_rate(1234000), "1.23MBps") + self.failUnlessEqual(common.abbreviate_rate(12340), "12.3kBps") + self.failUnlessEqual(common.abbreviate_rate(123), "123Bps") + + def test_abbreviate_size(self): + self.failUnlessEqual(common.abbreviate_size(None), "") + self.failUnlessEqual(common.abbreviate_size(1.23*1000*1000*1000), "1.23GB") + self.failUnlessEqual(common.abbreviate_size(1.23*1000*1000), "1.23MB") + self.failUnlessEqual(common.abbreviate_size(1230), "1.2kB") + self.failUnlessEqual(common.abbreviate_size(123), "123B") +