From 5187d1d3d2b4b24a426bec765a1b525414b9cb02 Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Sat, 20 Jan 2024 02:26:19 -0300 Subject: [PATCH] Fixed babel test to show that now numbers are localized --- pint/testsuite/test_babel.py | 39 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/pint/testsuite/test_babel.py b/pint/testsuite/test_babel.py index 3bb88db9d..d4e2194d7 100644 --- a/pint/testsuite/test_babel.py +++ b/pint/testsuite/test_babel.py @@ -20,15 +20,15 @@ def test_format(func_registry): dirname = os.path.dirname(__file__) ureg.load_definitions(os.path.join(dirname, "../xtranslated.txt")) - distance = 24.0 * ureg.meter - assert distance.format_babel(locale="fr_FR", length="long") == "24.0 mètres" - time = 8.0 * ureg.second - assert time.format_babel(locale="fr_FR", length="long") == "8.0 secondes" - assert time.format_babel(locale="ro_RO", length="short") == "8.0 s" + distance = 24.1 * ureg.meter + assert distance.format_babel(locale="fr_FR", length="long") == "24,1 mètres" + time = 8.1 * ureg.second + assert time.format_babel(locale="fr_FR", length="long") == "8,1 secondes" + assert time.format_babel(locale="ro_RO", length="short") == "8,1 s" acceleration = distance / time**2 assert ( - acceleration.format_babel(spec="P", locale="fr_FR", length="long") - == "0.375 mètre/seconde²" + acceleration.format_babel(spec=".3nP", locale="fr_FR", length="long") + == "0,367 mètre/seconde²" ) mks = ureg.get_system("mks") assert mks.format_babel(locale="fr_FR") == "métrique" @@ -40,16 +40,19 @@ def test_registry_locale(): dirname = os.path.dirname(__file__) ureg.load_definitions(os.path.join(dirname, "../xtranslated.txt")) - distance = 24.0 * ureg.meter - assert distance.format_babel(length="long") == "24.0 mètres" - time = 8.0 * ureg.second - assert time.format_babel(length="long") == "8.0 secondes" - assert time.format_babel(locale="ro_RO", length="short") == "8.0 s" + distance = 24.1 * ureg.meter + assert distance.format_babel(length="long") == "24,1 mètres" + time = 8.1 * ureg.second + assert time.format_babel(length="long") == "8,1 secondes" + assert time.format_babel(locale="ro_RO", length="short") == "8,1 s" acceleration = distance / time**2 assert ( - acceleration.format_babel(spec="C", length="long") == "0.375 mètre/seconde**2" + acceleration.format_babel(spec=".3nC", length="long") + == "0,367 mètre/seconde**2" + ) + assert ( + acceleration.format_babel(spec=".3nP", length="long") == "0,367 mètre/seconde²" ) - assert acceleration.format_babel(spec="P", length="long") == "0.375 mètre/seconde²" mks = ureg.get_system("mks") assert mks.format_babel(locale="fr_FR") == "métrique" @@ -82,21 +85,21 @@ def test_no_registry_locale(func_registry): @helpers.requires_babel() def test_str(func_registry): ureg = func_registry - d = 24.0 * ureg.meter + d = 24.1 * ureg.meter - s = "24.0 meter" + s = "24.1 meter" assert str(d) == s assert "%s" % d == s assert f"{d}" == s ureg.set_fmt_locale("fr_FR") - s = "24.0 mètres" + s = "24,1 mètres" assert str(d) == s assert "%s" % d == s assert f"{d}" == s ureg.set_fmt_locale(None) - s = "24.0 meter" + s = "24.1 meter" assert str(d) == s assert "%s" % d == s assert f"{d}" == s