5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
1 |
# Copyright (C) 2011 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Tests for bzrlib.i18n"""
|
|
18 |
||
19 |
from bzrlib import i18n, tests |
|
20 |
||
21 |
||
5875.2.9
by Vincent Ladeuil
Cleanup some PEP8 issues and move test code in test module, test_multiline still failing. |
22 |
class ZzzTranslations(object): |
23 |
"""Special Zzz translation for debugging i18n stuff.
|
|
24 |
||
25 |
This class can be used to confirm that the message is properly translated
|
|
26 |
during black box tests.
|
|
27 |
"""
|
|
28 |
_null_translation = i18n._gettext.NullTranslations() |
|
29 |
||
30 |
def zzz(self, s): |
|
31 |
return u'zz{{%s}}' % s |
|
32 |
||
33 |
def ugettext(self, s): |
|
34 |
return self.zzz(self._null_translation.ugettext(s)) |
|
35 |
||
36 |
def ungettext(self, s, p, n): |
|
37 |
return self.zzz(self._null_translation.ungettext(s, p, n)) |
|
38 |
||
39 |
||
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
40 |
class TestZzzTranslation(tests.TestCase): |
41 |
||
42 |
def _check_exact(self, expected, source): |
|
43 |
self.assertEqual(expected, source) |
|
44 |
self.assertEqual(type(expected), type(source)) |
|
45 |
||
46 |
def test_translation(self): |
|
5875.2.9
by Vincent Ladeuil
Cleanup some PEP8 issues and move test code in test module, test_multiline still failing. |
47 |
trans = ZzzTranslations() |
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
48 |
|
49 |
t = trans.zzz('msg') |
|
50 |
self._check_exact(u'zz{{msg}}', t) |
|
51 |
||
52 |
t = trans.ugettext('msg') |
|
53 |
self._check_exact(u'zz{{msg}}', t) |
|
54 |
||
55 |
t = trans.ungettext('msg1', 'msg2', 0) |
|
56 |
self._check_exact(u'zz{{msg2}}', t) |
|
57 |
t = trans.ungettext('msg1', 'msg2', 2) |
|
58 |
self._check_exact(u'zz{{msg2}}', t) |
|
59 |
||
60 |
t = trans.ungettext('msg1', 'msg2', 1) |
|
61 |
self._check_exact(u'zz{{msg1}}', t) |
|
62 |
||
63 |
||
64 |
class TestGetText(tests.TestCase): |
|
65 |
||
66 |
def setUp(self): |
|
67 |
super(TestGetText, self).setUp() |
|
5875.3.28
by Vincent Ladeuil
Fix more test failures. |
68 |
self.overrideAttr(i18n, '_translations', ZzzTranslations()) |
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
69 |
|
70 |
def test_oneline(self): |
|
71 |
self.assertEqual(u"zz{{spam ham eggs}}", |
|
72 |
i18n.gettext("spam ham eggs")) |
|
73 |
||
74 |
def test_multiline(self): |
|
5875.2.10
by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline. |
75 |
self.assertEqual(u"zz{{spam\nham\n\neggs\n}}", |
76 |
i18n.gettext("spam\nham\n\neggs\n")) |
|
77 |
||
78 |
||
79 |
class TestGetTextPerParagraph(tests.TestCase): |
|
80 |
||
81 |
def setUp(self): |
|
82 |
super(TestGetTextPerParagraph, self).setUp() |
|
5875.3.28
by Vincent Ladeuil
Fix more test failures. |
83 |
self.overrideAttr(i18n, '_translations', ZzzTranslations()) |
5875.2.10
by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline. |
84 |
|
85 |
def test_oneline(self): |
|
86 |
self.assertEqual(u"zz{{spam ham eggs}}", |
|
87 |
i18n.gettext_per_paragraph("spam ham eggs")) |
|
88 |
||
89 |
def test_multiline(self): |
|
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
90 |
self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}", |
5875.2.10
by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline. |
91 |
i18n.gettext_per_paragraph("spam\nham\n\neggs\n")) |
6025.1.1
by Jelmer Vernooij
Fix i18n use when no environment variables are set. |
92 |
|
93 |
||
94 |
class TestInstall(tests.TestCase): |
|
95 |
||
96 |
def test_custom_languages(self): |
|
97 |
self.addCleanup(i18n.install) |
|
98 |
i18n.install('nl:fy') |
|
99 |
||
100 |
def test_no_env_variables(self): |
|
101 |
self.addCleanup(i18n.install) |
|
102 |
self.overrideEnv('LANGUAGE', None) |
|
103 |
self.overrideEnv('LC_ALL', None) |
|
104 |
self.overrideEnv('LC_MESSAGES', None) |
|
105 |
self.overrideEnv('LANG', None) |
|
106 |
i18n.install() |