Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fsutil/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def convert_size_bytes_to_string(size: int) -> str:
units = SIZE_UNITS
factor = 0
factor_limit = len(units) - 1
while (size_num >= 1024) and (factor <= factor_limit):
while (size_num >= 1024) and (factor < factor_limit):
size_num /= 1024
factor += 1
size_units = units[factor]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
(1073741824, "1.00 GB"),
(1879048192, "1.75 GB"),
(1099511627776, "1.00 TB"),
(2**80, "1.00 YB"),
(2**90, "1024.00 YB"),
(2**100, "1048576.00 YB"),
],
)
def test_convert_size_bytes_to_string(size_bytes, expected_output):
Expand Down Expand Up @@ -51,6 +54,9 @@ def test_convert_size_bytes_to_string_and_convert_size_string_to_bytes(
("1.00 MB", 1048576),
("1.00 GB", 1073741824),
("1.00 TB", 1099511627776),
("1.00 YB", 2**80),
("1024.00 YB", 2**90),
("1048576.00 YB", 2**100),
],
)
def test_convert_size_string_to_bytes(size_string, expected_output):
Expand All @@ -69,6 +75,9 @@ def test_convert_size_string_to_bytes(size_string, expected_output):
(1170378588, 1170378588),
(2136746229, 2136746229),
(1099511627776, 1099511627776),
(2**80, 2**80),
(2**90, 2**90),
(2**100, 2**100),
],
)
def test_convert_size_string_to_bytes_and_convert_size_bytes_to_string(
Expand Down
Loading