3
|
1 |
#!/usr/bin/env python3
|
|
2 |
|
|
3 |
from pycolib import prettysize
|
|
4 |
|
|
5 |
import unittest
|
|
6 |
|
|
7 |
|
|
8 |
class TestPrettySize(unittest.TestCase):
|
|
9 |
|
|
10 |
def test_prettysize(self):
|
|
11 |
psize = prettysize.prettysize_short
|
|
12 |
expected = (
|
|
13 |
(0, '0'),
|
|
14 |
(1000, '1000'),
|
|
15 |
(1024, '1K'),
|
|
16 |
(1050, '1.03K'),
|
|
17 |
(2050, '2K'),
|
|
18 |
(333333, '325.52K'),
|
|
19 |
(1048576, '1M'),
|
|
20 |
(1050000, '1M'),
|
|
21 |
(5555555, '5.3M'),
|
|
22 |
(1073741824, '1G'),
|
|
23 |
)
|
|
24 |
for value, result in expected:
|
|
25 |
self.assertEqual(psize(value), result)
|
|
26 |
|
|
27 |
|
|
28 |
if __name__ == '__main__':
|
|
29 |
unittest.main()
|