/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: Martin
  • Date: 2017-06-05 20:48:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6658.
  • Revision ID: gzlist@googlemail.com-20170605204831-20accykspjcrx0a8
Apply 2to3 dict fixer and clean up resulting mess using view helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
    )
37
 
import bzrlib.branch
38
 
from bzrlib.osutils import pathjoin
39
 
from bzrlib.revisionspec import RevisionSpec
40
 
from bzrlib.status import show_tree_status
41
 
from bzrlib.tests import TestCaseWithTransport, TestSkipped
42
 
from bzrlib.workingtree import WorkingTree
 
34
    status,
 
35
    )
 
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
43
45
 
44
46
 
45
47
class BranchStatus(TestCaseWithTransport):
46
48
 
47
 
    def assertStatus(self, expected_lines, working_tree,
 
49
    def setUp(self):
 
50
        super(BranchStatus, self).setUp()
 
51
        # As TestCase.setUp clears all hooks, we install this default
 
52
        # post_status hook handler for the test.
 
53
        status.hooks.install_named_hook('post_status',
 
54
            status._show_shelve_summary,
 
55
            'brz status')
 
56
 
 
57
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
48
58
        revision=None, short=False, pending=True, verbose=False):
49
59
        """Run status in working_tree and look for output.
50
60
 
51
61
        :param expected_lines: The lines to look for.
52
62
        :param working_tree: The tree to run status in.
53
63
        """
54
 
        output_string = self.status_string(working_tree, revision, short,
 
64
        output_string = self.status_string(working_tree, specific_files, revision, short,
55
65
                pending, verbose)
56
66
        self.assertEqual(expected_lines, output_string.splitlines(True))
57
67
 
58
 
    def status_string(self, wt, revision=None, short=False, pending=True,
59
 
        verbose=False):
60
 
        # use a real file rather than StringIO because it doesn't handle
61
 
        # Unicode very well.
62
 
        tof = codecs.getwriter('utf-8')(TemporaryFile())
63
 
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
64
 
                show_pending=pending, verbose=verbose)
65
 
        tof.seek(0)
66
 
        return tof.read().decode('utf-8')
 
68
    def status_string(self, wt, specific_files=None, revision=None,
 
69
        short=False, pending=True, verbose=False):
 
70
        uio = self.make_utf8_encoded_stringio()
 
71
        show_tree_status(wt, specific_files=specific_files, to_file=uio,
 
72
                revision=revision, short=short, show_pending=pending,
 
73
                verbose=verbose)
 
74
        return uio.getvalue().decode('utf-8')
67
75
 
68
76
    def test_branch_status(self):
69
77
        """Test basic branch status"""
178
186
        wt2.merge_from_branch(wt.branch)
179
187
        message = self.status_string(wt2, verbose=True)
180
188
        self.assertStartsWith(message, "pending merges:\n")
181
 
        self.assert_("Empty commit 3" in message)
 
189
        self.assertTrue("Empty commit 3" in message)
182
190
        self.assertEndsWith(message, "...\n")
183
191
 
184
192
    def test_tree_status_ignores(self):
202
210
        wt = self.make_branch_and_tree('.')
203
211
        b = wt.branch
204
212
 
205
 
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
 
213
        self.build_tree(['directory/','directory/hello.c',
 
214
                         'bye.c','test.c','dir2/',
 
215
                         'missing.c'])
206
216
        wt.add('directory')
207
217
        wt.add('test.c')
208
218
        wt.commit('testing')
 
219
        wt.add('missing.c')
 
220
        unlink('missing.c')
209
221
 
