~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_i18n.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-15 11:36:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5975.
  • Revision ID: v.ladeuil+lp@free.fr-20110615113605-p7zyyfry9wy1hquc
Make ContentConflict resolution more robust

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 (
20
 
    i18n,
21
 
    tests,
22
 
    errors,
23
 
    workingtree,
24
 
    )
 
19
from bzrlib import i18n, tests
 
20
 
 
21
 
25
22
 
26
23
 
27
24
class ZzzTranslations(object):
33
30
    _null_translation = i18n._gettext.NullTranslations()
34
31
 
35
32
    def zzz(self, s):
36
 
        return u'zz\xe5{{%s}}' % s
 
33
        return u'zz{{%s}}' % s
37
34
 
38
35
    def ugettext(self, s):
39
36
        return self.zzz(self._null_translation.ugettext(s))
52
49
        trans = ZzzTranslations()
53
50
 
54
51
        t = trans.zzz('msg')
55
 
        self._check_exact(u'zz\xe5{{msg}}', t)
 
52
        self._check_exact(u'zz{{msg}}', t)
56
53
 
57
54
        t = trans.ugettext('msg')
58
 
        self._check_exact(u'zz\xe5{{msg}}', t)
 
55
        self._check_exact(u'zz{{msg}}', t)
59
56
 
60
57
        t = trans.ungettext('msg1', 'msg2', 0)
61
 
        self._check_exact(u'zz\xe5{{msg2}}', t)
 
58
        self._check_exact(u'zz{{msg2}}', t)
62
59
        t = trans.ungettext('msg1', 'msg2', 2)
63
 
        self._check_exact(u'zz\xe5{{msg2}}', t)
 
60
        self._check_exact(u'zz{{msg2}}', t)
64
61
 
65
62
        t = trans.ungettext('msg1', 'msg2', 1)
66
 
        self._check_exact(u'zz\xe5{{msg1}}', t)
 
63
        self._check_exact(u'zz{{msg1}}', t)
67
64
 
68
65
 
69
66
class TestGetText(tests.TestCase):
70
67
 
71
68
    def setUp(self):
72
69
        super(TestGetText, self).setUp()
73
 
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
70
        self.overrideAttr(i18n, '_translation', ZzzTranslations())
74
71
 
75
72
    def test_oneline(self):
76
 
        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
 
73
        self.assertEqual(u"zz{{spam ham eggs}}",
77
74
                         i18n.gettext("spam ham eggs"))
78
75
 
79
76
    def test_multiline(self):
80
 
        self.assertEqual(u"zz\xe5{{spam\nham\n\neggs\n}}",
 
77
        self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
81
78
                         i18n.gettext("spam\nham\n\neggs\n"))
82
79
 
83
80
 
85
82
 
86
83
    def setUp(self):
87
84
        super(TestGetTextPerParagraph, self).setUp()
88
 
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
85
        self.overrideAttr(i18n, '_translation', ZzzTranslations())
89
86
 
90
87
    def test_oneline(self):
91
 
        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
 
88
        self.assertEqual(u"zz{{spam ham eggs}}",
92
89
                         i18n.gettext_per_paragraph("spam ham eggs"))
93
90
 
94
91
    def test_multiline(self):
95
 
        self.assertEqual(u"zz\xe5{{spam\nham}}\n\nzz\xe5{{eggs\n}}",
 
92
        self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
96
93
                         i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))
97
 
 
98
 
 
99
 
class TestInstall(tests.TestCase):
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
 
 
106
 
    def test_custom_languages(self):
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)
112
 
 
113
 
    def test_no_env_variables(self):
114
 
        self.overrideEnv('LANGUAGE', None)
115
 
        self.overrideEnv('LC_ALL', None)
116
 
        self.overrideEnv('LC_MESSAGES', None)
117
 
        self.overrideEnv('LANG', None)
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
 
 
131
 
 
132
 
class TestTranslate(tests.TestCaseWithTransport):
133
 
 
134
 
    def setUp(self):
135
 
        super(TestTranslate, self).setUp()
136
 
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
137
 
 
138
 
    def test_error_message_translation(self):
139
 
        """do errors get translated?"""
140
 
        err = None
141
 
        tree = self.make_branch_and_tree('.')
142
 
        try:
143
 
            workingtree.WorkingTree.open('./foo')
144
 
        except errors.NotBranchError,e:
145
 
            err = str(e)
146
 
        self.assertContainsRe(err, 
147
 
                              u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))
148
 
 
149
 
    def test_topic_help_translation(self):
150
 
        """does topic help get translated?"""
151
 
        from bzrlib import help
152
 
        from StringIO import StringIO
153
 
        out = StringIO()
154
 
        help.help("authentication", out)
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"))