/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 breezy/tests/blackbox/test_status.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
interface later, they will be non blackbox tests.
23
23
"""
24
24
 
25
 
from cStringIO import StringIO
26
25
import codecs
27
26
from os import mkdir, chdir, rmdir, unlink
28
27
import sys
29
 
from tempfile import TemporaryFile
30
28
 
31
 
from breezy import (
 
29
from ... import (
32
30
    bzrdir,
33
31
    conflicts,
34
32
    errors,
36
34
    status,
37
35
    )
38
36
import breezy.branch
39
 
from breezy.osutils import pathjoin
40
 
from breezy.revisionspec import RevisionSpec
41
 
from breezy.status import show_tree_status
42
 
from breezy.tests import TestCaseWithTransport, TestSkipped
43
 
from breezy.workingtree import WorkingTree
 
37
from ...osutils import pathjoin
 
38
from ...revisionspec import RevisionSpec
 
39
from ...sixish import (
 
40
    BytesIO,
 
41
    )
 
42
from ...status import show_tree_status
 
43
from .. import TestCaseWithTransport, TestSkipped
 
44
from ...workingtree import WorkingTree
44
45
 
45
46
 
46
47
class BranchStatus(TestCaseWithTransport):
66
67
 
67
68
    def status_string(self, wt, specific_files=None, revision=None,
68
69
        short=False, pending=True, verbose=False):
69
 
        # use a real file rather than StringIO because it doesn't handle
70
 
        # Unicode very well.
71
 
        tof = codecs.getwriter('utf-8')(TemporaryFile())
72
 
        show_tree_status(wt, specific_files=specific_files, to_file=tof,
 
70
        uio = self.make_utf8_encoded_stringio()
 
71
        show_tree_status(wt, specific_files=specific_files, to_file=uio,
73
72
                revision=revision, short=short, show_pending=pending,
74
73
                verbose=verbose)
75
 
        tof.seek(0)
76
 
        return tof.read().decode('utf-8')
 
74
        return uio.getvalue().decode('utf-8')
77
75
 
78
76
    def test_branch_status(self):
79
77
        """Test basic branch status"""
239
237
                ],
240
238
                wt, short=True)
241
239
 
242
 
        tof = StringIO()
 
240
        tof = BytesIO()
243
241
        self.assertRaises(errors.PathsDoNotExist,
244
242
                          show_tree_status,
245
243
                          wt, specific_files=['bye.c','test.c','absent.c'],
246
244
                          to_file=tof)
247
245
 
248
 
        tof = StringIO()
 
246
        tof = BytesIO()
249
247
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
250
248
        tof.seek(0)
251
249
        self.assertEqual(tof.readlines(),
252
250
                          ['unknown:\n',
253
251
                           '  directory/hello.c\n'
254
252
                           ])
255
 
        tof = StringIO()
 
253
        tof = BytesIO()
256
254
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
257
255
                         short=True)
258
256
        tof.seek(0)
259
257
        self.assertEqual(tof.readlines(), ['?   directory/hello.c\n'])
260
258
 
261
 
        tof = StringIO()
 
259
        tof = BytesIO()
262
260
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
263
261
        tof.seek(0)
264
262
        self.assertEqual(tof.readlines(),
265
263
                          ['unknown:\n',
266
264
                           '  dir2/\n'
267
265
                           ])
268
 
        tof = StringIO()
 
266
        tof = BytesIO()
269
267
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
270
268
        tof.seek(0)
271
269
        self.assertEqual(tof.readlines(), ['?   dir2/\n'])
272
270
 
273
 
        tof = StringIO()
 
271
        tof = BytesIO()
274
272
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
275
273
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
276
274
                         short=True, revision=revs)
277
275
        tof.seek(0)
278
276
        self.assertEqual(tof.readlines(), ['+N  test.c\n'])
279
277
 
280
 
        tof = StringIO()
 
278
        tof = BytesIO()
281
279
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
282
280
        tof.seek(0)
283
281
        self.assertEqual(tof.readlines(),
284
282
                          ['missing:\n',
285
283
                           '  missing.c\n'])
286
284
 
287
 
        tof = StringIO()
 
285
        tof = BytesIO()
288
286
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
289
287
                         short=True)
290
288
        tof.seek(0)
298
296
        tree.commit('added dir2')
299
297
        tree.set_conflicts(conflicts.ConflictList(
300
298
            [conflicts.ContentsConflict('foo')]))
301
 
        tof = StringIO()
 
299
        tof = BytesIO()
302
300
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
303
301
        self.assertEqualDiff('', tof.getvalue())
304
302
        tree.set_conflicts(conflicts.ConflictList(
305
303
            [conflicts.ContentsConflict('dir2')]))
306
 
        tof = StringIO()
 
304
        tof = BytesIO()
307
305
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
308
306
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
309
307
                             tof.getvalue())
310
308
 
311
309
        tree.set_conflicts(conflicts.ConflictList(
312
310
            [conflicts.ContentsConflict('dir2/file1')]))
313
 
        tof = StringIO()
 
311
        tof = BytesIO()
314
312
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
315
313
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
316
314
                             tof.getvalue())
470
468
        self.assertContainsRe(err,
471
469
                              r'.*ERROR: Path\(s\) do not exist: '
472
470
                              'NONEXISTENT.*')
473
 
        expected = [
 
471
        expected = sorted([
474
472
          '+N  FILE_Q\n',
475
473
          '?   UNVERSIONED_BUT_EXISTING\n',
476
474
          ' D  FILE_E\n',
477
475
          ' M  FILE_C\n',
478
476
          ' M  FILE_B\n',
479
477
          'X   NONEXISTENT\n',
480
 
          ]
481
 
        expected.sort()
 
478
          ])
482
479
        out, err = self.run_bzr('status --short NONEXISTENT '
483
480
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
484
481
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)