~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Keir Mierle
  • Date: 2006-11-23 18:56:25 UTC
  • mto: (2168.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2171.
  • Revision ID: keir@cs.utoronto.ca-20061123185625-ndto53ylcb8zo1y6
Fix spacing error and add tests for status --short command flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"""
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.assert_("?  hello.txt\n" in result, result)
 
262
 
232
263
        self.run_bzr("add", "hello.txt")
233
264
        result = self.run_bzr("status")[0]
234
265
        self.assert_("added:\n  hello.txt\n" in result, result)
 
266
        result = self.run_bzr("status","--short")[0]
 
267
        self.assert_("A  hello.txt\n" in result, result)
 
268
 
235
269
        self.run_bzr("commit", "-m", "added")
236
270
        result = self.run_bzr("status", "-r", "0..1")[0]
237
271
        self.assert_("added:\n  hello.txt\n" in result, result)
 
272
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
 
273
        self.assert_("A  hello.txt\n" in result, result)
 
274
 
238
275
        self.build_tree(['world.txt'])
239
276
        result = self.run_bzr("status", "-r", "0")[0]
240
277
        self.assert_("added:\n  hello.txt\n" \
241
278
                     "unknown:\n  world.txt\n" in result, result)
242
 
 
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.assert_("A  hello.txt\n" \
 
283
                     "?  world.txt\n" in result, result)
 
284
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
 
285
        self.assertEquals(result2, result)
245
286
 
246
287
 
247
288
class TestStatusEncodings(TestCaseWithTransport):