/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_status.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

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 bzrlib import (
 
29
from ... import (
32
30
    bzrdir,
33
31
    conflicts,
34
32
    errors,
35
33
    osutils,
36
34
    status,
37
35
    )
38
 
import bzrlib.branch
39
 
from bzrlib.osutils import pathjoin
40
 
from bzrlib.revisionspec import RevisionSpec
41
 
from bzrlib.status import show_tree_status
42
 
from bzrlib.tests import TestCaseWithTransport, TestSkipped
43
 
from bzrlib.workingtree import WorkingTree
 
36
import breezy.branch
 
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):
51
52
        # post_status hook handler for the test.
52
53
        status.hooks.install_named_hook('post_status',
53
54
            status._show_shelve_summary,
54
 
            'bzr status')
 
55
            'brz status')
55
56
 
56
57
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
57
58
        revision=None, short=False, pending=True, verbose=False):
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())
361
359
        # Okay, everything's looking good with the existent files.
362
360
        # Let's see what happens when we throw in non-existent files.
363
361
 
364
 
        # bzr st [--short] NONEXISTENT '
 
362
        # brz st [--short] NONEXISTENT '
365
363
        expected = [
366
364
          'nonexistent:\n',
367
365
          '  NONEXISTENT\n',
380
378
                              'NONEXISTENT.*')
381
379
 
382
380
    def test_status_nonexistent_file_with_others(self):
383
 
        # bzr st [--short] NONEXISTENT ...others..
 
381
        # brz st [--short] NONEXISTENT ...others..
384
382
        wt = self._prepare_nonexistent()
385
383
        expected = [
386
384
          'removed:\n',
413
411
                              'NONEXISTENT.*')
414
412
 
415
413
    def test_status_multiple_nonexistent_files(self):
416
 
        # bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
 
414
        # brz st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
417
415
        wt = self._prepare_nonexistent()
418
416
        expected = [
419
417
          'removed:\n',
448
446
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
449
447
 
450
448
    def test_status_nonexistent_file_with_unversioned(self):
451
 
        # bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
 
449
        # brz st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
452
450
        wt = self._prepare_nonexistent()
453
451
        expected = [
454
452
          'removed:\n',
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)
503
500
            # before run another commands we should unlock tree
504
501
            tree.unlock()
505
502
        out, err = self.run_bzr('status')
506
 
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
 
503
        self.assertEqual("working tree is out of date, run 'brz update'\n",
507
504
                         err)
508
505
 
509
506
    def test_status_on_ignored(self):
566
563
        self.assertStatus([
567
564
                'added:\n',
568
565
                '  bye.c\n',
569
 
                '1 shelf exists. See "bzr shelve --list" for details.\n',
 
566
                '1 shelf exists. See "brz shelve --list" for details.\n',
570
567
            ],
571
568
            wt)
572
569
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
577
574
                'added:\n',
578
575
                '  eggs.c\n',
579
576
                '  spam.c\n',
580
 
                '2 shelves exist. See "bzr shelve --list" for details.\n',
 
577
                '2 shelves exist. See "brz shelve --list" for details.\n',
581
578
            ],
582
579
            wt)
583
580
        self.assertStatus([