1
from twisted.trial.unittest import TestCase
3
from dosage.util import saneDataSize
5
class SizeFormattingTests(TestCase):
7
Unit tests for L{saneDataSize}.
9
def check(self, size, expectedOutput):
11
Check that a particular size is formatted as expected; in particular, a
12
negative size should be formatted the same as a positive size, except
13
with a minus sign in front.
15
self.assertEqual(saneDataSize(size), expectedOutput)
16
self.assertEqual(saneDataSize(-size), '-' + expectedOutput)
18
def test_verySmallSize(self):
20
Sizes smaller than a single byte should be formatted as bytes; this
21
case is fairly pathological, so the output is somewhat nonsensical.
23
self.check(0.1, '0.100 B')
25
def test_normalSizes(self):
27
Sizes should be formatted in the largest unit for which the size will
28
not be less than a single unit.
30
self.check(1, '1.000 B')
31
self.check(2.075 * 2 ** 10, '2.075 kB')
32
self.check(5.88 * 2 ** 20, '5.880 MB')
33
self.check(13.34 * 2 ** 30, '13.340 GB')
34
self.check(445.348 * 2 ** 40, '445.348 TB')
35
self.check(34.25 * 2 ** 50, '34.250 PB')
36
self.check(3.14 * 2 ** 60, '3.140 EB')
37
self.check(57.892 * 2 ** 70, '57.892 ZB')
38
self.check(999.99 * 2 ** 80, '999.990 YB')
40
def test_veryLargeSize(self):
42
Sizes larger than 1024 yottabytes should be formatted as yottabytes.
44
self.check(5567254 * 2 ** 80, '5567254.000 YB')