Skip to content
Closed
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
24 changes: 24 additions & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ def test_intcomma(
assert humanize.intcomma(*test_args) == expected


@pytest.mark.parametrize(
"thousands_sep, decimal_sep, expected",
[
(".", ",", "1.234.567,89"),
(" ", ",", "1 234 567,89"),
],
)
def test_intcomma_localized_separators(
monkeypatch: pytest.MonkeyPatch,
thousands_sep: str,
decimal_sep: str,
expected: str,
) -> None:
monkeypatch.setattr(number, "thousands_separator", lambda: thousands_sep)
monkeypatch.setattr(number, "decimal_separator", lambda: decimal_sep)

assert humanize.intcomma(1234567.89) == expected


@pytest.mark.parametrize("sign", [1, -1])
def test_intcomma_large_integer(sign: int) -> None:
value = sign * (10**400 + 123)
Expand Down Expand Up @@ -297,6 +316,11 @@ def test_clamp(test_args: list[typing.Any], expected: str) -> None:
assert humanize.clamp(*test_args) == expected


def test_clamp_invalid_format() -> None:
with pytest.raises(ValueError, match="Invalid format"):
humanize.clamp(10, format=123)


@pytest.mark.parametrize(
"test_args, expected",
[
Expand Down