~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Max Bowsher
  • Date: 2011-08-23 09:29:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6104.
  • Revision ID: _@maxb.eu-20110823092927-c7fnueriuunvv9mh
Per jam's review comments, get rid of features.meliae_feature, which is new in
2.5 and so will not be missed, assigning the corrected behaviour to the
features.meliae name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    conflicts,
34
34
    errors,
35
35
    osutils,
 
36
    status,
36
37
    )
37
38
import bzrlib.branch
38
39
from bzrlib.osutils import pathjoin
44
45
 
45
46
class BranchStatus(TestCaseWithTransport):
46
47
 
 
48
    def setUp(self):
 
49
        super(BranchStatus, self).setUp()
 
50
        # As TestCase.setUp clears all hooks, we install this default
 
51
        # post_status hook handler for the test.
 
52
        status.hooks.install_named_hook('post_status',
 
53
            status._show_shelve_summary,
 
54
            'bzr status')
 
55
 
47
56
    def assertStatus(self, expected_lines, working_tree,
48
57
        revision=None, short=False, pending=True, verbose=False):
49
58
        """Run status in working_tree and look for output.
202
211
        wt = self.make_branch_and_tree('.')
203
212
        b = wt.branch
204
213
 
205
 
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
 
214
        self.build_tree(['directory/','directory/hello.c',
 
215
                         'bye.c','test.c','dir2/',
 
216
                         'missing.c'])
206
217
        wt.add('directory')
207
218
        wt.add('test.c')
208
219
        wt.commit('testing')
 
220
        wt.add('missing.c')
 
221
        unlink('missing.c')
209
222
 
210
223
        self.assertStatus([
 
224
                'missing:\n',
 
225
                '  missing.c\n',
211
226
                'unknown:\n',
212
227
                '  bye.c\n',
213
228
                '  dir2/\n',
218
233
        self.assertStatus([
219
234
                '?   bye.c\n',
220
235
                '?   dir2/\n',
 
236
                '+!  missing.c\n',
221
237
                '?   directory/hello.c\n'
222
238
                ],
223
239
                wt, short=True)
260
276
        tof.seek(0)
261
277
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
262
278
 
 
279
        tof = StringIO()
 
280
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
 
281
        tof.seek(0)
 
282
        self.assertEquals(tof.readlines(),
 
283
                          ['missing:\n',
 
284
                           '  missing.c\n'])
 
285
 
 
286
        tof = StringIO()
 
287
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
 
288
                         short=True)
 
289
        tof.seek(0)
 
290
        self.assertEquals(tof.readlines(),
 
291
                          ['+!  missing.c\n'])
 
292
 
263
293
    def test_specific_files_conflicts(self):
264
294
        tree = self.make_branch_and_tree('.')
265
295
        self.build_tree(['dir2/'])
294
324
        wt.add('FILE_D')
295
325
        wt.add('FILE_E')
296
326
        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.')
 
327
        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
 
328
        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
299
329
        unlink('FILE_E')  # FILE_E will be versioned but missing
300
 
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
 
330
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
301
331
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
302
332
        open('UNVERSIONED_BUT_EXISTING', 'w')
303
333
        return wt
447
477
          ' M  FILE_B\n',
448
478
          'X   NONEXISTENT\n',
449
479
          ]
 
480
        expected.sort()
450
481
        out, err = self.run_bzr('status --short NONEXISTENT '
451
482
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
452
483
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
453
 
        self.assertEqual(expected, out.splitlines(True))
 
484
        actual = out.splitlines(True)
 
485
        actual.sort()
 
486
        self.assertEqual(expected, actual)
454
487
        self.assertContainsRe(err,
455
488
                              r'.*ERROR: Path\(s\) do not exist: '
456
489
                              'NONEXISTENT.*')
520
553
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
521
554
        self.assertEqual('', out)
522
555
 
 
556
    def test_status_with_shelves(self):
 
557
        """Ensure that _show_shelve_summary handler works.
 
558
        """
 
559
        wt = self.make_branch_and_tree('.')
 
560
        self.build_tree(['hello.c'])
 
561
        wt.add('hello.c')
 
562
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
 
563
        self.build_tree(['bye.c'])
 
564
        wt.add('bye.c')
 
565
        self.assertStatus([
 
566
                'added:\n',
 
567
                '  bye.c\n',
 
568
                '1 shelf exists. See "bzr shelve --list" for details.\n',
 
569
            ],
 
570
            wt)
 
571
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
 
572
        self.build_tree(['spam.c'])
 
573
        wt.add('spam.c')
 
574
        self.assertStatus([
 
575
                'added:\n',
 
576
                '  spam.c\n',
 
577
                '2 shelves exist. See "bzr shelve --list" for details.\n',
 
578
            ],
 
579
            wt)
 
580
 
523
581
 
524
582
class CheckoutStatus(BranchStatus):
525
583
 
579
637
        self.assertContainsRe(result, "[+]N  hello.txt\n")
580
638
 
581
639
        self.build_tree(['world.txt'])
582
 
        result = self.run_bzr("status --short -r 0")[0]
 
640
        result = self.run_bzr("status -S -r 0")[0]
583
641
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
584
642
                                      "[?]   world.txt\n")
585
 
        result2 = self.run_bzr("status --short -r 0..")[0]
 
643
        result2 = self.run_bzr("status -S -r 0..")[0]
586
644
        self.assertEquals(result2, result)
587
645
 
588
646
    def test_status_versioned(self):
704
762
 
705
763
class TestStatusEncodings(TestCaseWithTransport):
706
764
 
707
 
    def setUp(self):
708
 
        TestCaseWithTransport.setUp(self)
709
 
        self.user_encoding = osutils._cached_user_encoding
710
 
        self.stdout = sys.stdout
711
 
 
712
 
    def tearDown(self):
713
 
        osutils._cached_user_encoding = self.user_encoding
714
 
        sys.stdout = self.stdout
715
 
        TestCaseWithTransport.tearDown(self)
716
 
 
717
765
    def make_uncommitted_tree(self):
718
766
        """Build a branch with uncommitted unicode named changes in the cwd."""
719
767
        working_tree = self.make_branch_and_tree(u'.')
727
775
        return working_tree
728
776
 
729
777
    def test_stdout_ascii(self):
730
 
        sys.stdout = StringIO()
731
 
        osutils._cached_user_encoding = 'ascii'
 
778
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
732
779
        working_tree = self.make_uncommitted_tree()
733
780
        stdout, stderr = self.run_bzr("status")
734
781
 
738
785
""")
739
786
 
740
787
    def test_stdout_latin1(self):
741
 
        sys.stdout = StringIO()
742
 
        osutils._cached_user_encoding = 'latin-1'
 
788
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
743
789
        working_tree = self.make_uncommitted_tree()
744
790
        stdout, stderr = self.run_bzr('status')
745
791