~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patrick Regan
  • Date: 2009-12-02 20:34:07 UTC
  • mto: (4852.3.3 2.1.0b4-doc-updates)
  • mto: This revision was merged to the branch mainline in revision 4856.
  • Revision ID: patrick.rubbs.regan@gmail.com-20091202203407-fjd0mshgn3j3foel
Removed trailing whitespace from files in doc directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
33
33
    conflicts,
34
34
    errors,
35
35
    osutils,
36
 
    status,
37
36
    )
38
37
import bzrlib.branch
39
38
from bzrlib.osutils import pathjoin
45
44
 
46
45
class BranchStatus(TestCaseWithTransport):
47
46
 
48
 
    def setUp(self):
49
 
        super(BranchStatus, self).setUp()
50
 
        # As TestCase.setUp clears all hooks, we install this default
51
 
        # post_status hook handler for the test.
52
 
        status.hooks.install_named_hook('post_status',
53
 
            status._show_shelve_summary,
54
 
            'bzr status')
55
 
 
56
 
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
 
47
    def assertStatus(self, expected_lines, working_tree,
57
48
        revision=None, short=False, pending=True, verbose=False):
58
49
        """Run status in working_tree and look for output.
59
50
 
60
51
        :param expected_lines: The lines to look for.
61
52
        :param working_tree: The tree to run status in.
62
53
        """
63
 
        output_string = self.status_string(working_tree, specific_files, revision, short,
 
54
        output_string = self.status_string(working_tree, revision, short,
64
55
                pending, verbose)
65
56
        self.assertEqual(expected_lines, output_string.splitlines(True))
66
57
 
67
 
    def status_string(self, wt, specific_files=None, revision=None,
68
 
        short=False, pending=True, verbose=False):
 
58
    def status_string(self, wt, revision=None, short=False, pending=True,
 
59
        verbose=False):
69
60
        # use a real file rather than StringIO because it doesn't handle
70
61
        # Unicode very well.
71
62
        tof = codecs.getwriter('utf-8')(TemporaryFile())
72
 
        show_tree_status(wt, specific_files=specific_files, to_file=tof,
73
 
                revision=revision, short=short, show_pending=pending,
74
 
                verbose=verbose)
 
63
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
 
64
                show_pending=pending, verbose=verbose)
75
65
        tof.seek(0)
76
66
        return tof.read().decode('utf-8')
77
67
 
188
178
        wt2.merge_from_branch(wt.branch)
189
179
        message = self.status_string(wt2, verbose=True)
190
180
        self.assertStartsWith(message, "pending merges:\n")
191
 
        self.assertTrue("Empty commit 3" in message)
 
181
        self.assert_("Empty commit 3" in message)
192
182
        self.assertEndsWith(message, "...\n")
193
183
 
194
184
    def test_tree_status_ignores(self):
212
202
        wt = self.make_branch_and_tree('.')
213
203
        b = wt.branch
214
204
 
215
 
        self.build_tree(['directory/','directory/hello.c',
216
 
                         'bye.c','test.c','dir2/',
217
 
                         'missing.c'])
 
205
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
218
206
        wt.add('directory')
219
207
        wt.add('test.c')
220
208
        wt.commit('testing')
221
 
        wt.add('missing.c')
222
 
        unlink('missing.c')
223
209
 
