/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jan Balster
  • Date: 2006-08-15 12:39:42 UTC
  • mfrom: (1923 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1928.
  • Revision ID: jan@merlinux.de-20060815123942-22c388c6e9a8ac91
merge bzr.dev 1923

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import sys
21
21
import os
22
22
 
 
23
from bzrlib import ignores, osutils, urlutils
23
24
import bzrlib
24
 
import bzrlib.osutils as osutils
25
 
from bzrlib.tests import TestCaseInTempDir, TestSkipped
 
25
from bzrlib.tests import TestCaseWithTransport, TestSkipped
26
26
from bzrlib.trace import mutter, note
27
 
import bzrlib.urlutils as urlutils
28
 
 
29
 
 
30
 
class TestNonAscii(TestCaseInTempDir):
 
27
 
 
28
 
 
29
class TestNonAscii(TestCaseWithTransport):
31
30
    """Test that bzr handles files/committers/etc which are non-ascii."""
32
31
 
33
32
    def setUp(self):
34
33
        super(TestNonAscii, self).setUp()
35
 
        self._orig_email = os.environ.get('BZREMAIL', None)
 
34
        self._orig_email = os.environ.get('BZR_EMAIL', None)
36
35
        self._orig_encoding = bzrlib.user_encoding
37
36
 
38
37
        bzrlib.user_encoding = self.encoding
39
38
        email = self.info['committer'] + ' <joe@foo.com>'
40
 
        os.environ['BZREMAIL'] = email.encode(bzrlib.user_encoding)
 
39
        os.environ['BZR_EMAIL'] = email.encode(bzrlib.user_encoding)
41
40
        self.create_base()
42
41
 
43
42
    def tearDown(self):
44
43
        if self._orig_email is not None:
45
 
            os.environ['BZREMAIL'] = self._orig_email
 
44
            os.environ['BZR_EMAIL'] = self._orig_email
46
45
        else:
47
 
            if os.environ.get('BZREMAIL', None) is not None:
48
 
                del os.environ['BZREMAIL']
 
46
            if os.environ.get('BZR_EMAIL', None) is not None:
 
47
                del os.environ['BZR_EMAIL']
49
48
        bzrlib.user_encoding = self._orig_encoding
50
49
        super(TestNonAscii, self).tearDown()
51
50
 
72
71
                                   ' filesystem encoding "%s")')
73
72
                                   % (thing, terminal_enc, fs_enc))
74
73
 
75
 
        bzr('init')
 
74
        wt = self.make_branch_and_tree('.')
76
75
        open('a', 'wb').write('foo\n')
77
 
        bzr('add', 'a')
78
 
        bzr('commit', '-m', 'adding a')
 
76
        wt.add('a')
 
77
        wt.commit('adding a')
79
78
 
80
79
        open('b', 'wb').write('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n')
81
 
        bzr('add', 'b')
82
 
        bzr('commit', '-m', self.info['message'])
 
80
        wt.add('b')
 
81
        wt.commit(self.info['message'])
83
82
 
84
83
        open(fname, 'wb').write('unicode filename\n')
85
 
        bzr('add', fname)
86
 
        bzr('commit', '-m', u'And a unicode file\n')
 
84
        wt.add(fname)
 
85
        wt.commit(u'And a unicode file\n')
 
86
        self.wt = wt
87
87
 
88
88
    def test_status(self):
89
89
        bzr = self.run_bzr_decode
184
184
        self.failIfExists('a')
185
185
        self.failUnlessExists(fname2)
186
186
 
187
 
        bzr('commit', '-m', 'renamed to non-ascii')
 
187
        # After 'mv' we need to re-open the working tree
 
188
        self.wt = self.wt.bzrdir.open_workingtree()
 
189
        self.wt.commit('renamed to non-ascii')
188
190
 
189
 
        bzr('mkdir', dirname)
 
191
        os.mkdir(dirname)
 
192
        self.wt.add(dirname)
190
193
        txt = bzr('mv', fname1, fname2, dirname)
