~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-27 22:08:46 UTC
  • mfrom: (2227.4.1 bzr.78026)
  • Revision ID: pqm@pqm.ubuntu.com-20070227220846-8cce3b2986915092
CapitalizeĀ rocksĀ output

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from cStringIO import StringIO
26
26
import codecs
27
 
from os import mkdir, chdir
 
27
from os import mkdir, chdir, rmdir, unlink
28
28
import sys
29
29
from tempfile import TemporaryFile
30
30
 
41
41
class BranchStatus(TestCaseWithTransport):
42
42
    
43
43
    def assertStatus(self, output_lines, working_tree,
44
 
        revision=None):
 
44
        revision=None, short=False):
45
45
        """Run status in working_tree and look for output.
46
46
        
47
47
        :param output_lines: The lines to look for.
48
48
        :param working_tree: The tree to run status in.
49
49
        """
50
 
        output_string = self.status_string(working_tree, revision)
 
50
        output_string = self.status_string(working_tree, revision, short)
51
51
        self.assertEqual(output_lines, output_string.splitlines(True))
52
52
    
53
 
    def status_string(self, wt, revision=None):
 
53
    def status_string(self, wt, revision=None, short=False):
54
54
        # use a real file rather than StringIO because it doesn't handle
55
55
        # Unicode very well.
56
56
        tof = codecs.getwriter('utf-8')(TemporaryFile())
57
 
        show_tree_status(wt, to_file=tof, revision=revision)
 
57
        show_tree_status(wt, to_file=tof, revision=revision, short=short)
58
58
        tof.seek(0)
59
59
        return tof.read().decode('utf-8')
60
60
 
75
75
                '  hello.c\n',
76
76
            ],
77
77
            wt)
 
78
        self.assertStatus([
 
79
                '?   bye.c\n',
 
80
                '?   hello.c\n',
 
81
            ],
 
82
            wt, short=True)
78
83
 
79
84
        # add a commit to allow showing pending merges.
80
85
        wt.commit('create a parent to allow testing merge output')
88
93
                '  pending@pending-0-0\n',
89
94
            ],
90
95
            wt)
 
96
        self.assertStatus([
 
97
                '?   bye.c\n',
 
98
                '?   hello.c\n',
 
99
                'P   pending@pending-0-0\n',
 
100
            ],
 
101
            wt, short=True)
91
102
 
92
103
    def test_branch_status_revisions(self):
93
104
        """Tests branch status with revisions"""
132
143
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
133
144
        merge(["./branch", -1], [None, None], this_dir = './copy')
134
145
        message = self.status_string(wt2)
135
 
        self.assert_(message.startswith("pending merges:\n"))
136
 
        self.assert_(message.endswith("Empty commit 2\n")) 
 
146
        self.assertStartsWith(message, "pending merges:\n")
 
147
        self.assertEndsWith(message, "Empty commit 2\n")
137
148
        wt2.commit("merged")
138
149
        # must be long to make sure we see elipsis at the end
139
 
        wt.commit("Empty commit 3 " + 
140
 
                   "blah blah blah blah " * 10)
 
150
        wt.commit("Empty commit 3 " +
 
151
                   "blah blah blah blah " * 100)
141
152
        merge(["./branch", -1], [None, None], this_dir = './copy')
142
153
        message = self.status_string(wt2)
143
 
        self.assert_(message.startswith("pending merges:\n"))
 
154
        self.assertStartsWith(message, "pending merges:\n")
144
155
        self.assert_("Empty commit 3" in message)
145
 
        self.assert_(message.endswith("...\n")) 
 
156
        self.assertEndsWith(message, "...\n")
146
157
 
147
158
    def test_branch_status_specific_files(self): 
148
159
        """Tests branch status with given specific files"""
154
165
        wt.add('test.c')
155
166
        wt.commit('testing')
156
167
        
 
168
        self.assertStatus([
 
169
                'unknown:\n',
 
170
                '  bye.c\n',
 
171
                '  dir2\n',
 
172
                '  directory/hello.c\n'
 
173
                ],
 
174
                wt)
 
