Skip to content

Commit 38d30d5

Browse files
committed
Lab2, test: add coverage for clamp errors and localized number formatting
1 parent d16e635 commit 38d30d5

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎tests/test_number.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ def test_intcomma(
8282
) -> None:
8383
assert humanize.intcomma(*test_args) == expected
8484

85+
@pytest.mark.parametrize(
86+
"thousands_sep, decimal_sep, expected",
87+
[
88+
(".", ",", "1.234.567,89"),
89+
(" ", ",", "1 234 567,89"),
90+
],
91+
)
92+
def test_intcomma_localized_separators(
93+
monkeypatch: pytest.MonkeyPatch,
94+
thousands_sep: str,
95+
decimal_sep: str,
96+
expected: str,
97+
) -> None:
98+
monkeypatch.setattr(number, "thousands_separator", lambda: thousands_sep)
99+
monkeypatch.setattr(number, "decimal_separator", lambda: decimal_sep)
100+
101+
assert humanize.intcomma(1234567.89) == expected
85102

86103
@pytest.mark.parametrize("sign", [1, -1])
87104
def test_intcomma_large_integer(sign: int) -> None:
@@ -296,6 +313,9 @@ def test_scientific(test_args: list[typing.Any], expected: str) -> None:
296313
def test_clamp(test_args: list[typing.Any], expected: str) -> None:
297314
assert humanize.clamp(*test_args) == expected
298315

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

300320
@pytest.mark.parametrize(
301321
"test_args, expected",

0 commit comments

Comments
 (0)