Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICU Format
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
ICU Format
Commits
b7015f320d56
Commit
b7015f320d56
authored
2 years ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
Fix tests when installing various languages in the test database
parent
fe6cbb34aa29
No related branches found
Branches containing commit
Tags
13.0.1.0.1
1 merge request
!10
🚑 Fix tests when installing various languages in the test database
Pipeline
#44268
passed
2 years ago
Changes
4
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
NEWS.rst
+5
-0
5 additions, 0 deletions
NEWS.rst
__manifest__.py
+1
-1
1 addition, 1 deletion
__manifest__.py
icu_format.py
+9
-4
9 additions, 4 deletions
icu_format.py
tests/test_icuformat.py
+18
-1
18 additions, 1 deletion
tests/test_icuformat.py
with
33 additions
and
6 deletions
NEWS.rst
+
5
−
0
View file @
b7015f32
Changelog
=========
15.0.1.0.1
----------
Fix tests when installing various languages in the test database.
15.0.1.0.0
----------
...
...
This diff is collapsed.
Click to expand it.
__manifest__.py
+
1
−
1
View file @
b7015f32
...
...
@@ -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/
"
,
...
...
This diff is collapsed.
Click to expand it.
icu_format.py
+
9
−
4
View file @
b7015f32
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_icuformat.py
+
18
−
1
View file @
b7015f32
...
...
@@ -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,
n
o n
eed for
translat
ion
# TRANSLATORS: This is a test message,
d
o n
ot
translat
e
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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment