diff options
author | Aarni Koskela <akx@iki.fi> | 2022-01-28 13:28:03 +0200 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2022-04-08 13:38:18 +0300 |
commit | d2b953b3288f289b84335437d947af53ebf35fec (patch) | |
tree | 67e58e6193ee7519a408289230b3eb4527a8d965 /tests | |
parent | 9cd0ed93ad5e69432f1fda11285b04f09d3b8e94 (diff) | |
download | babel-d2b953b3288f289b84335437d947af53ebf35fec.tar.gz |
Make test_smoke more thorough
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_smoke.py | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/tests/test_smoke.py b/tests/test_smoke.py index f5319f2..052c1cb 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -6,32 +6,51 @@ operations don't fail due to odd corner cases on any locale that we ship. """ import decimal -from datetime import datetime - +import datetime import pytest -from babel import Locale -from babel import dates -from babel import numbers + +from babel import Locale, units, dates, numbers + +NUMBERS = ( + decimal.Decimal("-33.76"), # Negative Decimal + decimal.Decimal("13.37"), # Positive Decimal + 1.2 - 1.0, # Inaccurate float + 10, # Plain old integer + 0, # Zero +) @pytest.mark.all_locales def test_smoke_dates(locale): locale = Locale.parse(locale) - instant = datetime.now() + instant = datetime.datetime.now() for width in ("full", "long", "medium", "short"): assert dates.format_date(instant, format=width, locale=locale) assert dates.format_datetime(instant, format=width, locale=locale) assert dates.format_time(instant, format=width, locale=locale) + # Interval test + past = instant - datetime.timedelta(hours=23) + assert dates.format_interval(past, instant, locale=locale) + # Duration test - at the time of writing, all locales seem to have `short` width, + # so let's test that. + duration = instant - instant.replace(hour=0, minute=0, second=0) + for granularity in ('second', 'minute', 'hour', 'day'): + assert dates.format_timedelta(duration, granularity=granularity, format="short", locale=locale) @pytest.mark.all_locales def test_smoke_numbers(locale): locale = Locale.parse(locale) - for number in ( - decimal.Decimal("-33.76"), # Negative Decimal - decimal.Decimal("13.37"), # Positive Decimal - 1.2 - 1.0, # Inaccurate float - 10, # Plain old integer - 0, # Zero - ): + for number in NUMBERS: assert numbers.format_decimal(number, locale=locale) + assert numbers.format_currency(number, "EUR", locale=locale) + assert numbers.format_scientific(number, locale=locale) + assert numbers.format_percent(number / 100, locale=locale) + + +@pytest.mark.all_locales +def test_smoke_units(locale): + locale = Locale.parse(locale) + for unit in ('length-meter', 'mass-kilogram', 'energy-calorie', 'volume-liter'): + for number in NUMBERS: + assert units.format_unit(number, measurement_unit=unit, locale=locale) |