Coverage for app/backend/src/tests/test_localize.py: 100%
25 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-05 15:46 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-05 15:46 +0000
1from datetime import UTC, date, datetime, time
2from zoneinfo import ZoneInfo
4import babel
6from couchers.i18n.localize import localize_date, localize_datetime, localize_time, localize_timezone
8babel_en = babel.Locale.parse("en")
9babel_es = babel.Locale.parse("es")
10babel_fr = babel.Locale.parse("fr")
11babel_zh = babel.Locale.parse("zh")
14def test_localize_date() -> None:
15 assert localize_date(date(2000, 1, 2), babel_en) == "January 2, 2000"
16 assert localize_date(date(2000, 1, 2), babel_es, abbrev=True) == "2 ene 2000"
17 assert localize_date(date(2000, 1, 2), babel_fr, with_day_of_week=True) == "dimanche 2 janvier 2000"
18 assert localize_date(date(2000, 1, 2), babel_zh, with_year=False) == "1月2日"
19 assert localize_date(date(2000, 1, 2), babel_en, with_year=False, with_day_of_week=True) == "Sunday, January 2"
22def test_localize_time() -> None:
23 assert localize_time(time(14, 5), babel_en) == "2:05 PM"
24 assert localize_time(time(14, 5), babel_fr) == "14:05"
25 assert localize_time(time(14, 5), babel_es, with_seconds=True) == "14:05:00"
28def test_localize_datetime() -> None:
29 value = datetime(2000, 1, 2, 14, 5, tzinfo=UTC)
30 assert localize_datetime(value, babel_en) == "January 2, 2000, 2:05 PM"
31 assert localize_datetime(value, babel_fr) == "2 janvier 2000, 14:05"
34def test_localize_timezone() -> None:
35 assert localize_timezone(ZoneInfo("Europe/London"), babel_en) == "United Kingdom Time"
36 assert localize_timezone(ZoneInfo("Europe/London"), babel_es) == "hora de Reino Unido"