~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2007-06-26 20:32:49 UTC
  • mto: (2581.1.1 cleanup-runbzr)
  • mto: This revision was merged to the branch mainline in revision 2588.
  • Revision ID: v.ladeuil+lp@free.fr-20070626203249-sqm4afiai5dxofum
Deprecate the varargs syntax and fix the tests.

* bzrlib/tests/__init__.py:
(TestCase.run_bzr): Activate the deprecation warning.
(TestCase.run_bzr_error): Add error_regexes to kwargs or run_bzr
get confused.

* bzrlib/tests/blackbox/test_selftest.py:
(TestRunBzr.test_args): Activate.

* bzrlib/tests/blackbox/test_inventory.py:
(TestInventory.assertInventoryEqual): Build the command from args
if not None.

* bzrlib/tests/blackbox/test_ls.py:
(TestLS.ls_equals): Build the command from args if not None.

* bzrlib/tests/blackbox/test_remove_tree.py:
(TestRemoveTree.test_remove_tree_lightweight_checkout_explicit):
Nice catch, we were calling run_bzr instead of run_bzr_error. This
went unnoticed for some time...

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
    def test_cat(self):
101
101
        # bzr cat shouldn't change the contents
102
102
        # using run_bzr since that doesn't decode
103
 
        txt = self.run_bzr('cat', 'b')[0]
 
103
        txt = self.run_bzr('cat b')[0]
104
104
        self.assertEqual('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n', txt)
105
105
 
106
 
        txt = self.run_bzr('cat', self.info['filename'])[0]
 
106
        txt = self.run_bzr(['cat', self.info['filename']])[0]
107
107
        self.assertEqual('unicode filename\n', txt)
108
108
 
109
109
    def test_cat_revision(self):
110
110
        bzr = self.run_bzr_decode
111
111
 
112
112
        committer = self.info['committer']
113
 
        txt = bzr('cat-revision', '-r', '1')
 
113
        txt = bzr('cat-revision -r 1')
114
114
        self.failUnless(committer in txt,
115
115
                        'failed to find %r in %r' % (committer, txt))
116
116
 
117
117
        msg = self.info['message']
118
 
        txt = bzr('cat-revision', '-r', '2')
 
118
        txt = bzr('cat-revision -r 2')
119
119
        self.failUnless(msg in txt, 'failed to find %r in %r' % (msg, txt))
120
120
 
121
121
    def test_mkdir(self):
122
122
        bzr = self.run_bzr_decode
123
123
 
124
 
        txt = bzr('mkdir', self.info['directory'])
 
124
        txt = bzr(['mkdir', self.info['directory']])
125
125
        self.assertEqual(u'added %s\n' % self.info['directory'], txt)
126
126
 
127
127
        # The text should be garbled, but the command should succeed
128
 
        txt = bzr('mkdir', self.info['directory'] + '2', encoding='ascii')
 
128
        txt = bzr(['mkdir', self.info['directory'] + '2'], encoding='ascii')
129
129
        expected = u'added %s2\n' % (self.info['directory'],)
130
130
        expected = expected.encode('ascii', 'replace')
131
131
        self.assertEqual(expected, txt)
133
133
    def test_relpath(self):
134
134
        bzr = self.run_bzr_decode
135
135
 
136
 
        txt = bzr('relpath', self.info['filename'])
 
136
        txt = bzr(['relpath', self.info['filename']])
137
137
        self.assertEqual(self.info['filename'] + '\n', txt)
138
138
 
139
 
        bzr('relpath', self.info['filename'], encoding='ascii', retcode=3)
 
139
        bzr(['relpath', self.info['filename']], encoding='ascii', retcode=3)
140
140
 
141
141
    def test_inventory(self):
142
142
        bzr = self.run_bzr_decode
150
150
 
151
151
        # We don't really care about the ids themselves,
152
152
        # but the command shouldn't fail
153
 
        txt = bzr('inventory', '--show-ids')
 
153
        txt = bzr('inventory --show-ids')
154
154
 
155
155
    def test_revno(self):
