1
# Copyright (C) 2011 Canonical Ltd
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.
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.
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
17
"""Tests for bzrlib.i18n"""
19
from bzrlib import i18n, tests
24
class ZzzTranslations(object):
25
"""Special Zzz translation for debugging i18n stuff.
27
This class can be used to confirm that the message is properly translated
28
during black box tests.
30
_null_translation = i18n._gettext.NullTranslations()
33
return u'zz{{%s}}' % s
35
def ugettext(self, s):
36
return self.zzz(self._null_translation.ugettext(s))
38
def ungettext(self, s, p, n):
39
return self.zzz(self._null_translation.ungettext(s, p, n))
42
class TestZzzTranslation(tests.TestCase):
44
def _check_exact(self, expected, source):
45
self.assertEqual(expected, source)
46
self.assertEqual(type(expected), type(source))
48
def test_translation(self):
49
trans = ZzzTranslations()
52
self._check_exact(u'zz{{msg}}', t)
54
t = trans.ugettext('msg')
55
self._check_exact(u'zz{{msg}}', t)
57
t = trans.ungettext('msg1', 'msg2', 0)
58
self._check_exact(u'zz{{msg2}}', t)
59
t = trans.ungettext('msg1', 'msg2', 2)
60
self._check_exact(u'zz{{msg2}}', t)
62
t = trans.ungettext('msg1', 'msg2', 1)
63
self._check_exact(u'zz{{msg1}}', t)
66
class TestGetText(tests.TestCase):
69
super(TestGetText, self).setUp()
70
self.overrideAttr(i18n, '_translations', ZzzTranslations())
72
def test_oneline(self):
73
self.assertEqual(u"zz{{spam ham eggs}}",
74
i18n.gettext("spam ham eggs"))
76
def test_multiline(self):
77
self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
78
i18n.gettext("spam\nham\n\neggs\n"))
81
class TestGetTextPerParagraph(tests.TestCase):
84
super(TestGetTextPerParagraph, self).setUp()
85
self.overrideAttr(i18n, '_translations', ZzzTranslations())
87
def test_oneline(self):
88
self.assertEqual(u"zz{{spam ham eggs}}",
89
i18n.gettext_per_paragraph("spam ham eggs"))
91
def test_multiline(self):
92
self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
93
i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))