bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
1 |
# Copyright (C) 2011, 2016 Canonical Ltd
|
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
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 |
||
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
17 |
"""Tests for breezy.i18n"""
|
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
18 |
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
19 |
import io |
20 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
21 |
from .. import ( |
6189.1.1
by Jelmer Vernooij
Add a load_plugin_translations method. |
22 |
i18n, |
23 |
tests, |
|
24 |
errors, |
|
25 |
workingtree, |
|
26 |
)
|
|
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
27 |
|
28 |
||
5875.2.9
by Vincent Ladeuil
Cleanup some PEP8 issues and move test code in test module, test_multiline still failing. |
29 |
class ZzzTranslations(object): |
30 |
"""Special Zzz translation for debugging i18n stuff. |
|
31 |
||
32 |
This class can be used to confirm that the message is properly translated
|
|
33 |
during black box tests.
|
|
34 |
"""
|
|
35 |
_null_translation = i18n._gettext.NullTranslations() |
|
36 |
||
37 |
def zzz(self, s): |
|
6112.5.12
by Jonathan Riddell
use non-ascii in error i18n tests to make it more realistic |
38 |
return u'zz\xe5{{%s}}' % s |
5875.2.9
by Vincent Ladeuil
Cleanup some PEP8 issues and move test code in test module, test_multiline still failing. |
39 |
|
7045.5.4
by Jelmer Vernooij
Fix a few more tests. |
40 |
def gettext(self, s): |
41 |
return self.zzz(self._null_translation.gettext(s)) |
|
42 |
||
7058.4.10
by Jelmer Vernooij
Fix i18n stuff. |
43 |
def ngettext(self, s, p, n): |
44 |
return self.zzz(self._null_translation.ngettext(s, p, n)) |
|
45 |
||
5875.2.9
by Vincent Ladeuil
Cleanup some PEP8 issues and move test code in test module, test_multiline still failing. |
46 |
def ugettext(self, s): |
47 |
return self.zzz(self._null_translation.ugettext(s)) |
|
48 |
||
49 |
def ungettext(self, s, p, n): |
|
50 |
return self.zzz(self._null_translation.ungettext(s, p, n)) |
|
51 |
||
52 |
||
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
53 |
class TestZzzTranslation(tests.TestCase): |
54 |
||
55 |
def _check_exact(self, expected, source): |
|
56 |
self.assertEqual(expected, source) |
|
57 |
self.assertEqual(type(expected), type(source)) |
|
58 |
||
59 |
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. |
60 |
trans = ZzzTranslations() |
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
61 |
|
62 |
t = trans.zzz('msg') |
|
6112.5.12
by Jonathan Riddell
use non-ascii in error i18n tests to make it more realistic |
63 |
self._check_exact(u'zz\xe5{{msg}}', t) |
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
64 |
|
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
65 |
t = trans.gettext('msg') |
66 |
self._check_exact(u'zz\xe5{{msg}}', t) |
|
67 |
||
68 |
t = trans.ngettext('msg1', 'msg2', 0) |
|
69 |
self._check_exact(u'zz\xe5{{msg2}}', t) |
|
70 |
t = trans.ngettext('msg1', 'msg2', 2) |
|
71 |
self._check_exact(u'zz\xe5{{msg2}}', t) |
|
72 |
||
73 |
t = trans.ngettext('msg1', 'msg2', 1) |
|
74 |
self._check_exact(u'zz\xe5{{msg1}}', t) |
|
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
75 |
|
76 |
||
77 |
class TestGetText(tests.TestCase): |
|
78 |
||
79 |
def setUp(self): |
|
80 |
super(TestGetText, self).setUp() |
|
5875.3.28
by Vincent Ladeuil
Fix more test failures. |
81 |
self.overrideAttr(i18n, '_translations', ZzzTranslations()) |
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
82 |
|
83 |
def test_oneline(self): |
|
6112.5.12
by Jonathan Riddell
use non-ascii in error i18n tests to make it more realistic |
84 |
self.assertEqual(u"zz\xe5{{spam ham eggs}}", |
5875.2.2
by INADA Naoki
Add tests for bzrlib.i18n |
85 |
i18n.gettext("spam ham eggs")) |
86 |
||
87 |
def test_multiline(self): |
|
6112.5.12
by Jonathan Riddell
use non-ascii in error i18n tests to make it more realistic |
88 |
self.assertEqual(u"zz\xe5{{spam\nham\n\neggs\n}}", |
5875.2.10
by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline. |
89 |
i18n.gettext("spam\nham\n\neggs\n")) |
90 |
||
91 |
||
92 |
class TestGetTextPerParagraph(tests.TestCase): |
|
93 |
||
94 |
def setUp(self): |
|
95 |
super(TestGetTextPerParagraph, self).setUp() |
|
5875.3.28
by Vincent Ladeuil
Fix more test failures. |
96 |
self.overrideAttr(i18n, '_translations', ZzzTranslations()) |
5875.2.10
by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline. |
97 |
|
98 |
def test_oneline(self): |
|
6112.5.12
by Jonathan Riddell
use non-ascii in error i18n tests to make it more realistic |
99 |
self.assertEqual(u"zz\xe5{{spam ham eggs}}", |
5875.2.10
by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline. |
100 |
i18n.gettext_per_paragraph("spam ham eggs")) |
101 |
||
102 |
def test_multiline(self): |
|
6112.5.12
by Jonathan Riddell
use non-ascii in error i18n tests to make it more realistic |
103 |
self.assertEqual(u"zz\xe5{{spam\nham}}\n\nzz\xe5{{eggs\n}}", |
5875.2.10
by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline. |
104 |
i18n.gettext_per_paragraph("spam\nham\n\neggs\n")) |
6025.1.1
by Jelmer Vernooij
Fix i18n use when no environment variables are set. |
105 |
|
106 |
||
107 |
class TestInstall(tests.TestCase): |
|
108 |
||
6133.3.11
by Jonathan Riddell
make TestInstall tests more consistent |
109 |
def setUp(self): |
110 |
super(TestInstall, self).setUp() |
|
111 |
# Restore a proper env to test translation installation
|
|
112 |
self.overrideAttr(i18n, '_translations', None) |
|
113 |
||
6025.1.1
by Jelmer Vernooij
Fix i18n use when no environment variables are set. |
114 |
def test_custom_languages(self): |
115 |
i18n.install('nl:fy') |
|
6133.3.13
by Jonathan Riddell
vila sorts it out, fix disable_i18n() and use it in tests.__init__ |
116 |
# Whether we found a valid tranlsation or not doesn't matter, we got
|
117 |
# one and _translations is not None anymore.
|
|
118 |
self.assertIsInstance(i18n._translations, |
|
119 |
i18n._gettext.NullTranslations) |
|
6025.1.1
by Jelmer Vernooij
Fix i18n use when no environment variables are set. |
120 |
|
121 |
def test_no_env_variables(self): |
|
122 |
self.overrideEnv('LANGUAGE', None) |
|
123 |
self.overrideEnv('LC_ALL', None) |
|
124 |
self.overrideEnv('LC_MESSAGES', None) |
|
125 |
self.overrideEnv('LANG', None) |
|
126 |
i18n.install() |
|
6133.3.13
by Jonathan Riddell
vila sorts it out, fix disable_i18n() and use it in tests.__init__ |
127 |
# Whether we found a valid tranlsation or not doesn't matter, we got
|
128 |
# one and _translations is not None anymore.
|
|
129 |
self.assertIsInstance(i18n._translations, |
|
130 |
i18n._gettext.NullTranslations) |
|
6112.5.3
by Jonathan Riddell
start a test case |
131 |
|
6131.2.4
by Jonathan Riddell
add test for i18n.disable_i18n() |
132 |
def test_disable_i18n(self): |
133 |
i18n.disable_i18n() |
|
134 |
i18n.install() |
|
6133.3.13
by Jonathan Riddell
vila sorts it out, fix disable_i18n() and use it in tests.__init__ |
135 |
# It's disabled, you can't install anything and we fallback to null
|
136 |
self.assertIsInstance(i18n._translations, |
|
137 |
i18n._gettext.NullTranslations) |
|
6133.3.10
by Jonathan Riddell
default _translations back to None so we can tell if it gets installed |
138 |
|
6131.2.4
by Jonathan Riddell
add test for i18n.disable_i18n() |
139 |
|
6112.5.3
by Jonathan Riddell
start a test case |
140 |
class TestTranslate(tests.TestCaseWithTransport): |
141 |
||
142 |
def setUp(self): |
|
143 |
super(TestTranslate, self).setUp() |
|
144 |
self.overrideAttr(i18n, '_translations', ZzzTranslations()) |
|
145 |
||
146 |
def test_error_message_translation(self): |
|
6112.5.5
by Jonathan Riddell
finish test_error_message_translation() |
147 |
"""do errors get translated?""" |
6112.5.3
by Jonathan Riddell
start a test case |
148 |
err = None |
149 |
tree = self.make_branch_and_tree('.') |
|
150 |
try: |
|
151 |
workingtree.WorkingTree.open('./foo') |
|
6619.3.2
by Jelmer Vernooij
Apply 2to3 except fix. |
152 |
except errors.NotBranchError as e: |
6112.5.3
by Jonathan Riddell
start a test case |
153 |
err = str(e) |
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
154 |
self.assertContainsRe(err, u"zz\xe5{{Not a branch: .*}}") |
6110.7.7
by Jonathan Riddell
add a test for topic help translations |
155 |
|
156 |
def test_topic_help_translation(self): |
|
157 |
"""does topic help get translated?""" |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
158 |
from .. import help |
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
159 |
out = io.StringIO() |
6110.7.7
by Jonathan Riddell
add a test for topic help translations |
160 |
help.help("authentication", out) |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
161 |
self.assertContainsRe( |
162 |
out.getvalue(), "zz\xe5{{Authentication Settings") |
|
6189.1.1
by Jelmer Vernooij
Add a load_plugin_translations method. |
163 |
|
164 |
||
165 |
class LoadPluginTranslations(tests.TestCase): |
|
166 |
||
167 |
def test_does_not_exist(self): |
|
168 |
translation = i18n.load_plugin_translations("doesnotexist") |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
169 |
self.assertEqual("foo", translation.gettext("foo")) |