mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-01-28 21:30:43 +00:00
Fix: it is impossible to have 0.1 byte as byte is the smallest unit
This commit is contained in:
@@ -85,8 +85,8 @@ def bytes_to_readable(size_bytes: int) -> str:
|
||||
Returns:
|
||||
A human-readable string representing the file size.
|
||||
"""
|
||||
if size_bytes == 0:
|
||||
return "0B"
|
||||
if size_bytes < 1024:
|
||||
return f"{size_bytes} B"
|
||||
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
|
||||
i = int(math.floor(math.log(size_bytes, 1024)))
|
||||
p = math.pow(1024, i)
|
||||
|
||||
@@ -23,8 +23,8 @@ def test_convert_time_unit():
|
||||
|
||||
|
||||
class TestBytesToReadable:
|
||||
assert bytes_to_readable(0) == "0B"
|
||||
assert bytes_to_readable(500) == "500.0 B"
|
||||
assert bytes_to_readable(0) == "0 B"
|
||||
assert bytes_to_readable(500) == "500 B"
|
||||
assert bytes_to_readable(1024) == "1.0 KB"
|
||||
assert bytes_to_readable(2048) == "2.0 KB"
|
||||
assert bytes_to_readable(1536) == "1.5 KB"
|
||||
@@ -40,6 +40,7 @@ class TestBytesToReadable:
|
||||
|
||||
class TestReadableToBytes:
|
||||
def test_conversion(self):
|
||||
assert readable_to_bytes("0B") == 0
|
||||
assert readable_to_bytes("100B") == 100
|
||||
assert readable_to_bytes("50 B") == 50
|
||||
assert readable_to_bytes("1KB") == 1024
|
||||
|
||||
Reference in New Issue
Block a user