210
222
        self.assertStatus([
 
223
                'missing:\n',
 
224
                '  missing.c\n',
211
225
                'unknown:\n',
212
226
                '  bye.c\n',
213
227
                '  dir2/\n',
218
232
        self.assertStatus([
219
233
                '?   bye.c\n',
220
234
                '?   dir2/\n',
 
235
                '+!  missing.c\n',
221
236
                '?   directory/hello.c\n'
222
237
                ],
223
238
                wt, short=True)
224
239
 
225
 
        tof = StringIO()
 
240
        tof = BytesIO()
226
241
        self.assertRaises(errors.PathsDoNotExist,
227
242
                          show_tree_status,
228
243
                          wt, specific_files=['bye.c','test.c','absent.c'],
229
244
                          to_file=tof)
230
245
 
231
 
        tof = StringIO()
 
246
        tof = BytesIO()
232
247
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
233
248
        tof.seek(0)
234
 
        self.assertEquals(tof.readlines(),
 
249
        self.assertEqual(tof.readlines(),
235
250
                          ['unknown:\n',
236
251
                           '  directory/hello.c\n'
237
252
                           ])
238
 
        tof = StringIO()
 
253
        tof = BytesIO()
239
254
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
240
255
                         short=True)
241
256
        tof.seek(0)
242
 
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
 
257
        self.assertEqual(tof.readlines(), ['?   directory/hello.c\n'])
243
258
 
244
 
        tof = StringIO()
 
259
        tof = BytesIO()
245
260
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
246
261
        tof.seek(0)
247
 
        self.assertEquals(tof.readlines(),
 
262
        self.assertEqual(tof.readlines(),
248
263
                          ['unknown:\n',
249
264
                           '  dir2/\n'
250
265
                           ])
251
 
        tof = StringIO()
 
266
        tof = BytesIO()
252
267
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
253
268
        tof.seek(0)
254
 
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
 
269
        self.assertEqual(tof.readlines(), ['?   dir2/\n'])
255
270
 
256
 
        tof = StringIO()
 
271
        tof = BytesIO()
257
272
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
258
273
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
259
274
                         short=True, revision=revs)
260
275
        tof.seek(0)
261
 
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
 
276
        self.assertEqual(tof.readlines(), ['+N  test.c\n'])
 
277
 
 
278
        tof = BytesIO()
 
279
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
 
280
        tof.seek(0)
 
281
        self.assertEqual(tof.readlines(),
 
282
                          ['missing:\n',
 
283
                           '  missing.c\n'])
 
284
 
 
285
        tof = BytesIO()
 
286
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
 
287
                         short=True)
 
288
        tof.seek(0)
 
289
        self.assertEqual(tof.readlines(),
 
290
                          ['+!  missing.c\n'])
262
291
 
263
292
    def test_specific_files_conflicts(self):
264
293
        tree = self.make_branch_and_tree('.')
267
296
        tree.commit('added dir2')
268
297
        tree.set_conflicts(conflicts.ConflictList(
269
298
            [conflicts.ContentsConflict('foo')]))
270
 
        tof = StringIO()
 
299
        tof = BytesIO()
271
300
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
272
301
        self.assertEqualDiff('', tof.getvalue())
273
302
        tree.set_conflicts(conflicts.ConflictList(
274
303
            [conflicts.ContentsConflict('dir2')]))
275
 
        tof = StringIO()
 
304
        tof = BytesIO()
276
305
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
277
306
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
278
307
                             tof.getvalue())
279
308
 
280
309
        tree.set_conflicts(conflicts.ConflictList(
281
310
            [conflicts.ContentsConflict('dir2/file1')]))
282
 
        tof = StringIO()
 
311
        tof = BytesIO()
283
312
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
284
313
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
285
314
                             tof.getvalue())
294
323
        wt.add('FILE_D')
295
324
        wt.add('FILE_E')
296
325
        wt.commit('Create five empty files.')
297
 
        open('FILE_B', 'w').write('Modification to file FILE_B.')
298
 
        open('FILE_C', 'w').write('Modification to file FILE_C.')
 
326
        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
 
327
        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
299
328
        unlink('FILE_E')  # FILE_E will be versioned but missing
300
 
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
 
329
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
301
330
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
302
331
        open('UNVERSIONED_BUT_EXISTING', 'w')
303
332
        return wt
330
359
        # Okay, everything's looking good with the existent files.
331
360
        # Let's see what happens when we throw in non-existent files.
332
361
 
333
 
        # bzr st [--short] NONEXISTENT '
 
