Skip to content
Snippets Groups Projects
Commit b7015f320d56 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:ambulance: Fix tests when installing various languages in the test database

parent fe6cbb34aa29
No related branches found
No related tags found
1 merge request!10🚑 Fix tests when installing various languages in the test database
Pipeline #44268 passed
Changelog
=========
15.0.1.0.1
----------
Fix tests when installing various languages in the test database.
15.0.1.0.0
----------
......
......@@ -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/",
......
......@@ -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:
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment