~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_i18n.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-06 10:15:06 UTC
  • mfrom: (6195.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20111006101506-mychax14dy7yjee2
(vila) Tag bzr-2.5b2 missed during freeze (Vincent Ladeuil)

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, 
20
 
                    tests, 
21
 
                    errors, 
22
 
                    workingtree,
23
 
                    )
 
19
from bzrlib import (
 
20
    i18n,
 
21
    tests,
 
22
    errors,
 
23
    workingtree,
 
24
    )
24
25
 
25
26
 
26
27
class ZzzTranslations(object):
97
98
 
98
99
class TestInstall(tests.TestCase):
99
100
 
 
101
    def setUp(self):
 
102
        super(TestInstall, self).setUp()
 
103
        # Restore a proper env to test translation installation
 
104
        self.overrideAttr(i18n, '_translations', None)
 
105
 
100
106
    def test_custom_languages(self):
101
 
        self.addCleanup(i18n.install)
102
107
        i18n.install('nl:fy')
 
108
        # Whether we found a valid tranlsation or not doesn't matter, we got
 
109
        # one and _translations is not None anymore.
 
110
        self.assertIsInstance(i18n._translations,
 
111
                              i18n._gettext.NullTranslations)
103
112
 
104
113
    def test_no_env_variables(self):
105
 
        self.addCleanup(i18n.install)
106
114
        self.overrideEnv('LANGUAGE', None)
107
115
        self.overrideEnv('LC_ALL', None)
108
116
        self.overrideEnv('LC_MESSAGES', None)
109
117
        self.overrideEnv('LANG', None)
110
118
        i18n.install()
 
119
        # Whether we found a valid tranlsation or not doesn't matter, we got
 
120
        # one and _translations is not None anymore.
 
121
        self.assertIsInstance(i18n._translations,
 
122
                              i18n._gettext.NullTranslations)
 
123
 
 
124
    def test_disable_i18n(self):
 
125
        i18n.disable_i18n()
 
126
        i18n.install()
 
127
        # It's disabled, you can't install anything and we fallback to null
 
128
        self.assertIsInstance(i18n._translations,
 
129
                              i18n._gettext.NullTranslations)
 
130
 
111
131
 
112
132
class TestTranslate(tests.TestCaseWithTransport):
113
133
 
119
139
        """do errors get translated?"""
120
140
        err = None
121
141
        tree = self.make_branch_and_tree('.')
122
 
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
123
142
        try:
124
143
            workingtree.WorkingTree.open('./foo')
125
144
        except errors.NotBranchError,e:
130
149
    def test_topic_help_translation(self):
131
150
        """does topic help get translated?"""
132
151
        from bzrlib import help
133
 
        i18n.install()
134
 
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
135
152
        from StringIO import StringIO
136
153
        out = StringIO()
137
154
        help.help("authentication", out)
138
155
        self.assertContainsRe(out.getvalue(), "zz\xe5{{Authentication Settings")
 
156
 
 
157
 
 
158
class LoadPluginTranslations(tests.TestCase):
 
159
 
 
160
    def test_does_not_exist(self):
 
161
        translation = i18n.load_plugin_translations("doesnotexist")
 
162
        self.assertEquals("foo", translation.gettext("foo"))