362
        # brz st [--short] NONEXISTENT '
334
363
        expected = [
335
364
          'nonexistent:\n',
336
365
          '  NONEXISTENT\n',
349
378
                              'NONEXISTENT.*')
350
379
 
351
380
    def test_status_nonexistent_file_with_others(self):
352
 
        # bzr st [--short] NONEXISTENT ...others..
 
381
        # brz st [--short] NONEXISTENT ...others..
353
382
        wt = self._prepare_nonexistent()
354
383
        expected = [
355
384
          'removed:\n',
382
411
                              'NONEXISTENT.*')
383
412
 
384
413
    def test_status_multiple_nonexistent_files(self):
385
 
        # bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
 
414
        # brz st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
386
415
        wt = self._prepare_nonexistent()
387
416
        expected = [
388
417
          'removed:\n',
417
446
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
418
447
 
419
448
    def test_status_nonexistent_file_with_unversioned(self):
420
 
        # 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
421
450
        wt = self._prepare_nonexistent()
422
451
        expected = [
423
452
          'removed:\n',
439
468
        self.assertContainsRe(err,
440
469
                              r'.*ERROR: Path\(s\) do not exist: '
441
470
                              'NONEXISTENT.*')
442
 
        expected = [
 
471
        expected = sorted([
443
472
          '+N  FILE_Q\n',
444
473
          '?   UNVERSIONED_BUT_EXISTING\n',
445
474
          ' D  FILE_E\n',
446
475
          ' M  FILE_C\n',
447
476
          ' M  FILE_B\n',
448
477
          'X   NONEXISTENT\n',
449
 
          ]
 
478
          ])
450
479
        out, err = self.run_bzr('status --short NONEXISTENT '
451
480
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
452
481
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
453
 
        self.assertEqual(expected, out.splitlines(True))
 
482
        actual = out.splitlines(True)
 
483
        actual.sort()
 
484
        self.assertEqual(expected, actual)
454
485
        self.assertContainsRe(err,
455
486
                              r'.*ERROR: Path\(s\) do not exist: '
456
487
                              'NONEXISTENT.*')
469
500
            # before run another commands we should unlock tree
470
501
            tree.unlock()
471
502
        out, err = self.run_bzr('status')
472
 
        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",
473
504
                         err)
474
505
 
475
506
    def test_status_on_ignored(self):
520
551
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
521
552
        self.assertEqual('', out)
522
553
 
 
554
    def test_status_with_shelves(self):
 
555
        """Ensure that _show_shelve_summary handler works.
 
556
        """
 
557
        wt = self.make_branch_and_tree('.')
 
558
        self.build_tree(['hello.c'])
 
559
        wt.add('hello.c')
 
560
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
 
561
        self.build_tree(['bye.c'])
 
562
        wt.add('bye.c')
 
563
        self.assertStatus([
 
564
                'added:\n',
 
565
                '  bye.c\n',
 
566
                '1 shelf exists. See "brz shelve --list" for details.\n',
 
567
            ],
 
568
            wt)
 
569
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
 
570
        self.build_tree(['eggs.c', 'spam.c'])
 
571
        wt.add('eggs.c')
 
572
        wt.add('spam.c')
 
573
        self.assertStatus([
 
574
                'added:\n',
 
575
                '  eggs.c\n',
 
576
                '  spam.c\n',
 
577
                '2 shelves exist. See "brz shelve --list" for details.\n',
 
578
            ],
 
579
            wt)
 
580
        self.assertStatus([
 
581
                'added:\n',
 
582
                '  spam.c\n',
 
583
            ],
 
584
            wt,
 
585
            specific_files=['spam.c'])
 
586
 
523
587
 
524
588
class CheckoutStatus(BranchStatus):
525
589
 
531
595
    def make_branch_and_tree(self, relpath):
532
596
        source = self.make_branch(pathjoin('..', relpath))
533
597
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
534
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
535
 
            target_branch=source)
 
598
        checkout.set_branch_reference(source)
536
599
        return checkout.create_workingtree()
537
600
 
538
601
 
561
624
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
562
625
                                      "unknown:\n  world.txt\n")
