~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
45
45
 
46
46
class BranchStatus(TestCaseWithTransport):
47
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
 
 
56
 
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
 
48
    def assertStatus(self, expected_lines, working_tree,
57
49
        revision=None, short=False, pending=True, verbose=False):
58
50
        """Run status in working_tree and look for output.
59
51
 
60
52
        :param expected_lines: The lines to look for.
61
53
        :param working_tree: The tree to run status in.
62
54
        """
63
 
        output_string = self.status_string(working_tree, specific_files, revision, short,
 
55
        output_string = self.status_string(working_tree, revision, short,
64
56
                pending, verbose)
65
57
        self.assertEqual(expected_lines, output_string.splitlines(True))
66
58
 
67
 
    def status_string(self, wt, specific_files=None, revision=None,
68
 
        short=False, pending=True, verbose=False):
 
59
    def status_string(self, wt, revision=None, short=False, pending=True,
 
60
        verbose=False):
69
61
        # use a real file rather than StringIO because it doesn't handle
70
62
        # Unicode very well.
71
63
        tof = codecs.getwriter('utf-8')(TemporaryFile())
72
 
        show_tree_status(wt, specific_files=specific_files, to_file=tof,
73
 
                revision=revision, short=short, show_pending=pending,
74
 
                verbose=verbose)
 
64
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
 
65
                show_pending=pending, verbose=verbose)
75
66
        tof.seek(0)
76
67
        return tof.read().decode('utf-8')
77
68
 
188
179
        wt2.merge_from_branch(wt.branch)
189
180
        message = self.status_string(wt2, verbose=True)
190
181
        self.assertStartsWith(message, "pending merges:\n")
191
 
        self.assertTrue("Empty commit 3" in message)
 
182
        self.assert_("Empty commit 3" in message)
192
183
        self.assertEndsWith(message, "...\n")
193
184
 
194
185
    def test_tree_status_ignores(self):
212
203
        wt = self.make_branch_and_tree('.')
213
204
        b = wt.branch
214
205
 
215
 
        self.build_tree(['directory/','directory/hello.c',
216
 
                         'bye.c','test.c','dir2/',
217
 
                         'missing.c'])
 
206
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
218
207
        wt.add('directory')
219
208
        wt.add('test.c')
220
209
        wt.commit('testing')
221
 
        wt.add('missing.c')
222
 
        unlink('missing.c')
223
210
 
224
211
        self.assertStatus([
225
 
                'missing:\n',
226
 
                '  missing.c\n',
227
212
                'unknown:\n',
228
213
                '  bye.c\n',
229
214
                '  dir2/\n',
234
219
        self.assertStatus([
235
220
                '?   bye.c\n',
236
221
                '?   dir2/\n',
237
 
                '+!  missing.c\n',
238
222
                '?   directory/hello.c\n'
239
223
                ],
240
224
                wt, short=True)
248
232
        tof = StringIO()
249
233
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
250
234
        tof.seek(0)
251
 
        self.assertEqual(tof.readlines(),
 
235
        self.assertEquals(tof.readlines(),
252
236
                          ['unknown:\n',
253
237
                           '  directory/hello.c\n'
254
238
                           ])
256
240
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
257
241
                         short=True)
258
242
        tof.seek(0)
259
 
        self.assertEqual(tof.readlines(), ['?   directory/hello.c\n'])
 
243
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
260
244
 
261
245
        tof = StringIO()
262
246
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
263
247
        tof.seek(0)
264
 
        self.assertEqual(tof.readlines(),
 
248
        self.assertEquals(tof.readlines(),
265
249
                          ['unknown:\n',
266
250
                           '  dir2/\n'
267
251
                           ])
268
252
        tof = StringIO()
269
253
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
270
254
        tof.seek(0)
271
 
        self.assertEqual(tof.readlines(), ['?   dir2/\n'])
 
255
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
272
256
 
273
257
        tof = StringIO()
274
258
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
275
259
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
276
260
                         short=True, revision=revs)
277
261
        tof.seek(0)
278
 
        self.assertEqual(tof.readlines(), ['+N  test.c\n'])
279
 
 
280
 
        tof = StringIO()
281
 
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
282
 
        tof.seek(0)
283
 
        self.assertEqual(tof.readlines(),
284
 
                          ['missing:\n',
285
 
                           '  missing.c\n'])
286
 
 
287
 
        tof = StringIO()
288
 
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
289
 
                         short=True)
290
 
        tof.seek(0)
291
 
        self.assertEqual(tof.readlines(),
292
 
                          ['+!  missing.c\n'])
 
262
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
293
263
 
294
264
    def test_specific_files_conflicts(self):
295
265
        tree = self.make_branch_and_tree('.')
325
295
        wt.add('FILE_D')
326
296
        wt.add('FILE_E')
327
297
        wt.commit('Create five empty files.')
328
 
        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
329
 
        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
 
298
        open('FILE_B', 'w').write('Modification to file FILE_B.')
 
299
        open('FILE_C', 'w').write('Modification to file FILE_C.')
330
300
        unlink('FILE_E')  # FILE_E will be versioned but missing
331
 
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
 
301
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
332
302
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
333
303
        open('UNVERSIONED_BUT_EXISTING', 'w')
334
304
        return wt
478
448
          ' M  FILE_B\n',
479
449
          'X   NONEXISTENT\n',
480
450
          ]
