From 38d30d54934f4ae2fa5775ae1c18a5292a9b4a48 Mon Sep 17 00:00:00 2001 From: Neuralman159 Date: Wed, 11 Nov 2026 20:28:34 +0300 Subject: [PATCH 1/2] Lab2, test: add coverage for clamp errors and localized number formatting --- tests/test_number.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_number.py b/tests/test_number.py index 5fb12fa6..d7f63f81 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -82,6 +82,23 @@ def test_intcomma( ) -> None: 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: @@ -296,6 +313,9 @@ def test_scientific(test_args: list[typing.Any], expected: str) -> None: 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", From 30440778301e3b8f965dfc35e0f392a095ca45da Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:45:53 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_number.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_number.py b/tests/test_number.py index d7f63f81..4db0134d 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -82,6 +82,7 @@ def test_intcomma( ) -> None: assert humanize.intcomma(*test_args) == expected + @pytest.mark.parametrize( "thousands_sep, decimal_sep, expected", [ @@ -100,6 +101,7 @@ def test_intcomma_localized_separators( 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) @@ -313,10 +315,12 @@ def test_scientific(test_args: list[typing.Any], expected: str) -> None: 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", [