tests/test_prettysize.py
author Radek Brich <radek.brich@devl.cz>
Sat, 06 Apr 2013 00:07:17 +0200
changeset 3 cc27136cdead
permissions -rwxr-xr-x
Add ConfigParser and tests.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
from pycolib import prettysize
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
import unittest
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
class TestPrettySize(unittest.TestCase):
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
    def test_prettysize(self):
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
        psize = prettysize.prettysize_short
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
        expected = (
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
            (0, '0'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
            (1000, '1000'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
            (1024, '1K'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
            (1050, '1.03K'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
            (2050, '2K'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
            (333333, '325.52K'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
            (1048576, '1M'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
            (1050000, '1M'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
            (5555555, '5.3M'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
            (1073741824, '1G'),
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
            )
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
        for value, result in expected:
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
            self.assertEqual(psize(value), result)
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
if __name__ == '__main__':
cc27136cdead Add ConfigParser and tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
    unittest.main()