~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: INADA Naoki
  • Date: 2011-05-18 06:01:08 UTC
  • mto: This revision was merged to the branch mainline in revision 5894.
  • Revision ID: songofacandy@gmail.com-20110518060108-86t2kffcrzu0nf6i
Update Japanese docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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,
36
37
    )
37
38
import bzrlib.branch
38
39
from bzrlib.osutils import pathjoin
44
45
 
45
46
class BranchStatus(TestCaseWithTransport):
46
47
 
 
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
 
47
56
    def assertStatus(self, expected_lines, working_tree,
48
57
        revision=None, short=False, pending=True, verbose=False):
49
58
        """Run status in working_tree and look for output.
202
211
        wt = self.make_branch_and_tree('.')
203
212
        b = wt.branch
204
213
 
205
 
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
 
214
        self.build_tree(['directory/','directory/hello.c',
 
215
                         'bye.c','test.c','dir2/',
 
216
                         'missing.c'])
206
217
        wt.add('directory')
207
218
        wt.add('test.c')
208
219
        wt.commit('testing')
 
220
        wt.add('missing.c')
 
221
        unlink('missing.c')
209
222
 
210
223
        self.assertStatus([
 
224
                'missing:\n',
 
225
                '  missing.c\n',
211
226
                'unknown:\n',
212
227
                '  bye.c\n',
213
228
                '  dir2/\n',
218
233
        self.assertStatus([
219
234
                '?   bye.c\n',
220
235
                '?   dir2/\n',
 
236
                '+!  missing.c\n',
221
237
                '?   directory/hello.c\n'
222
238
                ],
223
239
                wt, short=True)
260
276
        tof.seek(0)
261
277
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
262
278
 
 
279
        tof = StringIO()
 
280
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
 
281
        tof.seek(0)
 
282
        self.assertEquals(tof.readlines(),
 
283
                          ['missing:\n',
 
284
                           '  missing.c\n'])
 
285
 
 
286
        tof = StringIO()
 
287
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
 
288
                         short=True)
 
289
        tof.seek(0)
 
290
        self.assertEquals(tof.readlines(),
 
291
                          ['+!  missing.c\n'])
 
292
 
263
293
    def test_specific_files_conflicts(self):
264
294
        tree = self.make_branch_and_tree('.')
265
295
        self.build_tree(['dir2/'])
472
502
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
473
503
                         err)
474
504
 
 
505
    def test_status_on_ignored(self):
 
506
        """Tests branch status on an unversioned file which is considered ignored.
 
507
 
 
508
        See https://bugs.launchpad.net/bzr/+bug/40103
 
509
        """
 
510
        tree = self.make_branch_and_tree('.')
 
511
 
 
512
        self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
 
513
        result = self.run_bzr('status')[0]
 
514
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
 
515
        short_result = self.run_bzr('status --short')[0]
 
516
        self.assertContainsRe(short_result, "\?   test1.c\n")
 
517
 
 
518
        result = self.run_bzr('status test1.c')[0]
 
519
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
 
520
        short_result = self.run_bzr('status --short test1.c')[0]
 
521
        self.assertContainsRe(short_result, "\?   test1.c\n")
 
522
 
 
523
        result = self.run_bzr('status test1.c~')[0]
 
524
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
 
525
        short_result = self.run_bzr('status --short test1.c~')[0]
 
526
        self.assertContainsRe(short_result, "I   test1.c~\n")
 
527
 
 
528
        result = self.run_bzr('status test1.c~ test2.c~')[0]
 
529
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
 
530
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
 
531
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
 
532
 
 
533
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
 
534
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
 
535
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
 
536
        self.assertContainsRe(short_result, "\?   test1.c\nI   test1.c~\nI   test2.c~\n")
 
537
 
475
538
    def test_status_write_lock(self):
476
539
        """Test that status works without fetching history and
477
540
        having a write lock.
487
550
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
488
551
        self.assertEqual('', out)
489
552
 
 
553
    def test_status_with_shelves(self):
 
554
        """Ensure that _show_shelve_summary handler works.
 
555
        """
 
556
        wt = self.make_branch_and_tree('.')
 
