Skip to content

Commit

Permalink
Fixed babel test to show that now numbers are localized
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Jan 20, 2024
1 parent 9dff7c8 commit 5187d1d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions pint/testsuite/test_babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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

0 comments on commit 5187d1d

Please sign in to comment.