~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-09-08 11:01:15 UTC
  • mfrom: (6123.1.16 gpg-typo)
  • Revision ID: pqm@cupuasso-20110908110115-gbb9benwkdksvzk5
(jelmer) Fix a typo (invalid format identifier) in an error message in
 bzrlib.gpg. (Jelmer Vernooij)

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
 
19
from bzrlib import (i18n, 
 
20
                    tests, 
 
21
                    errors, 
 
22
                    workingtree,
 
23
                    )
20
24
 
21
25
 
22
26
class ZzzTranslations(object):
28
32
    _null_translation = i18n._gettext.NullTranslations()
29
33
 
30
34
    def zzz(self, s):
31
 
        return u'zz{{%s}}' % s
 
35
        return u'zz\xe5{{%s}}' % s
32
36
 
33
37
    def ugettext(self, s):
34
38
        return self.zzz(self._null_translation.ugettext(s))
47
51
        trans = ZzzTranslations()
48
52
 
49
53
        t = trans.zzz('msg')
50
 
        self._check_exact(u'zz{{msg}}', t)
 
54
        self._check_exact(u'zz\xe5{{msg}}', t)
51
55
 
52
56
        t = trans.ugettext('msg')
53
 
        self._check_exact(u'zz{{msg}}', t)
 
57
        self._check_exact(u'zz\xe5{{msg}}', t)
54
58
 
55
59
        t = trans.ungettext('msg1', 'msg2', 0)
56
 
        self._check_exact(u'zz{{msg2}}', t)
 
60
        self._check_exact(u'zz\xe5{{msg2}}', t)
57
61
        t = trans.ungettext('msg1', 'msg2', 2)
58
 
        self._check_exact(u'zz{{msg2}}', t)
 
62
        self._check_exact(u'zz\xe5{{msg2}}', t)
59
63
 
60
64
        t = trans.ungettext('msg1', 'msg2', 1)
61
 
        self._check_exact(u'zz{{msg1}}', t)
 
65
        self._check_exact(u'zz\xe5{{msg1}}', t)
62
66
 
63
67
 
64
68
class TestGetText(tests.TestCase):
68
72
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
69
73
 
70
74
    def test_oneline(self):
71
 
        self.assertEqual(u"zz{{spam ham eggs}}",
 
75
        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
72
76
                         i18n.gettext("spam ham eggs"))
73
77
 
74
78
    def test_multiline(self):
75
 
        self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
 
79
        self.assertEqual(u"zz\xe5{{spam\nham\n\neggs\n}}",
76
80
                         i18n.gettext("spam\nham\n\neggs\n"))
77
81
 
78
82
 
83
87
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
84
88
 
85
89
    def test_oneline(self):
86
 
        self.assertEqual(u"zz{{spam ham eggs}}",
 
90
        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
87
91
                         i18n.gettext_per_paragraph("spam ham eggs"))
88
92
 
89
93
    def test_multiline(self):
90
 
        self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
 
94
        self.assertEqual(u"zz\xe5{{spam\nham}}\n\nzz\xe5{{eggs\n}}",
91
95
                         i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))
92
96
 
93
97
 
104
108
        self.overrideEnv('LC_MESSAGES', None)
105
109
        self.overrideEnv('LANG', None)
106
110
        i18n.install()
 
111
 
 
112
class TestTranslate(tests.TestCaseWithTransport):
 
113
 
 
114
    def setUp(self):
 
115
        super(TestTranslate, self).setUp()
 
116
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
117
 
 
118
    def test_error_message_translation(self):
 
119
        """do errors get translated?"""
 
120
        err = None
 
121
        tree = self.make_branch_and_tree('.')
 
122
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
123
        try:
 
124
            workingtree.WorkingTree.open('./foo')
 
125
        except errors.NotBranchError,e:
 
126
            err = str(e)
 
127
        self.assertContainsRe(err, 
 
128
                              u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))
 
129
 
 
130
    def test_topic_help_translation(self):
 
131
        """does topic help get translated?"""
 
132
        from bzrlib import help
 
133
        i18n.install()
 
134
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
135
        from StringIO import StringIO
 
136
        out = StringIO()
 
137
        help.help("authentication", out)
 
138
        self.assertContainsRe(out.getvalue(), "zz\xe5{{Authentication Settings")