/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
23
24
class ZzzTranslations(object):
25
    """Special Zzz translation for debugging i18n stuff.
26
27
    This class can be used to confirm that the message is properly translated
28
    during black box tests.
29
    """
30
    _null_translation = i18n._gettext.NullTranslations()
31
32
    def zzz(self, s):
33
        return u'zz{{%s}}' % s
34
35
    def ugettext(self, s):
36
        return self.zzz(self._null_translation.ugettext(s))
37
38
    def ungettext(self, s, p, n):
39
        return self.zzz(self._null_translation.ungettext(s, p, n))
40
41
5875.2.2 by INADA Naoki
Add tests for bzrlib.i18n
42
class TestZzzTranslation(tests.TestCase):
43
44
    def _check_exact(self, expected, source):
45
        self.assertEqual(expected, source)
46
        self.assertEqual(type(expected), type(source))
47
48
    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.
49
        trans = ZzzTranslations()
5875.2.2 by INADA Naoki
Add tests for bzrlib.i18n
50
51
        t = trans.zzz('msg')
52
        self._check_exact(u'zz{{msg}}', t)
53
54
        t = trans.ugettext('msg')
55
        self._check_exact(u'zz{{msg}}', t)
56
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)
61
62
        t = trans.ungettext('msg1', 'msg2', 1)
63
        self._check_exact(u'zz{{msg1}}', t)
64
65
66
class TestGetText(tests.TestCase):
67
68
    def setUp(self):
69
        super(TestGetText, self).setUp()
5875.2.9 by Vincent Ladeuil
Cleanup some PEP8 issues and move test code in test module, test_multiline still failing.
70
        self.overrideAttr(i18n, '_translation', ZzzTranslations())
5875.2.2 by INADA Naoki
Add tests for bzrlib.i18n
71
72
    def test_oneline(self):
73
        self.assertEqual(u"zz{{spam ham eggs}}",
74
                         i18n.gettext("spam ham eggs"))
75
76
    def test_multiline(self):
5875.2.10 by INADA Naoki
Add TestGetTextPerParagraph and fix error on TestGetText.test_multiline.
77
        self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
78
                         i18n.gettext("spam\nham\n\neggs\n"))
79
80
81
class TestGetTextPerParagraph(tests.TestCase):
82
83
    def setUp(self):
84
        super(TestGetTextPerParagraph, self).setUp()
85
        self.overrideAttr(i18n, '_translation', ZzzTranslations())
86
87
    def test_oneline(self):
88
        self.assertEqual(u"zz{{spam ham eggs}}",
89
                         i18n.gettext_per_paragraph("spam ham eggs"))
90
91
    def test_multiline(self):
5875.2.2 by INADA Naoki
Add tests for bzrlib.i18n
92
        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.
93
                         i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))