~dosage-dev/dosage/bunch-of-comics

« back to all changes in this revision

Viewing changes to dosage/test/test_util.py

  • Committer: ns
  • Date: 2009-12-01 07:07:18 UTC
  • Revision ID: ns@ww1aviationlinks.cjb.net-20091201070718-3xoj70sz52zsq09v
Y plugin added YAFGC

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from twisted.trial.unittest import TestCase
2
 
 
3
 
from dosage.util import saneDataSize
4
 
 
5
 
class SizeFormattingTests(TestCase):
6
 
    """
7
 
    Unit tests for L{saneDataSize}.
8
 
    """
9
 
    def check(self, size, expectedOutput):
10
 
        """
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.
14
 
        """
15
 
        self.assertEqual(saneDataSize(size), expectedOutput)
16
 
        self.assertEqual(saneDataSize(-size), '-' + expectedOutput)
17
 
 
18
 
    def test_verySmallSize(self):
19
 
        """
20
 
        Sizes smaller than a single byte should be formatted as bytes; this
21
 
        case is fairly pathological, so the output is somewhat nonsensical.
22
 
        """
23
 
        self.check(0.1, '0.100 B')
24
 
 
25
 
    def test_normalSizes(self):
26
 
        """
27
 
        Sizes should be formatted in the largest unit for which the size will
28
 
        not be less than a single unit.
29
 
        """
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')
39
 
 
40
 
    def test_veryLargeSize(self):
41
 
        """
42
 
        Sizes larger than 1024 yottabytes should be formatted as yottabytes.
43
 
        """
44
 
        self.check(5567254 * 2 ** 80, '5567254.000 YB')