~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_i18n.py

  • Committer: Robert Collins
  • Date: 2006-05-04 13:26:31 UTC
  • mto: (1697.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1701.
  • Revision ID: robertc@robertcollins.net-20060504132631-ab199c12d7427f82
Branch.break_lock should handle bound branches too

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
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
 
 
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):
49
 
        trans = ZzzTranslations()
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()
70
 
        self.overrideAttr(i18n, '_translation', ZzzTranslations())
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):
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):
92
 
        self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
93
 
                         i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))