156
156
        # There isn't a lot to test here, since revno should always
163
163
    def test_revision_info(self):
164
164
        bzr = self.run_bzr_decode
165
165
 
166
 
        bzr('revision-info', '-r', '1')
 
166
        bzr('revision-info -r 1')
167
167
 
168
168
        # TODO: jam 20060105 If we support revisions with non-ascii characters,
169
169
        # this should be strict and fail.
170
 
        bzr('revision-info', '-r', '1', encoding='ascii')
 
170
        bzr('revision-info -r 1', encoding='ascii')
171
171
 
172
172
    def test_mv(self):
173
173
        bzr = self.run_bzr_decode
177
177
        dirname = self.info['directory']
178
178
 
179
179
        # fname1 already exists
180
 
        bzr('mv', 'a', fname1, retcode=3)
 
180
        bzr(['mv', 'a', fname1], retcode=3)
181
181
 
182
 
        txt = bzr('mv', 'a', fname2)
 
182
        txt = bzr(['mv', 'a', fname2])
183
183
        self.assertEqual(u'a => %s\n' % fname2, txt)
184
184
        self.failIfExists('a')
185
185
        self.failUnlessExists(fname2)
190
190
 
191
191
        os.mkdir(dirname)
192
192
        self.wt.add(dirname)
193
 
        txt = bzr('mv', fname1, fname2, dirname)
 
193
        txt = bzr(['mv', fname1, fname2, dirname])
194
194
        self.assertEqual([u'%s => %s/%s' % (fname1, dirname, fname1),
195
195
                          u'%s => %s/%s' % (fname2, dirname, fname2)]
196
196
                         , txt.splitlines())
197
197
 
198
198
        # The rename should still succeed
199
199
        newpath = u'%s/%s' % (dirname, fname2)
200
 
        txt = bzr('mv', newpath, 'a', encoding='ascii')
 
200
        txt = bzr(['mv', newpath, 'a'], encoding='ascii')
201
201
        self.failUnlessExists('a')
202
202
        self.assertEqual(newpath.encode('ascii', 'replace') + ' => a\n', txt)
203
203
 
205
205
        # We should be able to branch into a directory that
206
206
        # has a unicode name, even if we can't display the name
207
207
        bzr = self.run_bzr_decode
208
 
        bzr('branch', u'.', self.info['directory'])
209
 
        bzr('branch', u'.', self.info['directory'] + '2', encoding='ascii')
 
208
        bzr(['branch', u'.', self.info['directory']])
 
209
        bzr(['branch', u'.', self.info['directory'] + '2'], encoding='ascii')
210
210
 
211
211
    def test_pull(self):
212
212
        # Make sure we can pull from paths that can't be encoded
237
237
 
238
238
        os.chdir('../' + dirname2)
239
239
        # We should be able to pull, even if our encoding is bad
240
 
        bzr('pull', '--verbose', encoding='ascii')
 
240
        bzr('pull --verbose', encoding='ascii')
241
241
 
242
242
    def test_push(self):
243
243
        # TODO: Test push to an SFTP location
249
249
        #       the files around as much.
250
250
 
251
251
        dirname = self.info['directory']
252
 
        bzr('push', dirname)
 
252
        bzr(['push', dirname])
253
253
 
254
254
        open('a', 'ab').write('adding more text\n')
255
255
        self.wt.commit('added some stuff')
266
266
            f.close()
267
267
 
268
268
        self.wt.commit('Added some ' + dirname)
269
 
        bzr('push', '--verbose', encoding='ascii')
270
 
 
271
 
        bzr('push', '--verbose', dirname + '2')
272
 
 
273
 
        bzr('push', '--verbose', dirname + '3', encoding='ascii')
274
 
 
275
 
        bzr('push', '--verbose', '--create-prefix', dirname + '4/' + dirname + '5')
276
 
        bzr('push', '--verbose', '--create-prefix', dirname + '6/' + dirname + '7', encoding='ascii')
 
269
        bzr('push --verbose', encoding='ascii')
 
270
 
 
271
        bzr(['push', '--verbose', dirname + '2'])
 