191
194
        self.assertEqual([u'%s => %s/%s' % (fname1, dirname, fname1),
192
195
                          u'%s => %s/%s' % (fname2, dirname, fname2)]
211
214
 
212
215
        dirname1 = self.info['directory']
213
216
        dirname2 = self.info['directory'] + '2'
214
 
        bzr('branch', '.', dirname1)
215
 
        bzr('branch', dirname1, dirname2)
 
217
        url1 = urlutils.local_path_to_url(dirname1)
 
218
        url2 = urlutils.local_path_to_url(dirname2)
 
219
        out_bzrdir = self.wt.bzrdir.sprout(url1)
 
220
        out_bzrdir.sprout(url2)
216
221
 
217
222
        os.chdir(dirname1)
218
223
        open('a', 'ab').write('more text\n')
219
 
        bzr('commit', '-m', 'mod a')
 
224
        self.wt.commit('mod a')
220
225
 
221
226
        pwd = osutils.getcwd()
222
227
 
227
232
 
228
233
        os.chdir('../' + dirname1)
229
234
        open('a', 'ab').write('and yet more\n')
230
 
        bzr('commit', '-m', 'modifying a by ' + self.info['committer'])
 
235
        self.wt.commit(u'modifying a by ' + self.info['committer'])
231
236
 
232
237
        os.chdir('../' + dirname2)
233
238
        # We should be able to pull, even if our encoding is bad
246
251
        bzr('push', dirname)
247
252
 
248
253
        open('a', 'ab').write('adding more text\n')
249
 
        bzr('commit', '-m', 'added some stuff')
 
254
        self.wt.commit('added some stuff')
250
255
 
251
256
        # TODO: check the output text is properly encoded
252
257
        bzr('push')
253
258
 
254
259
        f = open('a', 'ab')
255
 
        f.write('and a bit more: ')
256
 
        f.write(dirname.encode('utf-8'))
257
 
        f.write('\n')
258
 
        f.close()
 
260
        try:
 
261
            f.write('and a bit more: ')
 
262
            f.write(dirname.encode('utf-8'))
 
263
            f.write('\n')
 
264
        finally:
 
265
            f.close()
259
266
 
260
 
        bzr('commit', '-m', u'Added some ' + dirname)
 
267
        self.wt.commit('Added some ' + dirname)
261
268
        bzr('push', '--verbose', encoding='ascii')
262
269
 
263
270
        bzr('push', '--verbose', dirname + '2')
306
313
        # Create a directory structure
307
314
        fname = self.info['filename']
308
315
        dirname = self.info['directory']
309
 
        bzr('mkdir', 'base')
310
 
        bzr('mkdir', 'base/' + dirname)
 
316
        os.mkdir('base')
 
317
        os.mkdir('base/' + dirname)
 
318
        self.wt.add('base')
 
319
        self.wt.add('base/'+dirname)
311
320
        path = '/'.join(['base', dirname, fname])
312
 
        bzr('mv', fname, path)
313
 
        bzr('commit', '-m', 'moving things around')
 
321
        self.wt.rename_one(fname, path)
 
322
        self.wt.commit('moving things around')
314
323
 
315
324
        txt = bzr('file-path', path)
316
325
 
345
354
 
346
355
        fname = self.info['filename']
347
356
        os.remove(fname)
348
 
        bzr('rm', fname)
 
357
        self.wt.remove(fname)
349
358
 
350
359
        txt = bzr('deleted')
351
360
        self.assertEqual(fname+'\n', txt)
374
383
 
375
384
        fname = self.info['filename'] + '2'
376
385
        open(fname, 'wb').write('added\n')
377
 
        bzr('add', fname)
 
386
        self.wt.add(fname)
378
387
 
379
388
        txt = bzr('added')
380
389
        self.assertEqual(fname+'\n', txt)
385
394
        bzr = self.run_bzr_decode
386
395
 
387
396
        dirname = self.info['directory']
 
397
        url = urlutils.local_path_to_url(dirname)
388
398
        bzr('root')
389
399
 
390
 
        bzr('branch', u'.', dirname)
 
400
        self.wt.bzrdir.sprout(url)
391
401
 
392
402
        os.chdir(dirname)
393
403
 
421
431
        self.assertEqual(u'     3 added %s\n' % (fname,), txt)
422
432
 
423
433
        fname2 = self.info['filename'] + '2'
424
 
        bzr('mv', fname, fname2)
425
 
        bzr('commit', '-m', u'Renamed %s => %s' % (fname, fname2))
 
434
        self.wt.rename_one(fname, fname2)
 
435
        self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
426
436
 
427
437
        txt = bzr('touching-revisions', fname2)
428
438
        expected_txt = (u'     3 added %s\n' 
436
446
        bzr = self.run_bzr_decode
437
447
 
438
448
        txt = bzr('ls')
439
 
        self.assertEqual(['a', 'b', self.info['filename']],
440
 
                         txt.splitlines())
 
449
        self.assertEqual(sorted(['a', 'b', self.info['filename']]),
 
450
                         sorted(txt.splitlines()))
441
451
        txt = bzr('ls', '--null')
442
 
        self.assertEqual(['a', 'b', self.info['filename'], ''],
443
 
                         txt.split('\0'))
 
452
        self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
 
453
                         sorted(txt.split('\0')))
444
454
 
445
455
        txt = bzr('ls', encoding='ascii', retcode=3)
446
456
        txt = bzr('ls', '--null', encoding='ascii', retcode=3)
461
471
    def test_ignore(self):
462
472
        bzr = self.run_bzr_decode
463
473
 
 
474
        ignores._set_user_ignores(['./.bazaar'])
464
475
        fname2 = self.info['filename'] + '2.txt'
465
476
        open(fname2, 'wb').write('ignored\n')
466
477
 
467
 
        txt = bzr('unknowns')
468
 
        self.assertEqual(u'"%s"\n' % (fname2,), txt)
 
478
        def check_unknowns(expected):
 
479
            self.assertEqual(expected, list(self.wt.unknowns()))
 
480
 
 
481
        check_unknowns([fname2])
469
482
 
470
483
        bzr('ignore', './' + fname2)
471
 
        txt = bzr('unknowns')
472
 
        self.assertEqual(u'', txt)
 
484
        # After 'ignore' you must re-open the working tree
 
485
        self.wt = self.wt.bzrdir.open_workingtree()
 
486
        check_unknowns([])
473
487
 
474
488
        fname3 = self.info['filename'] + '3.txt'
475
489
        open(fname3, 'wb').write('unknown 3\n')
476
 
        txt = bzr('unknowns')
477
 
        self.assertEqual(u'"%s"\n' % (fname3,), txt)
 
490
        check_unknowns([fname3])
478
491
 
479
492
        # Ignore should not care what the encoding is
480
493
        # (right now it doesn't print anything)
481
494
        bzr('ignore', fname3, encoding='ascii')
482
 
        txt = bzr('unknowns')
483
 
        self.assertEqual('', txt)
 
495
        self.wt = self.wt.bzrdir.open_workingtree()
 
496
        check_unknowns([])
484
497
 
485
498
        # Now try a wildcard match
486
499
        fname4 = self.info['filename'] + '4.txt'
487
500
        open(fname4, 'wb').write('unknown 4\n')
488
501
        bzr('ignore', '*.txt')
489
 
        txt = bzr('unknowns')
490
 
        self.assertEqual('', txt)
 
502
        self.wt = self.wt.bzrdir.open_workingtree()
 
503
        check_unknowns([])
491
504
 
 
505
        # and a different wildcard that matches everything
492
506
        os.remove('.bzrignore')
493
507
        bzr('ignore', self.info['filename'] + '*')
494
 
        txt = bzr('unknowns')
495
 
        self.assertEqual('', txt)
496
 
 
497
 
 
 
508
        self.wt = self.wt.bzrdir.open_workingtree()
 
509
        check_unknowns([])
 
510
 
 
511
    def test_missing(self):
 
512
        bzr = self.run_bzr_decode
 
513
 
 
514
        # create empty tree as reference for missing
 
515
        self.run_bzr('init', 'empty-tree')
 
516
 
 
517
        msg = self.info['message']
 
518
 
 
519
        txt = bzr('missing', 'empty-tree', retcode=1)
 
520
        self.assertNotEqual(-1, txt.find(self.info['committer']))
 
521
        self.assertNotEqual(-1, txt.find(msg))
 
522
 
 
523
        # Make sure missing doesn't fail even if we can't write out
 
524
        txt = bzr('missing', 'empty-tree', encoding='ascii', retcode=1)
 
525
        self.assertEqual(-1, txt.find(msg))
 
526
        self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))