175
 
 
176
        self.assertStatus([
 
177
                '?   bye.c\n',
 
178
                '?   dir2\n',
 
179
                '?   directory/hello.c\n'
 
180
                ],
 
181
                wt, short=True)
 
182
 
157
183
        tof = StringIO()
158
 
        show_tree_status(wt, to_file=tof)
159
 
        tof.seek(0)
160
 
        self.assertEquals(tof.readlines(),
161
 
                          ['unknown:\n',
162
 
                           '  bye.c\n',
163
 
                           '  dir2\n',
164
 
                           '  directory/hello.c\n'
165
 
                           ])
166
 
 
167
184
        self.assertRaises(errors.PathsDoNotExist,
168
185
                          show_tree_status,
169
186
                          wt, specific_files=['bye.c','test.c','absent.c'], 
177
194
                           '  directory/hello.c\n'
178
195
                           ])
179
196
        tof = StringIO()
 
197
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
 
198
                         short=True)
 
199
        tof.seek(0)
 
200
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
 
201
 
 
202
        tof = StringIO()
180
203
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
181
204
        tof.seek(0)
182
205
        self.assertEquals(tof.readlines(),
183
206
                          ['unknown:\n',
184
207
                           '  dir2\n'
185
208
                           ])
 
209
        tof = StringIO()
 
210
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
 
211
        tof.seek(0)
 
212
        self.assertEquals(tof.readlines(), ['?   dir2\n'])
186
213
 
187
214
    def test_status_nonexistent_file(self):
188
215
        # files that don't exist in either the basis tree or working tree
226
253
 
227
254
    def test_status(self):
228
255
        self.run_bzr("init")
 
256
 
229
257
        self.build_tree(['hello.txt'])
230
258
        result = self.run_bzr("status")[0]
231
259
        self.assert_("unknown:\n  hello.txt\n" in result, result)
 
260
        result = self.run_bzr("status","--short")[0]
 
261
        self.assertContainsRe(result, "[?]   hello.txt\n")
 
262
 
232
263
        self.run_bzr("add", "hello.txt")
233
264
        result = self.run_bzr("status")[0]
234
 
        self.assert_("added:\n  hello.txt\n" in result, result)
 
265
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
266
        result = self.run_bzr("status","--short")[0]
 
267
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
268
 
235
269
        self.run_bzr("commit", "-m", "added")
236
270
        result = self.run_bzr("status", "-r", "0..1")[0]
237
 
        self.assert_("added:\n  hello.txt\n" in result, result)
 
271
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
272
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
 
273
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
274
 
238
275
        self.build_tree(['world.txt'])
239
276
        result = self.run_bzr("status", "-r", "0")[0]
240
 
        self.assert_("added:\n  hello.txt\n" \
241
 
                     "unknown:\n  world.txt\n" in result, result)
242
 
 
 
277
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
 
278
                                      "unknown:\n  world.txt\n")
243
279
        result2 = self.run_bzr("status", "-r", "0..")[0]
244
280
        self.assertEquals(result2, result)
 
281
        result = self.run_bzr("status", "--short", "-r", "0")[0]
 
282
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
 
283
                                      "[?]   world.txt\n")
 
284
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
 
285
        self.assertEquals(result2, result)
 
286
 
 
287
    def assertStatusContains(self, pattern):
 
288
        """Run status, and assert it contains the given pattern"""
 
289
        result = self.run_bzr("status", "--short")[0]
 
290
        self.assertContainsRe(result, pattern)
 
291
 
 
292
    def test_kind_change_short(self):
 
293
        tree = self.make_branch_and_tree('.')
 
294
        self.build_tree(['file'])
 
295
        tree.add('file')
 
296
        tree.commit('added file')
 
297
        unlink('file')
 
298
        self.build_tree(['file/'])
 
299
        self.assertStatusContains('K  file => file/')
 
300
        tree.rename_one('file', 'directory')
 
301
        self.assertStatusContains('RK  file => directory/')
 
302
        rmdir('directory')
 
303
        self.assertStatusContains('RD  file => directory')
245
304
 
246
305
 
247
306
class TestStatusEncodings(TestCaseWithTransport):