481
 
        expected.sort()
482
451
        out, err = self.run_bzr('status --short NONEXISTENT '
483
452
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
484
453
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
485
 
        actual = out.splitlines(True)
486
 
        actual.sort()
487
 
        self.assertEqual(expected, actual)
 
454
        self.assertEqual(expected, out.splitlines(True))
488
455
        self.assertContainsRe(err,
489
456
                              r'.*ERROR: Path\(s\) do not exist: '
490
457
                              'NONEXISTENT.*')
563
530
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
564
531
        self.build_tree(['bye.c'])
565
532
        wt.add('bye.c')
 
533
        # As TestCase.setUp clears all hooks, we install this default
 
534
        # post_status hook handler for the test.
 
535
        status.hooks.install_named_hook('post_status',
 
536
            status._show_shelve_summary,
 
537
            'bzr status')
566
538
        self.assertStatus([
567
539
                'added:\n',
568
540
                '  bye.c\n',
569
 
                '1 shelf exists. See "bzr shelve --list" for details.\n',
570
 
            ],
571
 
            wt)
572
 
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
573
 
        self.build_tree(['eggs.c', 'spam.c'])
574
 
        wt.add('eggs.c')
575
 
        wt.add('spam.c')
576
 
        self.assertStatus([
577
 
                'added:\n',
578
 
                '  eggs.c\n',
579
 
                '  spam.c\n',
580
 
                '2 shelves exist. See "bzr shelve --list" for details.\n',
581
 
            ],
582
 
            wt)
583
 
        self.assertStatus([
584
 
                'added:\n',
585
 
                '  spam.c\n',
586
 
            ],
587
 
            wt,
588
 
            specific_files=['spam.c'])
 
541
                '1 shelves exist. See "bzr shelve --list" for details.\n',
 
542
            ],
 
543
            wt)
589
544
 
590
545
 
591
546
class CheckoutStatus(BranchStatus):
598
553
    def make_branch_and_tree(self, relpath):
599
554
        source = self.make_branch(pathjoin('..', relpath))
600
555
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
601
 
        checkout.set_branch_reference(source)
 
556
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
 
557
            target_branch=source)
602
558
        return checkout.create_workingtree()
603
559
 
604
560
 
627
583
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
628
584
                                      "unknown:\n  world.txt\n")
629
585
        result2 = self.run_bzr("status -r 0..")[0]
630
 
        self.assertEqual(result2, result)
 
586
        self.assertEquals(result2, result)
631
587
 
632
588
    def test_status_short(self):
633
589
        tree = self.make_branch_and_tree('.')
645
601
        self.assertContainsRe(result, "[+]N  hello.txt\n")
646
602
 
647
603
        self.build_tree(['world.txt'])
648
 
        result = self.run_bzr("status -S -r 0")[0]
 
604
        result = self.run_bzr("status --short -r 0")[0]
649
605
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
650
606
                                      "[?]   world.txt\n")
651
 
        result2 = self.run_bzr("status -S -r 0..")[0]
652
 
        self.assertEqual(result2, result)
 
607
        result2 = self.run_bzr("status --short -r 0..")[0]
 
608
        self.assertEquals(result2, result)
653
609
 
654
610
    def test_status_versioned(self):
655
611
        tree = self.make_branch_and_tree('.')
671
627
        self.assertContainsRe(result, "added:\n  hello.txt\n")
672
628
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
673
629
        result2 = self.run_bzr("status --versioned -r 0..")[0]
674
 
        self.assertEqual(result2, result)
 
630
        self.assertEquals(result2, result)
675
631
 
676
632
    def test_status_SV(self):
677
633
        tree = self.make_branch_and_tree('.')
693
649
        self.assertContainsRe(result, "[+]N  hello.txt\n")
694
650
 
695
651
        result2 = self.run_bzr("status -SV -r 0..")[0]
696
 
        self.assertEqual(result2, result)
 
652
        self.assertEquals(result2, result)
697
653
 
698
654
    def assertStatusContains(self, pattern, short=False):
699
655
        """Run status, and assert it contains the given pattern"""
749
705
 
750
706
        self.run_bzr('merge ../b', working_dir='a')
751
707
        out, err = self.run_bzr('status --no-pending', working_dir='a')
752
 
        self.assertEqual(out, "added:\n  b\n")
 
708
        self.assertEquals(out, "added:\n  b\n")
753
709
 
754
710
    def test_pending_specific_files(self):
755
711
        """With a specific file list, pending merges are not shown."""
787
743
        working_tree = self.make_uncommitted_tree()
788
744
        stdout, stderr = self.run_bzr("status")
789
745
 
790
 
        self.assertEqual(stdout, """\
 
746
        self.assertEquals(stdout, """\
791
747
added:
792
748
  hell?
793
749
""")
797
753
        working_tree = self.make_uncommitted_tree()
798
754
        stdout, stderr = self.run_bzr('status')
799
755
 
800
 
        self.assertEqual(stdout, u"""\
 
756
        self.assertEquals(stdout, u"""\
801
757
added:
802
758
  hell\u00d8
803
759
""".encode('latin-1'))