272
 
 
273
        bzr(['push', '--verbose', dirname + '3'], encoding='ascii')
 
274
 
 
275
        bzr(['push', '--verbose', '--create-prefix',
 
276
             dirname + '4/' + dirname + '5'])
 
277
        bzr(['push', '--verbose', '--create-prefix',
 
278
             dirname + '6/' + dirname + '7'], encoding='ascii')
277
279
 
278
280
    def test_renames(self):
279
281
        bzr = self.run_bzr_decode
280
282
 
281
283
        fname = self.info['filename'] + '2'
282
 
        bzr('mv', 'a', fname)
 
284
        bzr(['mv', 'a', fname])
283
285
        txt = bzr('renames')
284
286
        self.assertEqual(u'a => %s\n' % fname, txt)
285
287
 
289
291
        bzr = self.run_bzr_decode
290
292
 
291
293
        fname = self.info['filename']
292
 
        txt = bzr('remove', fname, encoding='ascii')
 
294
        txt = bzr(['remove', fname], encoding='ascii')
293
295
 
294
296
    def test_remove_verbose(self):
295
297
        bzr = self.run_bzr_decode
296
298
 
297
299
        fname = self.info['filename']
298
 
        txt = bzr('remove', '--verbose', fname, encoding='ascii')
 
300
        txt = bzr(['remove', '--verbose', fname], encoding='ascii')
299
301
 
300
302
    def test_file_id(self):
301
303
        bzr = self.run_bzr_decode
302
304
 
303
305
        fname = self.info['filename']
304
 
        txt = bzr('file-id', fname)
 
306
        txt = bzr(['file-id', fname])
305
307
 
306
308
        # TODO: jam 20060106 We don't support non-ascii file ids yet, 
307
309
        #       so there is nothing which would fail in ascii encoding
308
310
        #       This *should* be retcode=3
309
 
        txt = bzr('file-id', fname, encoding='ascii')
 
311
        txt = bzr(['file-id', fname], encoding='ascii')
310
312
 
311
313
    def test_file_path(self):
312
314
        bzr = self.run_bzr_decode
322
324
        self.wt.rename_one(fname, path)
323
325
        self.wt.commit('moving things around')
324
326
 
325
 
        txt = bzr('file-path', path)
 
327
        txt = bzr(['file-path', path])
326
328
 
327
329
        # TODO: jam 20060106 We don't support non-ascii file ids yet, 
328
330
        #       so there is nothing which would fail in ascii encoding
329
331
        #       This *should* be retcode=3
330
 
        txt = bzr('file-path', path, encoding='ascii')
 
332
        txt = bzr(['file-path', path], encoding='ascii')
331
333
 
332
334
    def test_revision_history(self):
333
335
        bzr = self.run_bzr_decode
360
362
        txt = bzr('deleted')
361
363
        self.assertEqual(fname+'\n', txt)
362
364
 
363
 
        txt = bzr('deleted', '--show-ids')
 
365
        txt = bzr('deleted --show-ids')
364
366
        self.failUnless(txt.startswith(fname))
365
367
 
366
368
        # Deleted should fail if cannot decode
416
418
        self.assertNotEqual(-1, txt.find(self.info['committer']))
417
419
        self.assertNotEqual(-1, txt.find(self.info['message']))
418
420
 
419
 
        txt = bzr('log', '--verbose')
 
421
        txt = bzr('log --verbose')
420
422
        self.assertNotEqual(-1, txt.find(fname))
421
423
 
422
424
        # Make sure log doesn't fail even if we can't write out
423
 
        txt = bzr('log', '--verbose', encoding='ascii')
 
425
        txt = bzr('log --verbose', encoding='ascii')
424
426
        self.assertEqual(-1, txt.find(fname))
425
427
        self.assertNotEqual(-1, txt.find(fname.encode('ascii', 'replace')))
426
428
 
428
430
        bzr = self.run_bzr_decode
429
431
 
430
432
        fname = self.info['filename']
431
 
        txt = bzr('touching-revisions', fname)
 