224
210
        self.assertStatus([
225
 
                'missing:\n',
226
 
                '  missing.c\n',
227
211
                'unknown:\n',
228
212
                '  bye.c\n',
229
213
                '  dir2/\n',
234
218
        self.assertStatus([
235
219
                '?   bye.c\n',
236
220
                '?   dir2/\n',
237
 
                '+!  missing.c\n',
238
221
                '?   directory/hello.c\n'
239
222
                ],
240
223
                wt, short=True)
248
231
        tof = StringIO()
249
232
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
250
233
        tof.seek(0)
251
 
        self.assertEqual(tof.readlines(),
 
234
        self.assertEquals(tof.readlines(),
252
235
                          ['unknown:\n',
253
236
                           '  directory/hello.c\n'
254
237
                           ])
256
239
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
257
240
                         short=True)
258
241
        tof.seek(0)
259
 
        self.assertEqual(tof.readlines(), ['?   directory/hello.c\n'])
 
242
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
260
243
 
261
244
        tof = StringIO()
262
245
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
263
246
        tof.seek(0)
264
 
        self.assertEqual(tof.readlines(),
 
247
        self.assertEquals(tof.readlines(),
265
248
                          ['unknown:\n',
266
249
                           '  dir2/\n'
267
250
                           ])
268
251
        tof = StringIO()
269
252
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
270
253
        tof.seek(0)
271
 
        self.assertEqual(tof.readlines(), ['?   dir2/\n'])
 
254
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
272
255
 
273
256
        tof = StringIO()
274
257
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
275
258
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
276
259
                         short=True, revision=revs)
277
260
        tof.seek(0)
278
 
        self.assertEqual(tof.readlines(), ['+N  test.c\n'])
279
 
 
280
 
        tof = StringIO()
281
 
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
282
 
        tof.seek(0)
283
 
        self.assertEqual(tof.readlines(),
284
 
                          ['missing:\n',
285
 
                           '  missing.c\n'])
286
 
 
287
 
        tof = StringIO()
288
 
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
289
 
                         short=True)
290
 
        tof.seek(0)
291
 
        self.assertEqual(tof.readlines(),
292
 
                          ['+!  missing.c\n'])
 
261
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
293
262
 
294
263
    def test_specific_files_conflicts(self):
295
264
        tree = self.make_branch_and_tree('.')
325
294
        wt.add('FILE_D')
326
295
        wt.add('FILE_E')
327
296
        wt.commit('Create five empty files.')
328
 
        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
329
 
        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
 
297
        open('FILE_B', 'w').write('Modification to file FILE_B.')
 
298
        open('FILE_C', 'w').write('Modification to file FILE_C.')
330
299
        unlink('FILE_E')  # FILE_E will be versioned but missing
331
 
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
 
300
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
332
301
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
333
302
        open('UNVERSIONED_BUT_EXISTING', 'w')
334
303
        return wt
478
447
          ' M  FILE_B\n',
479
448
          'X   NONEXISTENT\n',
480
449
          ]
481
 
        expected.sort()
482
450
        out, err = self.run_bzr('status --short NONEXISTENT '
483
451
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
484
452
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
485
 
        actual = out.splitlines(True)
486
 
        actual.sort()
487
 
        self.assertEqual(expected, actual)
 
453
        self.assertEqual(expected, out.splitlines(True))
488
454
        self.assertContainsRe(err,
489
455
                              r'.*ERROR: Path\(s\) do not exist: '
490
456
                              'NONEXISTENT.*')
506
472
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
507
473
                         err)
508
474
 
509
 
    def test_status_on_ignored(self):
510
 
        """Tests branch status on an unversioned file which is considered ignored.
511
 
 
512
 
        See https://bugs.launchpad.net/bzr/+bug/40103
513
 
        """
514
 
        tree = self.make_branch_and_tree('.')
515
 
 
516
 
        self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
517
 
        result = self.run_bzr('status')[0]
518
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
519
 
        short_result = self.run_bzr('status --short')[0]
520
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
521
 
 
522
 
        result = self.run_bzr('status test1.c')[0]
523
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
524
 
        short_result = self.run_bzr('status --short test1.c')[0]
525
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
526
 
 
527
 
        result = self.run_bzr('status test1.c~')[0]
528
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
529
 
        short_result = self.run_bzr('status --short test1.c~')[0]
530
 
        self.assertContainsRe(short_result, "I   test1.c~\n")
531
 
 
532
 
        result = self.run_bzr('status test1.c~ test2.c~')[0]
