Skip to content

Commit 6218be2

Browse files
committed
Add unit tests for filesize.py
1 parent 4545913 commit 6218be2

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

cloudbot/util/filesize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
are listed in the accompanying credits file.
5353
"""
5454

55+
5556
traditional = [
5657
(1024 ** 5, 'P'),
5758
(1024 ** 4, 'T'),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from cloudbot.util.filesize import size, si, verbose
2+
3+
4+
def test_size():
5+
# Using the traditional system, where a factor of 1024 is used
6+
assert size(10) == "10B"
7+
assert size(100) == "100B"
8+
assert size(1000) == "1000B"
9+
assert size(2000) == "1K"
10+
assert size(10000) == "9K"
11+
assert size(20000) == "19K"
12+
assert size(100000) == "97K"
13+
assert size(200000) == "195K"
14+
assert size(1000000) == "976K"
15+
assert size(2000000) == "1M"
16+
17+
18+
def test_size_verbose():
19+
# Using the verbose system, where a factor of 1024 is used
20+
assert size(1, system=verbose) == "1 byte"
21+
assert size(1000, system=verbose) == "1000 bytes"
22+
assert size(2000, system=verbose) == "1 kilobyte"
23+
assert size(10000, system=verbose) == "9 kilobytes"
24+
assert size(2000000, system=verbose) == "1 megabyte"
25+
assert size(30000000, system=verbose) == "28 megabytes"
26+
27+
28+
def test_size_si():
29+
# Using the SI system, with a factor of 1000
30+
assert size(10, system=si) == "10B"
31+
assert size(100, system=si) == "100B"
32+
assert size(1000, system=si) == "1K"
33+
assert size(2000, system=si) == "2K"
34+
assert size(10000, system=si) == "10K"
35+
assert size(20000, system=si) == "20K"
36+
assert size(100000, system=si) == "100K"
37+
assert size(200000, system=si) == "200K"
38+
assert size(1000000, system=si) == "1M"
39+
assert size(2000000, system=si) == "2M"
40+

0 commit comments

Comments
 (0)