~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_status.py

MergeĀ fromĀ jam-storage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
"""Tests of status command.
 
19
 
 
20
Most of these depend on the particular formatting used.
 
21
"""
 
22
 
 
23
 
 
24
from cStringIO import StringIO
 
25
from os import mkdir
 
26
from tempfile import TemporaryFile
 
27
import codecs
 
28
 
 
29
from bzrlib.tests import TestCaseInTempDir
 
30
from bzrlib.revisionspec import RevisionSpec
 
31
from bzrlib.merge import merge
 
32
from bzrlib.status import show_status
 
33
from bzrlib.branch import Branch
 
34
 
 
35
class BranchStatus(TestCaseInTempDir):
 
36
    
 
37
    def test_branch_status(self): 
 
38
        """Test basic branch status"""
 
39
        from bzrlib.status import show_status
 
40
        from bzrlib.branch import Branch
 
41
        
 
42
        b = Branch.initialize(u'.')
 
43
 
 
44
        # status with nothing
 
45
        tof = StringIO()
 
46
        show_status(b, to_file=tof)
 
47
        self.assertEquals(tof.getvalue(), "")
 
48
 
 
49
        tof = StringIO()
 
50
        self.build_tree(['hello.c', 'bye.c'])
 
51
        b.working_tree().add_pending_merge('pending@pending-0-0')
 
52
        show_status(b, to_file=tof)
 
53
        tof.seek(0)
 
54
        self.assertEquals(tof.readlines(),
 
55
                          ['unknown:\n',
 
56
                           '  bye.c\n',
 
57
                           '  hello.c\n',
 
58
                           'pending merges:\n',
 
59
                           '  pending@pending-0-0\n'
 
60
                           ])
 
61
 
 
62
    def test_branch_status_revisions(self):
 
63
        """Tests branch status with revisions"""
 
64
        
 
65
        b = Branch.initialize(u'.')
 
66
 
 
67
        tof = StringIO()
 
68
        self.build_tree(['hello.c', 'bye.c'])
 
69
        b.working_tree().add('hello.c')
 
70
        b.working_tree().add('bye.c')
 
71
        b.working_tree().commit('Test message')
 
72
 
 
73
        tof = StringIO()
 
74
        revs =[]
 
75
        revs.append(RevisionSpec(0))
 
76
        
 
77
        show_status(b, to_file=tof, revision=revs)
 
78
        
 
79
        tof.seek(0)
 
80
        self.assertEquals(tof.readlines(),
 
81
                          ['added:\n',
 
82
                           '  bye.c\n',
 
83
                           '  hello.c\n'])
 
84
 
 
85
        self.build_tree(['more.c'])
 
86
        b.working_tree().add('more.c')
 
87
        b.working_tree().commit('Another test message')
 
88
        
 
89
        tof = StringIO()
 
90
        revs.append(RevisionSpec(1))
 
91
        
 
92
        show_status(b, to_file=tof, revision=revs)
 
93
        
 
94
        tof.seek(0)
 
95
        self.assertEquals(tof.readlines(),
 
96
                          ['added:\n',
 
97
                           '  bye.c\n',
 
98
                           '  hello.c\n'])
 
99
 
 
100
    def status_string(self, branch):
 
101
        # use a real file rather than StringIO because it doesn't handle
 
102
        # Unicode very well.
 
103
        tof = codecs.getwriter('utf-8')(TemporaryFile())
 
104
        show_status(branch, to_file=tof)
 
105
        tof.seek(0)
 
106
        return tof.read().decode('utf-8')
 
107
 
 
108
    def test_pending(self):
 
109
        """Pending merges display works, including Unicode"""
 
110
        mkdir("./branch")
 
111
        b = Branch.initialize('./branch')
 
112
        b.working_tree().commit("Empty commit 1")
 
113
        b_2 = b.clone('./copy')
 
114
        b.working_tree().commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
 
115
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
116
        message = self.status_string(b_2)
 
117
        self.assert_(message.startswith("pending merges:\n"))
 
118
        self.assert_(message.endswith("Empty commit 2\n")) 
 
119
        b_2.working_tree().commit("merged")
 
120
        # must be long to make sure we see elipsis at the end
 
121
        b.working_tree().commit("Empty commit 3 " + 
 
122
                                "blah blah blah blah " * 10)
 
123
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
124
        message = self.status_string(b_2)
 
125
        self.assert_(message.startswith("pending merges:\n"))
 
126
        self.assert_("Empty commit 3" in message)
 
127
        self.assert_(message.endswith("...\n")) 
 
128
 
 
129
    def test_branch_status_specific_files(self): 
 
130
        """Tests branch status with given specific files"""
 
131
        from cStringIO import StringIO
 
132
        from bzrlib.status import show_status
 
133
        from bzrlib.branch import Branch
 
134
        
 
135
        b = Branch.initialize(u'.')
 
136
 
 
137
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
 
138
        b.working_tree().add('directory')
 
139
        b.working_tree().add('test.c')
 
140
        b.working_tree().commit('testing')
 
141
        
 
142
        tof = StringIO()
 
143
        show_status(b, to_file=tof)
 
144
        tof.seek(0)
 
145
        self.assertEquals(tof.readlines(),
 
146
                          ['unknown:\n',
 
147
                           '  bye.c\n',
 
148
                           '  dir2\n',
 
149
                           '  directory/hello.c\n'
 
150
                           ])
 
151
 
 
152
        tof = StringIO()
 
153
        show_status(b, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
 
154
        tof.seek(0)
 
155
        self.assertEquals(tof.readlines(),
 
156
                          ['unknown:\n',
 
157
                           '  bye.c\n'
 
158
                           ])
 
159
        
 
160
        tof = StringIO()
 
161
        show_status(b, specific_files=['directory'], to_file=tof)
 
162
        tof.seek(0)
 
163
        self.assertEquals(tof.readlines(),
 
164
                          ['unknown:\n',
 
165
                           '  directory/hello.c\n'
 
166
                           ])
 
167
        tof = StringIO()
 
168
        show_status(b, specific_files=['dir2'], to_file=tof)
 
169
        tof.seek(0)
 
170
        self.assertEquals(tof.readlines(),
 
171
                          ['unknown:\n',
 
172
                           '  dir2\n'
 
173
                           ])