Issues (53)

tests/test_backup_compress.py (2 issues)

Severity
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
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...
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