tests.test_backup_compress   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

1 Function

Rating   Name   Duplication   Size   Complexity  
A humanize_bytes() 0 9 4
1
import os
2
import shutil
3
from dirutility.backup import ZipBackup
4
5
directory = 'data/games'
6
destination = os.path.join(os.path.dirname(__file__), 'data')
7
if os.path.exists(destination):
8
    shutil.rmtree(destination)
9
if not os.path.exists(destination):
10
    os.mkdir(destination)
11
12
13
def humanize_bytes(bytes, precision=2):
14
    """Return a humanized string representation of a number of bytes."""
15
    abbrevs = ((1 << 50, 'PB'), (1 << 40, 'TB'), (1 << 30, 'GB'), (1 << 20, 'MB'), (1 << 10, 'kB'), (1, 'bytes'))
16
    if bytes == 1:
17
        return '1 byte'
18
    for factor, suffix in abbrevs:
19
        if bytes >= factor:
20
            break
21
    return '%.*f %s' % (precision, bytes / factor, suffix)
0 ignored issues
show
introduced by
The variable factor does not seem to be defined in case the for loop on line 18 is not entered. Are you sure this can never be the case?
Loading history...
introduced by
The variable suffix does not seem to be defined in case the for loop on line 18 is not entered. Are you sure this can never be the case?
Loading history...
22
23
24
for i in range(0, 10):
25
    d = ZipBackup(directory, destination, compress_level=i).backup()
26
    print(humanize_bytes(os.path.getsize(str(d))), d)
27