~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_i18n.py

  • Committer: Benoît Pierre
  • Date: 2011-10-10 20:55:52 UTC
  • mto: This revision was merged to the branch mainline in revision 6215.
  • Revision ID: benoit.pierre@gmail.com-20111010205552-7o6qoaiihy31hhxb
Avoid prompt duplication for shelf_ui tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for bzrlib.i18n"""
18
18
 
19
 
from bzrlib import i18n, tests
20
 
 
21
 
 
 
19
from bzrlib import (i18n, 
 
20
                    tests, 
 
21
                    errors, 
 
22
                    workingtree,
 
23
                    )
22
24
 
23
25
 
24
26
class ZzzTranslations(object):
30
32
    _null_translation = i18n._gettext.NullTranslations()
31
33
 
32
34
    def zzz(self, s):
33
 
        return u'zz{{%s}}' % s
 
35
        return u'zz\xe5{{%s}}' % s
34
36
 
35
37
    def ugettext(self, s):
36
38
        return self.zzz(self._null_translation.ugettext(s))
49
51
        trans = ZzzTranslations()
50
52
 
51
53
        t = trans.zzz('msg')
52
 
        self._check_exact(u'zz{{msg}}', t)
 
54
        self._check_exact(u'zz\xe5{{msg}}', t)
53
55
 
54
56
        t = trans.ugettext('msg')
55
 
        self._check_exact(u'zz{{msg}}', t)
 
57
        self._check_exact(u'zz\xe5{{msg}}', t)
56
58
 
57
59
        t = trans.ungettext('msg1', 'msg2', 0)
58
 
        self._check_exact(u'zz{{msg2}}', t)
 
60
        self._check_exact(u'zz\xe5{{msg2}}', t)
59
61
        t = trans.ungettext('msg1', 'msg2', 2)
60
 
        self._check_exact(u'zz{{msg2}}', t)
 
62
        self._check_exact(u'zz\xe5{{msg2}}', t)
61
63
 
62
64
        t = trans.ungettext('msg1', 'msg2', 1)
63
 
        self._check_exact(u'zz{{msg1}}', t)
 
65
        self._check_exact(u'zz\xe5{{msg1}}', t)
64
66
 
65
67
 
66
68
class TestGetText(tests.TestCase):
70
72
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
71
73
 
72
74
    def test_oneline(self):
73
 
        self.assertEqual(u"zz{{spam ham eggs}}",
 
75
        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
74
76
                         i18n.gettext("spam ham eggs"))
75
77
 
76
78
    def test_multiline(self):
77
 
        self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
 
79
        self.assertEqual(u"zz\xe5{{spam\nham\n\neggs\n}}",
78
80
                         i18n.gettext("spam\nham\n\neggs\n"))
79
81
 
80
82
 
85
87
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
86
88
 
87
89
    def test_oneline(self):
88
 
        self.assertEqual(u"zz{{spam ham eggs}}",
 
90
        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
89
91
                         i18n.gettext_per_paragraph("spam ham eggs"))
90
92
 
91
93
    def test_multiline(self):
92
 
        self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
 
94
        self.assertEqual(u"zz\xe5{{spam\nham}}\n\nzz\xe5{{eggs\n}}",
93
95
                         i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))
 
96
 
 
97
 
 
98
class TestInstall(tests.TestCase):
 
99
 
 
100
    def setUp(self):
 
101
        super(TestInstall, self).setUp()
 
102
        # Restore a proper env to test translation installation
 
103
        self.overrideAttr(i18n, '_translations', None)
 
104
 
 
105
    def test_custom_languages(self):
 
106
        i18n.install('nl:fy')
 
107
        # Whether we found a valid tranlsation or not doesn't matter, we got
 
108
        # one and _translations is not None anymore.
 
109
        self.assertIsInstance(i18n._translations,
 
110
                              i18n._gettext.NullTranslations)
 
111
 
 
112
    def test_no_env_variables(self):
 
113
        self.overrideEnv('LANGUAGE', None)
 
114
        self.overrideEnv('LC_ALL', None)
 
115
        self.overrideEnv('LC_MESSAGES', None)
 
116
        self.overrideEnv('LANG', None)
 
117
        i18n.install()
 
118
        # Whether we found a valid tranlsation or not doesn't matter, we got
 
119
        # one and _translations is not None anymore.
 
120
        self.assertIsInstance(i18n._translations,
 
121
                              i18n._gettext.NullTranslations)
 
122
 
 
123
    def test_disable_i18n(self):
 
124
        i18n.disable_i18n()
 
125
        i18n.install()
 
126
        # It's disabled, you can't install anything and we fallback to null
 
127
        self.assertIsInstance(i18n._translations,
 
128
                              i18n._gettext.NullTranslations)
 
129
 
 
130
 
 
131
class TestTranslate(tests.TestCaseWithTransport):
 
132
 
 
133
    def setUp(self):
 
134
        super(TestTranslate, self).setUp()
 
135
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
136
 
 
137
    def test_error_message_translation(self):
 
138
        """do errors get translated?"""
 
139
        err = None
 
140
        tree = self.make_branch_and_tree('.')
 
141
        try:
 
142
            workingtree.WorkingTree.open('./foo')
 
143
        except errors.NotBranchError,e:
 
144
            err = str(e)
 
145
        self.assertContainsRe(err, 
 
146
                              u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))
 
147
 
 
148
    def test_topic_help_translation(self):
 
149
        """does topic help get translated?"""
 
150
        from bzrlib import help
 
151
        from StringIO import StringIO
 
152
        out = StringIO()
 
153
        help.help("authentication", out)
 
154
        self.assertContainsRe(out.getvalue(), "zz\xe5{{Authentication Settings")