~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2009-09-14 02:30:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4693.
  • Revision ID: mbp@sourcefrog.net-20090914023023-ros0f3ndo04j3bww
Clearer docs about bzr help.  (Thanks to Naoki)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 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
473
472
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
474
473
                         err)
475
474
 
476
 
    def test_status_on_ignored(self):
477
 
        """Tests branch status on an unversioned file which is considered ignored.
478
 
 
479
 
        See https://bugs.launchpad.net/bzr/+bug/40103
480
 
        """
481
 
        tree = self.make_branch_and_tree('.')
482
 
 
483
 
        self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
484
 
        result = self.run_bzr('status')[0]
485
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
486
 
        short_result = self.run_bzr('status --short')[0]
487
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
488
 
 
489
 
        result = self.run_bzr('status test1.c')[0]
490
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
491
 
        short_result = self.run_bzr('status --short test1.c')[0]
492
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
493
 
 
494
 
        result = self.run_bzr('status test1.c~')[0]
495
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
496
 
        short_result = self.run_bzr('status --short test1.c~')[0]
497
 
        self.assertContainsRe(short_result, "I   test1.c~\n")
498
 
 
499
 
        result = self.run_bzr('status test1.c~ test2.c~')[0]
500
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
501
 
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
502
 
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
503
 
 
504
 
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
505
 
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
506
 
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
507
 
        self.assertContainsRe(short_result, "\?   test1.c\nI   test1.c~\nI   test2.c~\n")
508
 
 
509
475
    def test_status_write_lock(self):
510
476
        """Test that status works without fetching history and
511
477
        having a write lock.
521
487
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
522
488
        self.assertEqual('', out)
523
489
 
524
 
    def test_status_with_shelves(self):
525
 
        """Ensure that _show_shelve_summary handler works.
526
 
        """
527
 
        wt = self.make_branch_and_tree('.')
528
 
        self.build_tree(['hello.c'])
529
 
        wt.add('hello.c')
530
 
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
531
 
        self.build_tree(['bye.c'])
532
 
        wt.add('bye.c')
533
 
        # As TestCase.setUp clears all hooks, we install this default
534
 
        # post_status hook handler for the test.
535
 
        status.hooks.install_named_hook('post_status',
536
 
            status._show_shelve_summary,
537
 
            'bzr status')
538
 
        self.assertStatus([
539
 
                'added:\n',
540
 
                '  bye.c\n',
541
 
                '1 shelves exist. See "bzr shelve --list" for details.\n',
542
 
            ],
543
 
            wt)
544
 
 
545
490
 
546
491
class CheckoutStatus(BranchStatus):
547
492
 
553
498
    def make_branch_and_tree(self, relpath):
554
499
        source = self.make_branch(pathjoin('..', relpath))
555
500
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
556
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
557
 
            target_branch=source)
 
501
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
558
502
        return checkout.create_workingtree()
559
503
 
560
504
 
651
595
        result2 = self.run_bzr("status -SV -r 0..")[0]
652
596
        self.assertEquals(result2, result)
653
597
 
654
 
    def assertStatusContains(self, pattern, short=False):
 
598
    def assertStatusContains(self, pattern):
655
599
        """Run status, and assert it contains the given pattern"""
656
 
        if short:
657
 
            result = self.run_bzr("status --short")[0]
658
 
        else:
659
 
            result = self.run_bzr("status")[0]
 
600
        result = self.run_bzr("status --short")[0]
660
601
        self.assertContainsRe(result, pattern)
661
602
 
662
 
    def test_kind_change_plain(self):
663
 
        tree = self.make_branch_and_tree('.')
664
 
        self.build_tree(['file'])
665
 
        tree.add('file')
666
 
        tree.commit('added file')
667
 
        unlink('file')
668
 
        self.build_tree(['file/'])
669
 
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
670
 
        tree.rename_one('file', 'directory')
671
 
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
672
 
                                  'modified:\n  directory/\n')
673
 
        rmdir('directory')
674
 
        self.assertStatusContains('removed:\n  file\n')
675
 
 
676
603
    def test_kind_change_short(self):
677
604
        tree = self.make_branch_and_tree('.')
678
605
        self.build_tree(['file'])
680
607
        tree.commit('added file')
681
608
        unlink('file')
682
609
        self.build_tree(['file/'])
683
 
        self.assertStatusContains('K  file => file/',
684
 
                                   short=True)
 
610
        self.assertStatusContains('K  file => file/')
685
611
        tree.rename_one('file', 'directory')
686
 
        self.assertStatusContains('RK  file => directory/',
687
 
                                   short=True)
 
612
        self.assertStatusContains('RK  file => directory/')
688
613
        rmdir('directory')
689
 
        self.assertStatusContains('RD  file => directory',
690
 
                                   short=True)
 
614
        self.assertStatusContains('RD  file => directory')
691
615
 
692
616
    def test_status_illegal_revision_specifiers(self):
693
617
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
726
650
 
727
651
class TestStatusEncodings(TestCaseWithTransport):
728
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
 
729
663
    def make_uncommitted_tree(self):
730
664
        """Build a branch with uncommitted unicode named changes in the cwd."""
731
665
        working_tree = self.make_branch_and_tree(u'.')
739
673
        return working_tree
740
674
 
741
675
    def test_stdout_ascii(self):
742
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
 
676
        sys.stdout = StringIO()
 
677
        osutils._cached_user_encoding = 'ascii'
743
678
        working_tree = self.make_uncommitted_tree()
744
679
        stdout, stderr = self.run_bzr("status")
745
680
 
749
684
""")
750
685
 
751
686
    def test_stdout_latin1(self):
752
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
 
687
        sys.stdout = StringIO()
 
688
        osutils._cached_user_encoding = 'latin-1'
753
689
        working_tree = self.make_uncommitted_tree()
754
690
        stdout, stderr = self.run_bzr('status')
755
691