~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-10-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006 by 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
28
import sys
29
29
from tempfile import TemporaryFile
30
30
 
 
31
from bzrlib import bzrdir, errors
31
32
import bzrlib.branch
32
33
from bzrlib.builtins import merge
33
 
import bzrlib.bzrdir as bzrdir
34
 
import bzrlib.errors as errors
35
34
from bzrlib.osutils import pathjoin
36
35
from bzrlib.revisionspec import RevisionSpec
37
36
from bzrlib.status import show_tree_status
41
40
 
42
41
class BranchStatus(TestCaseWithTransport):
43
42
    
44
 
    def test_branch_status(self): 
 
43
    def assertStatus(self, output_lines, working_tree,
 
44
        revision=None):
 
45
        """Run status in working_tree and look for output.
 
46
        
 
47
        :param output_lines: The lines to look for.
 
48
        :param working_tree: The tree to run status in.
 
49
        """
 
50
        output_string = self.status_string(working_tree, revision)
 
51
        self.assertEqual(output_lines, output_string.splitlines(True))
 
52
    
 
53
    def status_string(self, wt, revision=None):
 
54
        # use a real file rather than StringIO because it doesn't handle
 
55
        # Unicode very well.
 
56
        tof = codecs.getwriter('utf-8')(TemporaryFile())
 
57
        show_tree_status(wt, to_file=tof, revision=revision)
 
58
        tof.seek(0)
 
59
        return tof.read().decode('utf-8')
 
60
 
 
61
    def test_branch_status(self):
45
62
        """Test basic branch status"""
46
63
        wt = self.make_branch_and_tree('.')
47
 
        b = wt.branch
48
 
 
49
 
        # status with nothing
50
 
        tof = StringIO()
51
 
        show_tree_status(wt, to_file=tof)
52
 
        self.assertEquals(tof.getvalue(), "")
53
 
 
54
 
        tof = StringIO()
 
64
 
 
65
        # status with no commits or files - it must
 
66
        # work and show no output. We do this with no
 
67
        # commits to be sure that it's not going to fail
 
68
        # as a corner case.
 
69
        self.assertStatus([], wt)
 
70
 
55
71
        self.build_tree(['hello.c', 'bye.c'])
56
 
        wt.add_pending_merge('pending@pending-0-0')
57
 
        show_tree_status(wt, to_file=tof)
58
 
        tof.seek(0)
59
 
        self.assertEquals(tof.readlines(),
60
 
                          ['unknown:\n',
61
 
                           '  bye.c\n',
62
 
                           '  hello.c\n',
63
 
                           'pending merges:\n',
64
 
                           '  pending@pending-0-0\n'
65
 
                           ])
 
72
        self.assertStatus([
 
73
                'unknown:\n',
 
74
                '  bye.c\n',
 
75
                '  hello.c\n',
 
76
            ],
 
77
            wt)
 
78
 
 
79
        # add a commit to allow showing pending merges.
 
80
        wt.commit('create a parent to allow testing merge output')
 
81
 
 
82
        wt.add_parent_tree_id('pending@pending-0-0')
 
83
        self.assertStatus([
 
84
                'unknown:\n',
 
85
                '  bye.c\n',
 
86
                '  hello.c\n',
 
87
                'pending merges:\n',
 
88
                '  pending@pending-0-0\n',
 
89
            ],
 
90
            wt)
66
91
 
67
92
    def test_branch_status_revisions(self):
68
93
        """Tests branch status with revisions"""
69
94
        wt = self.make_branch_and_tree('.')
70
 
        b = wt.branch
71
95
 
72
 
        tof = StringIO()
73
96
        self.build_tree(['hello.c', 'bye.c'])
74
97
        wt.add('hello.c')
75
98
        wt.add('bye.c')
76
99
        wt.commit('Test message')
77
100
 
78
 
        tof = StringIO()
79
 
        revs =[]
80
 
        revs.append(RevisionSpec(0))
81
 
        
82
 
        show_tree_status(wt, to_file=tof, revision=revs)
83
 
        
84
 
        tof.seek(0)
85
 
        self.assertEquals(tof.readlines(),
86
 
                          ['added:\n',
87
 
                           '  bye.c\n',
88
 
                           '  hello.c\n'])
 
101
        revs = [RevisionSpec.from_string('0')]
 
102
        self.assertStatus([
 
103
                'added:\n',
 
104
                '  bye.c\n',
 
105
                '  hello.c\n'
 
106
            ],
 
107
            wt,
 
108
            revision=revs)
89
109
 
90
110
        self.build_tree(['more.c'])
91
111
        wt.add('more.c')
92
112
        wt.commit('Another test message')
93
113
        
94
 
        tof = StringIO()
95
 
        revs.append(RevisionSpec(1))
96
 
        
97
 
        show_tree_status(wt, to_file=tof, revision=revs)
98
 
        
99
 
        tof.seek(0)
100
 
        self.assertEquals(tof.readlines(),
101
 
                          ['added:\n',
102
 
                           '  bye.c\n',
103
 
                           '  hello.c\n'])
104
 
 
105
 
    def status_string(self, wt):
106
 
        # use a real file rather than StringIO because it doesn't handle
107
 
        # Unicode very well.
108
 
        tof = codecs.getwriter('utf-8')(TemporaryFile())
109
 
        show_tree_status(wt, to_file=tof)
110
 
        tof.seek(0)
111
 
        return tof.read().decode('utf-8')
 
114
        revs.append(RevisionSpec.from_string('1'))
 
115
        self.assertStatus([
 
116
                'added:\n',
 
117
                '  bye.c\n',
 
118
                '  hello.c\n',
 
119
            ],
 
120
            wt,
 
121
            revision=revs)
112
122
 
113
123
    def test_pending(self):
114
124
        """Pending merges display works, including Unicode"""