diff --git a/tests/test_i18n.py b/tests/test_i18n.py index 0d3ced84..37c88c51 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -470,3 +470,24 @@ def test_intword_unit_has_no_format_placeholder(locale: str) -> None: pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh") finally: humanize.i18n.deactivate() + + +def test_activate_populates_translation_cache(monkeypatch: pytest.MonkeyPatch) -> None: + """activate() caches translation on first call (cache-miss branch).""" + import gettext + + fake = gettext.NullTranslations() + monkeypatch.setattr( + humanize.i18n.gettext_module, + "translation", + lambda *args, **kwargs: fake, + ) + humanize.i18n._TRANSLATIONS.pop("de_DE", None) + try: + result = humanize.i18n.activate("de_DE") + assert result is fake + assert humanize.i18n._TRANSLATIONS["de_DE"] is fake + assert humanize.i18n._CURRENT.locale == "de_DE" + finally: + humanize.i18n._TRANSLATIONS.pop("de_DE", None) + humanize.i18n.deactivate() diff --git a/tests/test_number.py b/tests/test_number.py index 5fb12fa6..96c7e64c 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -377,3 +377,25 @@ def test_clamp(test_args: list[typing.Any], expected: str) -> None: ) def test_metric(test_args: list[typing.Any], expected: str) -> None: assert humanize.metric(*test_args) == expected + + +def test_format_not_finite_returns_empty_for_finite() -> None: + """_format_not_finite falls back to empty string for finite values.""" + assert number._format_not_finite(42.0) == "" + assert number._format_not_finite(0) == "" + assert number._format_not_finite(-1.5) == "" + + +def test_intcomma_with_custom_separators(monkeypatch: pytest.MonkeyPatch) -> None: + """intcomma uses thousands_separator/decimal_separator helpers.""" + monkeypatch.setattr(number, "thousands_separator", lambda: ".") + monkeypatch.setattr(number, "decimal_separator", lambda: ",") + assert humanize.intcomma(1234) == "1.234" + assert humanize.intcomma(1234.5, ndigits=2) == "1.234,50" + assert humanize.intcomma("14308,40", ndigits=1) == "14.308,4" + + +def test_clamp_invalid_format_raises() -> None: + """clamp raises ValueError for non-string, non-callable format.""" + with pytest.raises(ValueError, match="Invalid format"): + humanize.clamp(42, format=123) # type: ignore[arg-type]