Skip to content

Commit

Permalink
Test naturalsize with str
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Sep 29, 2024
1 parent 33119c0 commit 32365a5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/test_filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test_args, expected",
[
([300], "300 Bytes"),
(["1000"], "1.0 kB"),
([10**3], "1.0 kB"),
([10**6], "1.0 MB"),
([10**9], "1.0 GB"),
Expand Down Expand Up @@ -74,9 +75,15 @@
([10**26 * 30, True, False, "%.3f"], "2.423 RiB"),
],
)
def test_naturalsize(test_args: list[int] | list[int | bool], expected: str) -> None:
def test_naturalsize(
test_args: list[int | str] | list[int | bool], expected: str
) -> None:
assert humanize.naturalsize(*test_args) == expected

args_with_negative = test_args
args_with_negative[0] *= -1
assert humanize.naturalsize(*args_with_negative) == "-" + expected
# Retest with negative input
if isinstance(test_args[0], int):
test_args[0] *= -1
else:
test_args[0] = f"-{test_args[0]}"

assert humanize.naturalsize(*test_args) == "-" + expected

0 comments on commit 32365a5

Please sign in to comment.