557
        self.build_tree(['hello.c'])
 
558
        wt.add('hello.c')
 
559
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
 
560
        self.build_tree(['bye.c'])
 
561
        wt.add('bye.c')
 
562
        self.assertStatus([
 
563
                'added:\n',
 
564
                '  bye.c\n',
 
565
                '1 shelf exists. See "bzr shelve --list" for details.\n',
 
566
            ],
 
567
            wt)
 
568
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
 
569
        self.build_tree(['spam.c'])
 
570
        wt.add('spam.c')
 
571
        self.assertStatus([
 
572
                'added:\n',
 
573
                '  spam.c\n',
 
574
                '2 shelves exist. See "bzr shelve --list" for details.\n',
 
575
            ],
 
576
            wt)
 
577
 
490
578
 
491
579
class CheckoutStatus(BranchStatus):
492
580
 
498
586
    def make_branch_and_tree(self, relpath):
499
587
        source = self.make_branch(pathjoin('..', relpath))
500
588
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
501
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
 
589
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
 
590
            target_branch=source)
502
591
        return checkout.create_workingtree()
503
592
 
504
593
 
595
684
        result2 = self.run_bzr("status -SV -r 0..")[0]
596
685
        self.assertEquals(result2, result)
597
686
 
598
 
    def assertStatusContains(self, pattern):
 
687
    def assertStatusContains(self, pattern, short=False):
599
688
        """Run status, and assert it contains the given pattern"""
600
 
        result = self.run_bzr("status --short")[0]
 
689
        if short:
 
690
            result = self.run_bzr("status --short")[0]
 
691
        else:
 
692
            result = self.run_bzr("status")[0]
601
693
        self.assertContainsRe(result, pattern)
602
694
 
 
695
    def test_kind_change_plain(self):
 
696
        tree = self.make_branch_and_tree('.')
 
697
        self.build_tree(['file'])
 
698
        tree.add('file')
 
699
        tree.commit('added file')
 
700
        unlink('file')
 
701
        self.build_tree(['file/'])
 
702
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
 
703
        tree.rename_one('file', 'directory')
 
704
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
 
705
                                  'modified:\n  directory/\n')
 
706
        rmdir('directory')
 
707
        self.assertStatusContains('removed:\n  file\n')
 
708
 
603
709
    def test_kind_change_short(self):
604
710
        tree = self.make_branch_and_tree('.')
605
711
        self.build_tree(['file'])
607
713
        tree.commit('added file')
608
714
        unlink('file')
609
715
        self.build_tree(['file/'])
610
 
        self.assertStatusContains('K  file => file/')
 
716
        self.assertStatusContains('K  file => file/',
 
717
                                   short=True)
611
718
        tree.rename_one('file', 'directory')
612
 
        self.assertStatusContains('RK  file => directory/')
 
719
        self.assertStatusContains('RK  file => directory/',
 
720
                                   short=True)
613
721
        rmdir('directory')
614
 
        self.assertStatusContains('RD  file => directory')
 
722
        self.assertStatusContains('RD  file => directory',
 
723
                                   short=True)
615
724
 
616
725
    def test_status_illegal_revision_specifiers(self):
617
726
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
650
759
 
651
760
class TestStatusEncodings(TestCaseWithTransport):
652
761
 
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
 
 
663
762
    def make_uncommitted_tree(self):
664
763
        """Build a branch with uncommitted unicode named changes in the cwd."""
665
764
        working_tree = self.make_branch_and_tree(u'.')
673
772
        return working_tree
674
773
 
675
774
    def test_stdout_ascii(self):
676
 
        sys.stdout = StringIO()
677
 
        osutils._cached_user_encoding = 'ascii'
 
775
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
678
776
        working_tree = self.make_uncommitted_tree()
679
777
        stdout, stderr = self.run_bzr("status")
680
778
 
684
782
""")
685
783
 
686
784
    def test_stdout_latin1(self):
687
 
        sys.stdout = StringIO()
688
 
        osutils._cached_user_encoding = 'latin-1'
 
785
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
689
786
        working_tree = self.make_uncommitted_tree()
690
787
        stdout, stderr = self.run_bzr('status')
691
788