/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: Martin Pool
  • Date: 2007-09-21 06:02:45 UTC
  • mto: This revision was merged to the branch mainline in revision 2874.
  • Revision ID: mbp@sourcefrog.net-20070921060245-j6a3g6oxdbs1bdjn
Make run_bzr_decode undeprecated again, but put it in the particular test class
TestNonAscii that needs it.  Remove run_bzr(output_encoding) parameter.

run_bzr_decode now takes a specific parameter that says if we expect the
operation to fail with a UnicodeError, and we test for that in particular.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
48
47
        bzrlib.user_encoding = self._orig_encoding
49
48
        super(TestNonAscii, self).tearDown()
50
49
 
 
50
    def run_bzr_decode(self, args, encoding=None, fail=False, retcode=None):
 
51
        """Run bzr and decode the output into a particular encoding.
 
52
 
 
53
        Returns a string containing the stdout output from bzr.
 
54
 
 
55
        :param fail: If true, the operation is expected to fail with 
 
56
            a UnicodeError.
 
57
        """
 
58
        if encoding is None:
 
59
            encoding = bzrlib.user_encoding
 
60
        try:
 
61
            out = self.run_bzr(args, output_encoding=encoding, encoding=encoding,
 
62
                retcode=retcode)[0]
 
63
            return out.decode(encoding)
 
64
        except UnicodeError, e:
 
65
            if not fail:
 
66
                raise
 
67
        else:
 
68
            # This command, run from the regular command line, will give a
 
69
            # traceback to the user.  That's not really good for a situation
 
70
            # that can be provoked just by the interaction of their input data
 
71
            # and locale, as some of these are.  What would be better?
 
72
            if fail:
 
73
                self.fail("Expected UnicodeError not raised")
 
74
 
51
75
    def create_base(self):
52
76
        bzr = self.run_bzr
53
77
 
89
113
        bzr = self.run_bzr_decode
90
114
 
91
115
        open(self.info['filename'], 'ab').write('added something\n')
92
 
        txt = bzr('status')
 
116
        txt = self.run_bzr_decode('status')
93
117
        self.assertEqual(u'modified:\n  %s\n' % (self.info['filename'],), txt)
94
118
 
95
119
        txt = bzr('status', encoding='ascii')
136
160
        txt = bzr(['relpath', self.info['filename']])
137
161
        self.assertEqual(self.info['filename'] + '\n', txt)
138
162
 
139
 
        bzr(['relpath', self.info['filename']], encoding='ascii', retcode=3)
 
163
        bzr(['relpath', self.info['filename']], encoding='ascii', fail=True)
140
164
 
141
165
    def test_inventory(self):
142
166
        bzr = self.run_bzr_decode
146
170
                         txt.splitlines())
147
171
 
148
172
        # inventory should fail if unable to encode
149
 
        bzr('inventory', encoding='ascii', retcode=3)
 
173
        bzr('inventory', encoding='ascii', fail=True)
150
174
 
151
175
        # We don't really care about the ids themselves,
152
176
        # but the command shouldn't fail
177
201
        dirname = self.info['directory']
178
202
 
179
203
        # fname1 already exists
180
 
        bzr(['mv', 'a', fname1], retcode=3)
 
204
        bzr(['mv', 'a', fname1], fail=True)
181
205
 
182
206
        txt = bzr(['mv', 'a', fname2])
183
207
        self.assertEqual(u'a => %s\n' % fname2, txt)
285
309
        txt = bzr('renames')
286
310
        self.assertEqual(u'a => %s\n' % fname, txt)
287
311
 
288
 
        bzr('renames', retcode=3, encoding='ascii')
 
312
        bzr('renames', fail=True, encoding='ascii')
289
313
 
290
314
    def test_remove(self):
291
315
        bzr = self.run_bzr_decode
368
392
        # Deleted should fail if cannot decode
369
393
        # Because it is giving the exact paths
370
394
        # which might be used by a front end
371
 
        bzr('deleted', encoding='ascii', retcode=3)
 
395
        bzr('deleted', encoding='ascii', fail=True)
372
396
 
373
397
    def test_modified(self):
374
398
        bzr = self.run_bzr_decode
379
403
        txt = bzr('modified')
380
404
        self.assertEqual(fname+'\n', txt)
381
405
 
382
 
        bzr('modified', encoding='ascii', retcode=3)
 
406
        bzr('modified', encoding='ascii', fail=True)
383
407
 
384
408
    def test_added(self):
385
409
        bzr = self.run_bzr_decode
391
415
        txt = bzr('added')
392
416
        self.assertEqual(fname+'\n', txt)
393
417
 
394
 
        bzr('added', encoding='ascii', retcode=3)
 
418
        bzr('added', encoding='ascii', fail=True)
395
419
 
396
420
    def test_root(self):
397
421
        bzr = self.run_bzr_decode
407
431
        txt = bzr('root')
408
432
        self.failUnless(txt.endswith(dirname+'\n'))
409
433
 
410
 
        txt = bzr('root', encoding='ascii', retcode=3)
 
434
        txt = bzr('root', encoding='ascii', fail=True)
411
435
 
412
436
    def test_log(self):
413
437
        bzr = self.run_bzr_decode
443
467
                        % (fname, fname, fname2))
444
468
        self.assertEqual(expected_txt, txt)
445
469
 
446
 
        bzr(['touching-revisions', fname2], encoding='ascii', retcode=3)
 
470
        bzr(['touching-revisions', fname2], encoding='ascii', fail=True)
447
471
 
448
472
    def test_ls(self):
449
473
        bzr = self.run_bzr_decode
455
479
        self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
456
480
                         sorted(txt.split('\0')))
457
481
 
458
 
        txt = bzr('ls', encoding='ascii', retcode=3)
459
 
        txt = bzr('ls --null', encoding='ascii', retcode=3)
 
482
        txt = bzr('ls', encoding='ascii', fail=True)
 
483
        txt = bzr('ls --null', encoding='ascii', fail=True)
460
484
 
461
485
    def test_unknowns(self):
462
486
        bzr = self.run_bzr_decode
469
493
        txt = bzr('unknowns')
470
494
        self.assertEqual(u'"%s"\n' % (fname,), txt)
471
495
 
472
 
        bzr('unknowns', encoding='ascii', retcode=3)
 
496
        bzr('unknowns', encoding='ascii', fail=True)
473
497
 
474
498
    def test_ignore(self):
475
499
        bzr = self.run_bzr_decode