Skip to content

Commit

Permalink
refactor: improve compactness (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Aug 6, 2023
2 parents aa46f65 + 1895740 commit d742498
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions sepal_ui/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@ def get_file_size(filename: Union[str, Path]) -> str:
"""
file_size = Path(filename).stat().st_size

if file_size == 0:
return "0B"

size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")

i = int(math.floor(math.log(file_size, 1024)))
i = int(math.floor(math.log(file_size, 1024))) if file_size > 0 else 0
s = file_size / (1024**i)

return "{:.1f} {}".format(s, size_name[i])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scripts/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_get_file_size() -> None:
stat.return_value.st_size = 0

txt = su.get_file_size("random")
assert txt == "0B"
assert txt == "0.0 B"

# mock every pow of 1024 to YB
for i in range(9):
Expand Down

0 comments on commit d742498

Please sign in to comment.