~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2010-02-10 15:46:03 UTC
  • mfrom: (4985.3.21 update)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: v.ladeuil+lp@free.fr-20100210154603-k4no1gvfuqpzrw7p
Update performs two merges in a more logical order but stop on conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests of status command.
18
18
 
19
19
Most of these depend on the particular formatting used.
20
 
As such they really are blackbox tests even though some of the 
 
20
As such they really are blackbox tests even though some of the
21
21
tests are not using self.capture. If we add tests for the programmatic
22
22
interface later, they will be non blackbox tests.
23
23
"""
43
43
 
44
44
 
45
45
class BranchStatus(TestCaseWithTransport):
46
 
    
 
46
 
47
47
    def assertStatus(self, expected_lines, working_tree,
48
48
        revision=None, short=False, pending=True, verbose=False):
49
49
        """Run status in working_tree and look for output.
50
 
        
 
50
 
51
51
        :param expected_lines: The lines to look for.
52
52
        :param working_tree: The tree to run status in.
53
53
        """
54
54
        output_string = self.status_string(working_tree, revision, short,
55
55
                pending, verbose)
56
56
        self.assertEqual(expected_lines, output_string.splitlines(True))
57
 
    
 
57
 
58
58
    def status_string(self, wt, revision=None, short=False, pending=True,
59
59
        verbose=False):
60
60
        # use a real file rather than StringIO because it doesn't handle
147
147
        self.build_tree(['more.c'])
148
148
        wt.add('more.c')
149
149
        wt.commit('Another test message')
150
 
        
 
150
 
151
151
        revs.append(RevisionSpec.from_string('1'))
152
152
        self.assertStatus([
153
153
                'added:\n',
206
206
        wt.add('directory')
207
207
        wt.add('test.c')
208
208
        wt.commit('testing')
209
 
        
 
209
 
210
210
        self.assertStatus([
211
211
                'unknown:\n',
212
212
                '  bye.c\n',
225
225
        tof = StringIO()
226
226
        self.assertRaises(errors.PathsDoNotExist,
227
227
                          show_tree_status,
228
 
                          wt, specific_files=['bye.c','test.c','absent.c'], 
 
228
                          wt, specific_files=['bye.c','test.c','absent.c'],
229
229
                          to_file=tof)
230
 
        
 
230
 
231
231
        tof = StringIO()
232
232
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
233
233
        tof.seek(0)
284
284
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
285
285
                             tof.getvalue())
286
286
 
 
287
    def _prepare_nonexistent(self):
 
288
        wt = self.make_branch_and_tree('.')
 
289
        self.assertStatus([], wt)
 
290
        self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', 'FILE_E', ])
 
291
        wt.add('FILE_A')
 
292
        wt.add('FILE_B')
 
293
        wt.add('FILE_C')
 
294
        wt.add('FILE_D')
 
295
        wt.add('FILE_E')
 
296
        wt.commit('Create five empty files.')
 
297
        open('FILE_B', 'w').write('Modification to file FILE_B.')
 
298
        open('FILE_C', 'w').write('Modification to file FILE_C.')
 
299
        unlink('FILE_E')  # FILE_E will be versioned but missing
 
300
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
 
301
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
 
302
        open('UNVERSIONED_BUT_EXISTING', 'w')
 
303
        return wt
 
304
 
287
305
    def test_status_nonexistent_file(self):
288
306
        # files that don't exist in either the basis tree or working tree
289
307
        # should give an error
290
 
        wt = self.make_branch_and_tree('.')
291
 
        out, err = self.run_bzr('status does-not-exist', retcode=3)
292
 
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
 
308
        wt = self._prepare_nonexistent()
 
309
        self.assertStatus([
 
310
            'removed:\n',
 
311
            '  FILE_E\n',
 
312
            'added:\n',
 
313
            '  FILE_Q\n',
 
314
            'modified:\n',
 
315
            '  FILE_B\n',
 
316
            '  FILE_C\n',
 
317
            'unknown:\n',
 
318
            '  UNVERSIONED_BUT_EXISTING\n',
 
319
            ],
 
320
            wt)
 
321
        self.assertStatus([
 
322
            ' M  FILE_B\n',
 
323
            ' M  FILE_C\n',
 
324
            ' D  FILE_E\n',
 
325
            '+N  FILE_Q\n',
 
326
            '?   UNVERSIONED_BUT_EXISTING\n',
 
327
            ],
 
328
            wt, short=True)
 
329
 
 
330
        # Okay, everything's looking good with the existent files.
 
331
        # Let's see what happens when we throw in non-existent files.
 
332
 
 
333
        # bzr st [--short] NONEXISTENT '
 
334
        expected = [
 
335
          'nonexistent:\n',
 
336
          '  NONEXISTENT\n',
 
337
          ]
 
338
        out, err = self.run_bzr('status NONEXISTENT', retcode=3)
 
339
        self.assertEqual(expected, out.splitlines(True))
 
340
        self.assertContainsRe(err,
 
341
                              r'.*ERROR: Path\(s\) do not exist: '
 
342
                              'NONEXISTENT.*')
 
343
        expected = [
 
344
          'X:   NONEXISTENT\n',
 
345
          ]
 
346
        out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
 
347
        self.assertContainsRe(err,
 
348
                              r'.*ERROR: Path\(s\) do not exist: '
 
349
                              'NONEXISTENT.*')
 
350
 
 
351
    def test_status_nonexistent_file_with_others(self):
 
352
        # bzr st [--short] NONEXISTENT ...others..
 
353
        wt = self._prepare_nonexistent()
 
354
        expected = [
 
355
          'removed:\n',
 
356
          '  FILE_E\n',
 
357
          'modified:\n',
 
358
          '  FILE_B\n',
 
359
          '  FILE_C\n',
 
360
          'nonexistent:\n',
 
361
          '  NONEXISTENT\n',
 
362
          ]
 
363
        out, err = self.run_bzr('status NONEXISTENT '
 
364
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
 
365
                                retcode=3)
 
366
        self.assertEqual(expected, out.splitlines(True))
 
367
        self.assertContainsRe(err,
 
368
                              r'.*ERROR: Path\(s\) do not exist: '
 
369
                              'NONEXISTENT.*')
 
370
        expected = [
 
371
          ' D  FILE_E\n',
 
372
          ' M  FILE_C\n',
 
373
          ' M  FILE_B\n',
 
374
          'X   NONEXISTENT\n',
 
375
          ]
 
376
        out, err = self.run_bzr('status --short NONEXISTENT '
 
377
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
 
378
                                retcode=3)
 
379
        self.assertEqual(expected, out.splitlines(True))
 
380
        self.assertContainsRe(err,
 
381
                              r'.*ERROR: Path\(s\) do not exist: '
 
382
                              'NONEXISTENT.*')
 
383
 
 
384
    def test_status_multiple_nonexistent_files(self):
 
385
        # bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
 
386
        wt = self._prepare_nonexistent()
 
387
        expected = [
 
388
          'removed:\n',
 
389
          '  FILE_E\n',
 
390
          'modified:\n',
 
391
          '  FILE_B\n',
 
392
          '  FILE_C\n',
 
393
          'nonexistent:\n',
 
394
          '  ANOTHER_NONEXISTENT\n',
 
395
          '  NONEXISTENT\n',
 
396
          ]
 
397
        out, err = self.run_bzr('status NONEXISTENT '
 
398
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
 
399
                                'FILE_C FILE_D FILE_E', retcode=3)
 
400
        self.assertEqual(expected, out.splitlines(True))
 
401
        self.assertContainsRe(err,
 
402
                              r'.*ERROR: Path\(s\) do not exist: '
 
403
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
 
404
        expected = [
 
405
          ' D  FILE_E\n',
 
406
          ' M  FILE_C\n',
 
407
          ' M  FILE_B\n',
 
408
          'X   ANOTHER_NONEXISTENT\n',
 
409
          'X   NONEXISTENT\n',
 
410
          ]
 
411
        out, err = self.run_bzr('status --short NONEXISTENT '
 
412
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
 
413
                                'FILE_C FILE_D FILE_E', retcode=3)
 
414
        self.assertEqual(expected, out.splitlines(True))
 
415
        self.assertContainsRe(err,
 
416
                              r'.*ERROR: Path\(s\) do not exist: '
 
417
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
 
418
 
 
419
    def test_status_nonexistent_file_with_unversioned(self):
 
420
        # bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
 
421
        wt = self._prepare_nonexistent()
 
422
        expected = [
 
423
          'removed:\n',
 
424
          '  FILE_E\n',
 
425
          'added:\n',
 
426
          '  FILE_Q\n',
 
427
          'modified:\n',
 
428
          '  FILE_B\n',
 
429
          '  FILE_C\n',
 
430
          'unknown:\n',
 
431
          '  UNVERSIONED_BUT_EXISTING\n',
 
432
          'nonexistent:\n',
 
433
          '  NONEXISTENT\n',
 
434
          ]
 
435
        out, err = self.run_bzr('status NONEXISTENT '
 
436
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
 
437
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
 
438
        self.assertEqual(expected, out.splitlines(True))
 
439
        self.assertContainsRe(err,
 
440
                              r'.*ERROR: Path\(s\) do not exist: '
 
441
                              'NONEXISTENT.*')
 
442
        expected = [
 
443
          '+N  FILE_Q\n',
 
444
          '?   UNVERSIONED_BUT_EXISTING\n',
 
445
          ' D  FILE_E\n',
 
446
          ' M  FILE_C\n',
 
447
          ' M  FILE_B\n',
 
448
          'X   NONEXISTENT\n',
 
449
          ]
 
450
        out, err = self.run_bzr('status --short NONEXISTENT '
 
451
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
 
452
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
 
453
        self.assertEqual(expected, out.splitlines(True))
 
454
        self.assertContainsRe(err,
 
455
                              r'.*ERROR: Path\(s\) do not exist: '
 
456
                              'NONEXISTENT.*')
293
457
 
294
458
    def test_status_out_of_date(self):
295
459
        """Simulate status of out-of-date tree after remote push"""
330
494
        super(CheckoutStatus, self).setUp()
331
495
        mkdir('codir')
332
496
        chdir('codir')
333
 
        
 
497
 
334
498
    def make_branch_and_tree(self, relpath):
335
499
        source = self.make_branch(pathjoin('..', relpath))
336
500
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
485
649
 
486
650
 
487
651
class TestStatusEncodings(TestCaseWithTransport):
488
 
    
 
652
 
489
653
    def setUp(self):
490
654
        TestCaseWithTransport.setUp(self)
491
655
        self.user_encoding = osutils._cached_user_encoding
492
656
        self.stdout = sys.stdout
493
657
 
494
658
    def tearDown(self):
495
 
        bzrlib.user_encoding = self.user_encoding
 
659
        osutils._cached_user_encoding = self.user_encoding
496
660
        sys.stdout = self.stdout
497
661
        TestCaseWithTransport.tearDown(self)
498
662