533
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
534
 
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
535
 
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
536
 
 
537
 
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
538
 
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
539
 
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
540
 
        self.assertContainsRe(short_result, "\?   test1.c\nI   test1.c~\nI   test2.c~\n")
541
 
 
542
475
    def test_status_write_lock(self):
543
476
        """Test that status works without fetching history and
544
477
        having a write lock.
554
487
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
555
488
        self.assertEqual('', out)
556
489
 
557
 
    def test_status_with_shelves(self):
558
 
        """Ensure that _show_shelve_summary handler works.
559
 
        """
560
 
        wt = self.make_branch_and_tree('.')
561
 
        self.build_tree(['hello.c'])
562
 
        wt.add('hello.c')
563
 
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
564
 
        self.build_tree(['bye.c'])
565
 
        wt.add('bye.c')
566
 
        self.assertStatus([
567
 
                'added:\n',
568
 
                '  bye.c\n',
569
 
                '1 shelf exists. See "bzr shelve --list" for details.\n',
570
 
            ],
571
 
            wt)
572
 
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
573
 
        self.build_tree(['eggs.c', 'spam.c'])
574
 
        wt.add('eggs.c')
575
 
        wt.add('spam.c')
576
 
        self.assertStatus([
577
 
                'added:\n',
578
 
                '  eggs.c\n',
579
 
                '  spam.c\n',
580
 
                '2 shelves exist. See "bzr shelve --list" for details.\n',
581
 
            ],
582
 
            wt)
583
 
        self.assertStatus([
584
 
                'added:\n',
585
 
                '  spam.c\n',
586
 
            ],
587
 
            wt,
588
 
            specific_files=['spam.c'])
589
 
 
590
490
 
591
491
class CheckoutStatus(BranchStatus):
592
492
 
598
498
    def make_branch_and_tree(self, relpath):
599
499
        source = self.make_branch(pathjoin('..', relpath))
600
500
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
601
 
        checkout.set_branch_reference(source)
 
501
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
602
502
        return checkout.create_workingtree()
603
503
 
604
504
 
627
527
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
628
528
                                      "unknown:\n  world.txt\n")
629
529
        result2 = self.run_bzr("status -r 0..")[0]
630
 
        self.assertEqual(result2, result)
 
530
        self.assertEquals(result2, result)
631
531
 
632
532
    def test_status_short(self):
633
533
        tree = self.make_branch_and_tree('.')
645
545
        self.assertContainsRe(result, "[+]N  hello.txt\n")
646
546
 
647
547
        self.build_tree(['world.txt'])
648
 
        result = self.run_bzr("status -S -r 0")[0]
 
548
        result = self.run_bzr("status --short -r 0")[0]
649
549
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
650
550
                                      "[?]   world.txt\n")
651
 
        result2 = self.run_bzr("status -S -r 0..")[0]
652
 
        self.assertEqual(result2, result)
 
551
        result2 = self.run_bzr("status --short -r 0..")[0]
 
552
        self.assertEquals(result2, result)
653
553
 
654
554
    def test_status_versioned(self):
655
555
        tree = self.make_branch_and_tree('.')
671
571
        self.assertContainsRe(result, "added:\n  hello.txt\n")
672
572
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
673
573
        result2 = self.run_bzr("status --versioned -r 0..")[0]
674
 
        self.assertEqual(result2, result)
 
574
        self.assertEquals(result2, result)
675
575
 
676
576
    def test_status_SV(self):
677
577
        tree = self.make_branch_and_tree('.')
693
593
        self.assertContainsRe(result, "[+]N  hello.txt\n")
694
594
 
695
595
        result2 = self.run_bzr("status -SV -r 0..")[0]
696
 
        self.assertEqual(result2, result)
 
596
        self.assertEquals(result2, result)
697
597
 
698
 
    def assertStatusContains(self, pattern, short=False):
 
598
    def assertStatusContains(self, pattern):
699
599
        """Run status, and assert it contains the given pattern"""
700
 
        if short:
701
 
            result = self.run_bzr("status --short")[0]
702
 
        else:
703
 
            result = self.run_bzr("status")[0]
 
600
        result = self.run_bzr("status --short")[0]
704
601
        self.assertContainsRe(result, pattern)
705
602
 
706
 
    def test_kind_change_plain(self):
707
 
        tree = self.make_branch_and_tree('.')
708
 
        self.build_tree(['file'])
709
 
        tree.add('file')
710
 
        tree.commit('added file')
711
 
        unlink('file')
712
 
        self.build_tree(['file/'])
713
 
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
714
 
        tree.rename_one('file', 'directory')
715
 
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
716
 
                                  'modified:\n  directory/\n')
717
 
        rmdir('directory')
718
 
        self.assertStatusContains('removed:\n  file\n')
719
 
 
720
603
    def test_kind_change_short(self):
721
604
        tree = self.make_branch_and_tree('.')
722
605
        self.build_tree(['file'])
724
607
        tree.commit('added file')
725
608
        unlink('file')
726
609
        self.build_tree(['file/'])
727
 
        self.assertStatusContains('K  file => file/',
728
 
                                   short=True)
 
610
        self.assertStatusContains('K  file => file/')
729
611
        tree.rename_one('file', 'directory')
730
 
        self.assertStatusContains('RK  file => directory/',
731
 
                                   short=True)
 
612
        self.assertStatusContains('RK  file => directory/')
732
613
        rmdir('directory')
733
 
        self.assertStatusContains('RD  file => directory',
734
 
                                   short=True)
 
614
        self.assertStatusContains('RD  file => directory')
735
615
 
736
616
    def test_status_illegal_revision_specifiers(self):
737
617
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
749
629
 
750
630
        self.run_bzr('merge ../b', working_dir='a')
751
631
        out, err = self.run_bzr('status --no-pending', working_dir='a')
752
 
        self.assertEqual(out, "added:\n  b\n")
 
632
        self.assertEquals(out, "added:\n  b\n")
753
633
 
754
634
    def test_pending_specific_files(self):
755
635
        """With a specific file list, pending merges are not shown."""
770
650
 
771
651
class TestStatusEncodings(TestCaseWithTransport):
772
652
 
 
653
    def setUp(self):
 
654
        TestCaseWithTransport.setUp(self)
 
655
        self.user_encoding = osutils._cached_user_encoding
 
656
        self.stdout = sys.stdout
 
657
 
 
658
    def tearDown(self):
 
659
        osutils._cached_user_encoding = self.user_encoding
 
660
        sys.stdout = self.stdout
 
661
        TestCaseWithTransport.tearDown(self)
 
662
 
773
663
    def make_uncommitted_tree(self):
774
664
        """Build a branch with uncommitted unicode named changes in the cwd."""
775
665
        working_tree = self.make_branch_and_tree(u'.')
783
673
        return working_tree
784
674
 
785
675
    def test_stdout_ascii(self):
786
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
 
676
        sys.stdout = StringIO()
 
677
        osutils._cached_user_encoding = 'ascii'
787
678
        working_tree = self.make_uncommitted_tree()
788
679
        stdout, stderr = self.run_bzr("status")
789
680
 
790
 
        self.assertEqual(stdout, """\
 
681
        self.assertEquals(stdout, """\
791
682
added:
792
683
  hell?
793
684
""")
794
685
 
795
686
    def test_stdout_latin1(self):
796
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
 
687
        sys.stdout = StringIO()
 
688
        osutils._cached_user_encoding = 'latin-1'
797
689
        working_tree = self.make_uncommitted_tree()
798
690
        stdout, stderr = self.run_bzr('status')
799
691
 
800
 
        self.assertEqual(stdout, u"""\
 
692
        self.assertEquals(stdout, u"""\
801
693
added:
802
694
  hell\u00d8
803
695
""".encode('latin-1'))