433
        txt = bzr(['touching-revisions', fname])
432
434
        self.assertEqual(u'     3 added %s\n' % (fname,), txt)
433
435
 
434
436
        fname2 = self.info['filename'] + '2'
435
437
        self.wt.rename_one(fname, fname2)
436
438
        self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
437
439
 
438
 
        txt = bzr('touching-revisions', fname2)
 
440
        txt = bzr(['touching-revisions', fname2])
439
441
        expected_txt = (u'     3 added %s\n' 
440
442
                        u'     4 renamed %s => %s\n'
441
443
                        % (fname, fname, fname2))
442
444
        self.assertEqual(expected_txt, txt)
443
445
 
444
 
        bzr('touching-revisions', fname2, encoding='ascii', retcode=3)
 
446
        bzr(['touching-revisions', fname2], encoding='ascii', retcode=3)
445
447
 
446
448
    def test_ls(self):
447
449
        bzr = self.run_bzr_decode
449
451
        txt = bzr('ls')
450
452
        self.assertEqual(sorted(['a', 'b', self.info['filename']]),
451
453
                         sorted(txt.splitlines()))
452
 
        txt = bzr('ls', '--null')
 
454
        txt = bzr('ls --null')
453
455
        self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
454
456
                         sorted(txt.split('\0')))
455
457
 
456
458
        txt = bzr('ls', encoding='ascii', retcode=3)
457
 
        txt = bzr('ls', '--null', encoding='ascii', retcode=3)
 
459
        txt = bzr('ls --null', encoding='ascii', retcode=3)
458
460
 
459
461
    def test_unknowns(self):
460
462
        bzr = self.run_bzr_decode
480
482
 
481
483
        check_unknowns([fname2])
482
484
 
483
 
        bzr('ignore', './' + fname2)
 
485
        bzr(['ignore', './' + fname2])
484
486
        # After 'ignore' you must re-open the working tree
485
487
        self.wt = self.wt.bzrdir.open_workingtree()
486
488
        check_unknowns([])
491
493
 
492
494
        # Ignore should not care what the encoding is
493
495
        # (right now it doesn't print anything)
494
 
        bzr('ignore', fname3, encoding='ascii')
 
496
        bzr(['ignore', fname3], encoding='ascii')
495
497
        self.wt = self.wt.bzrdir.open_workingtree()
496
498
        check_unknowns([])
497
499
 
498
500
        # Now try a wildcard match
499
501
        fname4 = self.info['filename'] + '4.txt'
500
502
        open(fname4, 'wb').write('unknown 4\n')
501
 
        bzr('ignore', '*.txt')
 
503
        bzr('ignore *.txt')
502
504
        self.wt = self.wt.bzrdir.open_workingtree()
503
505
        check_unknowns([])
504
506
 
505
507
        # and a different wildcard that matches everything
506
508
        os.remove('.bzrignore')
507
 
        bzr('ignore', self.info['filename'] + '*')
 
509
        bzr(['ignore', self.info['filename'] + '*'])
508
510
        self.wt = self.wt.bzrdir.open_workingtree()
509
511
        check_unknowns([])
510
512
 
512
514
        bzr = self.run_bzr_decode
513
515
 
514
516
        # create empty tree as reference for missing
515
 
        self.run_bzr('init', 'empty-tree')
 
517
        self.run_bzr('init empty-tree')
516
518
 
517
519
        msg = self.info['message']
518
520
 
519
 
        txt = bzr('missing', 'empty-tree', retcode=1)
 
521
        txt = bzr('missing empty-tree', retcode=1)
520
522
        self.assertNotEqual(-1, txt.find(self.info['committer']))
521
523
        self.assertNotEqual(-1, txt.find(msg))
522
524
 
523
525
        # Make sure missing doesn't fail even if we can't write out
524
 
        txt = bzr('missing', 'empty-tree', encoding='ascii', retcode=1)
 
526
        txt = bzr('missing empty-tree', encoding='ascii', retcode=1)
525
527
        self.assertEqual(-1, txt.find(msg))
526
528
        self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))