diff --git a/NEWS.rst b/NEWS.rst index fe6cbb34aa296df54105e5f133aa84e684e2e076_TkVXUy5yc3Q=..b7015f320d56c5fde2fc7878b35d859b1ccdcfcb_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,6 +1,11 @@ Changelog ========= +15.0.1.0.1 +---------- + +Fix tests when installing various languages in the test database. + 15.0.1.0.0 ---------- diff --git a/__manifest__.py b/__manifest__.py index fe6cbb34aa296df54105e5f133aa84e684e2e076_X19tYW5pZmVzdF9fLnB5..b7015f320d56c5fde2fc7878b35d859b1ccdcfcb_X19tYW5pZmVzdF9fLnB5 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -21,7 +21,7 @@ { "name": "ICU Format", "summary": "Format message using ICU", - "version": "15.0.1.0.0", + "version": "15.0.1.0.1", "category": "Technical", "author": "XCG Consulting", "website": "https://odoo.consulting/", diff --git a/icu_format.py b/icu_format.py index fe6cbb34aa296df54105e5f133aa84e684e2e076_aWN1X2Zvcm1hdC5weQ==..b7015f320d56c5fde2fc7878b35d859b1ccdcfcb_aWN1X2Zvcm1hdC5weQ== 100644 --- a/icu_format.py +++ b/icu_format.py @@ -19,7 +19,7 @@ ############################################################################## import datetime import logging -from typing import Dict, Mapping, Optional, Union +from typing import Callable, Dict, Mapping, Optional, ParamSpec, TypeVar, Union # Disable the warning as the library name is pyicu # pylint: disable=missing-manifest-dependency @@ -27,7 +27,12 @@ _logger = logging.getLogger(__name__) +# Disable needed as the pylint version does not contain the fix for type var from +# https://github.com/PyCQA/pylint/pull/5894 +T = TypeVar("T") # pylint: disable=invalid-name +P = ParamSpec("P") + class Cache: """Cache of factory produced object. No maximum capacity.""" @@ -30,11 +35,11 @@ class Cache: """Cache of factory produced object. No maximum capacity.""" - def __init__(self, factory): + def __init__(self, factory: Callable[P, T]): """factory to create items to cache""" self.__data = {} """Cached data""" self.__factory = factory """Factory to create items""" @@ -35,10 +40,10 @@ """factory to create items to cache""" self.__data = {} """Cached data""" self.__factory = factory """Factory to create items""" - def get(self, *args, **kwargs): + def get(self, *args: P.args, **kwargs: P.kwargs) -> T: """Return an item, eventually created with the factory""" # create a tuple out of args and kwargs key = tuple( @@ -53,7 +58,7 @@ _locale_cache = Cache(Locale) -"""A Locale cache""" +"""A icu.Locale cache""" class ICUFormatter: diff --git a/tests/test_icuformat.py b/tests/test_icuformat.py index fe6cbb34aa296df54105e5f133aa84e684e2e076_dGVzdHMvdGVzdF9pY3Vmb3JtYXQucHk=..b7015f320d56c5fde2fc7878b35d859b1ccdcfcb_dGVzdHMvdGVzdF9pY3Vmb3JtYXQucHk= 100644 --- a/tests/test_icuformat.py +++ b/tests/test_icuformat.py @@ -106,10 +106,10 @@ def test_record_icu_format_and_translate(self): user = self.env["res.users"].search([], limit=1) - # TRANSLATORS: This is a test message, no need for translation + # TRANSLATORS: This is a test message, do not translate self.assertEqual("A message", user.icu_format_translate("A message", {})) def test_list_format(self): """Test the list formatter provided on BaseModel.""" self.assertEqual(icu_list_format("fr", ["a", "b", "c"]), "a, b et c") self.assertEqual(icu_list_format("en_GB", ["1", "2", "5"]), "1, 2 and 5") @@ -110,7 +110,8 @@ self.assertEqual("A message", user.icu_format_translate("A message", {})) def test_list_format(self): """Test the list formatter provided on BaseModel.""" self.assertEqual(icu_list_format("fr", ["a", "b", "c"]), "a, b et c") self.assertEqual(icu_list_format("en_GB", ["1", "2", "5"]), "1, 2 and 5") + self.assertEqual(icu_list_format("en_US", ["1", "2", "5"]), "1, 2, and 5") user = self.env["res.users"].search([], limit=1) @@ -116,4 +117,10 @@ user = self.env["res.users"].search([], limit=1) + + # Force language on the user and activate it to avoid depending on the language + # installed in the test database. + self.env["res.lang"]._activate_lang("en_US") + self.env.user.lang = "en_US" + # Note that this uses the current user lang, not user lang self.assertEqual(user.icu_list_format(["1", "2", "5"]), "1, 2, and 5") def test_format_currency(self): @@ -154,7 +161,9 @@ ) self.assertEqual(result, "Your total is 1,25 €") + # Force no language on the user + self.env.user.lang = None # Test with handy method on currency result = self.env.ref("base.EUR").icu_format( "Your total is {total, number, currency}", dict(total=1.25) ) @@ -157,7 +166,15 @@ # Test with handy method on currency result = self.env.ref("base.EUR").icu_format( "Your total is {total, number, currency}", dict(total=1.25) ) + self.assertEqual(result, "Your total is € 1.25") + # Force language on the user and activate it to avoid depending on the language + # installed in the test database. + self.env["res.lang"]._activate_lang("en_US") + self.env.user.lang = "en_US" + result = self.env.ref("base.EUR").icu_format( + "Your total is {total, number, currency}", dict(total=1.25) + ) self.assertEqual(result, "Your total is €1.25") def test_formatter(self):