1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
__author__ = "John Hollowell"
__copyright__ = "(c) John Hollowell 2022"
__license__ = "MIT"
import tempfile
from proxmoxer.backends import https
class TestGetFileSize:
"""
Tests for the get_file_size() function within proxmoxer.backends.https
"""
def test_empty(self):
with tempfile.TemporaryFile("w+b") as f_obj:
assert https.get_file_size(f_obj) == 0
def test_small(self):
size = 100
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
assert https.get_file_size(f_obj) == size
def test_large(self):
size = 10 * 1024 * 1024 # 10 MB
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
assert https.get_file_size(f_obj) == size
def test_half_seek(self):
size = 200
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
f_obj.seek(int(size / 2))
assert https.get_file_size(f_obj) == size
def test_full_seek(self):
size = 200
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
f_obj.seek(size)
assert https.get_file_size(f_obj) == size
class TestGetFileSizePartial:
"""
Tests for the get_file_size_partial() function within proxmoxer.backends.https
"""
def test_empty(self):
with tempfile.TemporaryFile("w+b") as f_obj:
assert https.get_file_size_partial(f_obj) == 0
def test_small(self):
size = 100
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
f_obj.seek(0)
assert https.get_file_size_partial(f_obj) == size
def test_large(self):
size = 10 * 1024 * 1024 # 10 MB
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
f_obj.seek(0)
assert https.get_file_size_partial(f_obj) == size
def test_half_seek(self):
size = 200
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
f_obj.seek(int(size / 2))
assert https.get_file_size_partial(f_obj) == size / 2
def test_full_seek(self):
size = 200
with tempfile.TemporaryFile("w+b") as f_obj:
f_obj.write(b"a" * size)
f_obj.seek(size)
assert https.get_file_size_partial(f_obj) == 0
|