~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:
21
21
"""
22
22
 
23
23
 
24
 
from bzrlib.selftest import InTempDir
25
 
 
26
 
class BranchStatus(InTempDir):
27
 
    def runTest(self): 
28
 
        """Basic 'bzr mkdir' operation"""
29
 
        from cStringIO import StringIO
 
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"""
30
39
        from bzrlib.status import show_status
31
40
        from bzrlib.branch import Branch
32
41
        
33
 
        b = Branch('.', init=True)
 
42
        b = Branch.initialize(u'.')
34
43
 
35
44
        # status with nothing
36
45
        tof = StringIO()
39
48
 
40
49
        tof = StringIO()
41
50
        self.build_tree(['hello.c', 'bye.c'])
 
51
        b.working_tree().add_pending_merge('pending@pending-0-0')
42
52
        show_status(b, to_file=tof)
43
53
        tof.seek(0)
44
54
        self.assertEquals(tof.readlines(),
45
55
                          ['unknown:\n',
46
56
                           '  bye.c\n',
47
57
                           '  hello.c\n',
48
 
                           ])
49
 
 
 
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
                           ])