563
626
        result2 = self.run_bzr("status -r 0..")[0]
564
 
        self.assertEquals(result2, result)
 
627
        self.assertEqual(result2, result)
565
628
 
566
629
    def test_status_short(self):
567
630
        tree = self.make_branch_and_tree('.')
579
642
        self.assertContainsRe(result, "[+]N  hello.txt\n")
580
643
 
581
644
        self.build_tree(['world.txt'])
582
 
        result = self.run_bzr("status --short -r 0")[0]
 
645
        result = self.run_bzr("status -S -r 0")[0]
583
646
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
584
647
                                      "[?]   world.txt\n")
585
 
        result2 = self.run_bzr("status --short -r 0..")[0]
586
 
        self.assertEquals(result2, result)
 
648
        result2 = self.run_bzr("status -S -r 0..")[0]
 
649
        self.assertEqual(result2, result)
587
650
 
588
651
    def test_status_versioned(self):
589
652
        tree = self.make_branch_and_tree('.')
605
668
        self.assertContainsRe(result, "added:\n  hello.txt\n")
606
669
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
607
670
        result2 = self.run_bzr("status --versioned -r 0..")[0]
608
 
        self.assertEquals(result2, result)
 
671
        self.assertEqual(result2, result)
609
672
 
610
673
    def test_status_SV(self):
611
674
        tree = self.make_branch_and_tree('.')
627
690
        self.assertContainsRe(result, "[+]N  hello.txt\n")
628
691
 
629
692
        result2 = self.run_bzr("status -SV -r 0..")[0]
630
 
        self.assertEquals(result2, result)
 
693
        self.assertEqual(result2, result)
631
694
 
632
695
    def assertStatusContains(self, pattern, short=False):
633
696
        """Run status, and assert it contains the given pattern"""
683
746
 
684
747
        self.run_bzr('merge ../b', working_dir='a')
685
748
        out, err = self.run_bzr('status --no-pending', working_dir='a')
686
 
        self.assertEquals(out, "added:\n  b\n")
 
749
        self.assertEqual(out, "added:\n  b\n")
687
750
 
688
751
    def test_pending_specific_files(self):
689
752
        """With a specific file list, pending merges are not shown."""
704
767
 
705
768
class TestStatusEncodings(TestCaseWithTransport):
706
769
 
707
 
    def setUp(self):
708
 
        TestCaseWithTransport.setUp(self)
709
 
        self.user_encoding = osutils._cached_user_encoding
710
 
        self.stdout = sys.stdout
711
 
 
712
 
    def tearDown(self):
713
 
        osutils._cached_user_encoding = self.user_encoding
714
 
        sys.stdout = self.stdout
715
 
        TestCaseWithTransport.tearDown(self)
716
 
 
717
770
    def make_uncommitted_tree(self):
718
771
        """Build a branch with uncommitted unicode named changes in the cwd."""
719
772
        working_tree = self.make_branch_and_tree(u'.')
727
780
        return working_tree
728
781
 
729
782
    def test_stdout_ascii(self):
730
 
        sys.stdout = StringIO()
731
 
        osutils._cached_user_encoding = 'ascii'
 
783
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
732
784
        working_tree = self.make_uncommitted_tree()
733
785
        stdout, stderr = self.run_bzr("status")
734
786
 
735
 
        self.assertEquals(stdout, """\
 
787
        self.assertEqual(stdout, """\
736
788
added:
737
789
  hell?
738
790
""")
739
791
 
740
792
    def test_stdout_latin1(self):
741
 
        sys.stdout = StringIO()
742
 
        osutils._cached_user_encoding = 'latin-1'
 
793
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
743
794
        working_tree = self.make_uncommitted_tree()
744
795
        stdout, stderr = self.run_bzr('status')
745
796
 
746
 
        self.assertEquals(stdout, u"""\
 
797
        self.assertEqual(stdout, u"""\
747
798
added:
748
799
  hell\u00d8
749
800
""".encode('latin-1'))