~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_log.py

  • Committer: Robert Collins
  • Date: 2006-03-28 14:29:13 UTC
  • mto: (1626.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1628.
  • Revision ID: robertc@robertcollins.net-20060328142913-ac5afb37075719c6
Convert log to use the new tsort.merge_sort routine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
 
23
 
import bzrlib
24
23
from bzrlib.tests.blackbox import ExternalBase
25
 
from bzrlib.tests import TestCaseInTempDir
26
24
 
27
25
 
28
26
class TestLog(ExternalBase):
153
151
        self.assertTrue('      branch 1' in out)
154
152
        self.assertTrue('  first post' in out)
155
153
        self.assertEqual('', err)
156
 
 
157
 
 
158
 
class TestLogEncodings(TestCaseInTempDir):
159
 
 
160
 
    _mu = u'\xb5'
161
 
    _message = u'Message with \xb5'
162
 
 
163
 
    # Encodings which can encode mu
164
 
    good_encodings = [
165
 
        'utf-8',
166
 
        'latin-1',
167
 
        'iso-8859-1',
168
 
        'cp437', # Common windows encoding
169
 
        'cp1251', # Alexander Belchenko's windows encoding
170
 
        'cp1258', # Common windows encoding
171
 
    ]
172
 
    # Encodings which cannot encode mu
173
 
    bad_encodings = [
174
 
        'ascii',
175
 
        'iso-8859-2',
176
 
        'koi8_r',
177
 
    ]
178
 
 
179
 
    def setUp(self):
180
 
        TestCaseInTempDir.setUp(self)
181
 
        self.user_encoding = bzrlib.user_encoding
182
 
 
183
 
    def tearDown(self):
184
 
        bzrlib.user_encoding = self.user_encoding
185
 
        TestCaseInTempDir.tearDown(self)
186
 
 
187
 
    def create_branch(self):
188
 
        bzr = self.run_bzr
189
 
        bzr('init')
190
 
        open('a', 'wb').write('some stuff\n')
191
 
        bzr('add', 'a')
192
 
        bzr('commit', '-m', self._message)
193
 
 
194
 
    def try_encoding(self, encoding, fail=False):
195
 
        bzr = self.run_bzr
196
 
        if fail:
197
 
            self.assertRaises(UnicodeEncodeError,
198
 
                self._mu.encode, encoding)
199
 
            encoded_msg = self._message.encode(encoding, 'replace')
200
 
        else:
201
 
            encoded_msg = self._message.encode(encoding)
202
 
 
203
 
        old_encoding = bzrlib.user_encoding
204
 
        # This test requires that 'run_bzr' uses the current
205
 
        # bzrlib, because we override user_encoding, and expect
206
 
        # it to be used
207
 
        try:
208
 
            bzrlib.user_encoding = 'ascii'
209
 
            # We should be able to handle any encoding
210
 
            out, err = bzr('log', encoding=encoding)
211
 
            if not fail:
212
 
                # Make sure we wrote mu as we expected it to exist
213
 
                self.assertNotEqual(-1, out.find(encoded_msg))
214
 
                out_unicode = out.decode(encoding)
215
 
                self.assertNotEqual(-1, out_unicode.find(self._message))
216
 
            else:
217
 
                self.assertNotEqual(-1, out.find('Message with ?'))
218
 
        finally:
219
 
            bzrlib.user_encoding = old_encoding
220
 
 
221
 
    def test_log_handles_encoding(self):
222
 
        self.create_branch()
223
 
 
224
 
        for encoding in self.good_encodings:
225
 
            self.try_encoding(encoding)
226
 
 
227
 
    def test_log_handles_bad_encoding(self):
228
 
        self.create_branch()
229
 
 
230
 
        for encoding in self.bad_encodings:
231
 
            self.try_encoding(encoding, fail=True)
232
 
 
233
 
    def test_stdout_encoding(self):
234
 
        bzr = self.run_bzr
235
 
        bzrlib.user_encoding = "cp1251"
236
 
 
237
 
        bzr('init')
238
 
        self.build_tree(['a'])
239
 
        bzr('add', 'a')
240
 
        bzr('commit', '-m', u'\u0422\u0435\u0441\u0442')
241
 
        stdout, stderr = self.run_bzr('log', encoding='cp866')
242
 
 
243
 
        message = stdout.splitlines()[-1]
244
 
 
245
 
        # explanation of the check:
246
 
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
247
 
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
248
 
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
249
 
        # This test should check that output of log command
250
 
        # encoded to sys.stdout.encoding
251
 
        test_in_cp866 = '\x92\xa5\xe1\xe2'
252
 
        test_in_cp1251 = '\xd2\xe5\xf1\xf2'
253
 
        # Make sure the log string is encoded in cp866
254
 
        self.assertEquals(test_in_cp866, message[2:])
255
 
        # Make sure the cp1251 string is not found anywhere
256
 
        self.assertEquals(-1, stdout.find(test_in_cp1251))
257