Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xueyun Qian
erp5
Commits
4bbfef1c
Commit
4bbfef1c
authored
Jun 25, 2012
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a test for new Localizer to check backward compatibility.
parent
ad388d27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
0 deletions
+105
-0
product/ERP5Type/tests/testLocalizer.py
product/ERP5Type/tests/testLocalizer.py
+105
-0
No files found.
product/ERP5Type/tests/testLocalizer.py
0 → 100644
View file @
4bbfef1c
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import
unittest
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Persistence
import
PersistentMapping
class
TestLocalizer
(
ERP5TypeTestCase
):
def
afterSetUp
(
self
):
self
.
message_catalog
=
self
.
Localizer
.
erp5_ui
if
'fr'
not
in
self
.
message_catalog
.
get_available_languages
():
self
.
message_catalog
.
add_language
(
'fr'
)
self
.
message_catalog
.
_messages
.
clear
()
def
test_non_ascii_msgid
(
self
):
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is 1€.'
,
lang
=
'fr'
),
"This is 1€."
)
# newly created key should be unicode.
self
.
assertFalse
(
'This is 1€.'
in
self
.
message_catalog
.
_messages
)
self
.
assertTrue
(
u'This is 1€.'
in
self
.
message_catalog
.
_messages
)
self
.
message_catalog
.
message_edit
(
u'This is 1€.'
,
'fr'
,
u"C'est 1€."
,
''
)
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is 1€.'
,
lang
=
'fr'
),
"C'est 1€."
)
self
.
assertFalse
(
'This is 1€.'
in
self
.
message_catalog
.
_messages
)
self
.
assertTrue
(
u'This is 1€.'
in
self
.
message_catalog
.
_messages
)
def
test_migrated_non_ascii_msgid
(
self
):
# register str key to simulate existing message that was already
# created by old Localizer.
self
.
message_catalog
.
_messages
[
'This is 1€.'
]
=
PersistentMapping
(
{
'fr'
:
"C'est 1€."
,
'note'
:
''
,})
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is 1€.'
,
lang
=
'fr'
),
"C'est 1€."
)
# translate() should not create a unicode key if str key already exists.
self
.
assertTrue
(
'This is 1€.'
in
self
.
message_catalog
.
_messages
)
self
.
assertFalse
(
u'This is 1€.'
in
self
.
message_catalog
.
_messages
)
self
.
message_catalog
.
message_edit
(
u'This is 1€.'
,
'fr'
,
u"Ceci est 1€."
,
''
)
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is 1€.'
,
lang
=
'fr'
),
"Ceci est 1€."
)
# message_edit() should not create a unicode key if str key already exists.
self
.
assertTrue
(
'This is 1€.'
in
self
.
message_catalog
.
_messages
)
self
.
assertFalse
(
u'This is 1€.'
in
self
.
message_catalog
.
_messages
)
def
test_non_ascii_mapping
(
self
):
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is 1${currency}.'
,
lang
=
'fr'
,
mapping
=
{
'currency'
:
'€'
}),
"This is 1€."
)
self
.
message_catalog
.
message_edit
(
u'This is 1${currency}.'
,
'fr'
,
u"C'est 1${currency}."
,
''
)
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is 1${currency}.'
,
lang
=
'fr'
,
mapping
=
{
'currency'
:
'€'
}),
"C'est 1€."
)
def
test_non_literal_mapping
(
self
):
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is ${obj}.'
,
lang
=
'fr'
,
mapping
=
{
'obj'
:[
1
,
2
]}),
"This is [1, 2]."
)
self
.
message_catalog
.
message_edit
(
u'This is ${obj}.'
,
'fr'
,
u"C'est ${obj}."
,
''
)
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is ${obj}.'
,
lang
=
'fr'
,
mapping
=
{
'obj'
:[
1
,
2
]}),
"C'est [1, 2]."
)
def
test_import_migrated_non_ascii_msgid
(
self
):
# register str key to simulate existing message that was already
# created by old Localizer.
self
.
message_catalog
.
_messages
[
'This is 1€.'
]
=
PersistentMapping
(
{
'fr'
:
"C'est 1€."
,
'note'
:
''
,})
self
.
message_catalog
.
po_import
(
'fr'
,
'msgid "This is 1€."
\
n
msgstr "Ceci est 1€."'
)
self
.
assertEqual
(
self
.
portal
.
Base_translateString
(
'This is 1€.'
,
lang
=
'fr'
),
"Ceci est 1€."
)
# po_import() converts existing str key to unicode key.
self
.
assertFalse
(
'This is 1€.'
in
self
.
message_catalog
.
_messages
)
self
.
assertTrue
(
u'This is 1€.'
in
self
.
message_catalog
.
_messages
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestLocalizer
))
return
suite
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment