/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
        # As TestCase.setUp clears all hooks, we install this default
56
56
        # post_status hook handler for the test.
57
57
        status.hooks.install_named_hook('post_status',
58
 
            status._show_shelve_summary,
59
 
            'brz status')
 
58
                                        status._show_shelve_summary,
 
59
                                        'brz status')
60
60
 
61
61
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
62
 
        revision=None, short=False, pending=True, verbose=False):
 
62
                     revision=None, short=False, pending=True, verbose=False):
63
63
        """Run status in working_tree and look for output.
64
64
 
65
65
        :param expected_lines: The lines to look for.
66
66
        :param working_tree: The tree to run status in.
67
67
        """
68
68
        output_string = self.status_string(working_tree, specific_files, revision, short,
69
 
                pending, verbose)
 
69
                                           pending, verbose)
70
70
        self.assertEqual(expected_lines, output_string.splitlines(True))
71
71
 
72
72
    def status_string(self, wt, specific_files=None, revision=None,
73
 
        short=False, pending=True, verbose=False):
 
73
                      short=False, pending=True, verbose=False):
74
74
        uio = self.make_utf8_encoded_stringio()
75
75
        show_tree_status(wt, specific_files=specific_files, to_file=uio,
76
 
                revision=revision, short=short, show_pending=pending,
77
 
                verbose=verbose)
 
76
                         revision=revision, short=short, show_pending=pending,
 
77
                         verbose=verbose)
78
78
        return uio.getvalue().decode('utf-8')
79
79
 
80
80
    def test_branch_status(self):
89
89
 
90
90
        self.build_tree(['hello.c', 'bye.c'])
91
91
        self.assertStatus([
92
 
                'unknown:\n',
93
 
                '  bye.c\n',
94
 
                '  hello.c\n',
 
92
            'unknown:\n',
 
93
            '  bye.c\n',
 
94
            '  hello.c\n',
95
95
            ],
96
96
            wt)
97
97
        self.assertStatus([
98
 
                '?   bye.c\n',
99
 
                '?   hello.c\n',
 
98
            '?   bye.c\n',
 
99
            '?   hello.c\n',
100
100
            ],
101
101
            wt, short=True)
102
102
 
105
105
 
106
106
        wt.add_parent_tree_id(b'pending@pending-0-0')
107
107
        self.assertStatus([
108
 
                'unknown:\n',
109
 
                '  bye.c\n',
110
 
                '  hello.c\n',
111
 
                'pending merge tips: (use -v to see all merge revisions)\n',
112
 
                '  (ghost) pending@pending-0-0\n',
 
108
            'unknown:\n',
 
109
            '  bye.c\n',
 
110
            '  hello.c\n',
 
111
            'pending merge tips: (use -v to see all merge revisions)\n',
 
112
            '  (ghost) pending@pending-0-0\n',
113
113
            ],
114
114
            wt)
115
115
        self.assertStatus([
116
 
                'unknown:\n',
117
 
                '  bye.c\n',
118
 
                '  hello.c\n',
119
 
                'pending merges:\n',
120
 
                '  (ghost) pending@pending-0-0\n',
 
116
            'unknown:\n',
 
117
            '  bye.c\n',
 
118
            '  hello.c\n',
 
119
            'pending merges:\n',
 
120
            '  (ghost) pending@pending-0-0\n',
121
121
            ],
122
122
            wt, verbose=True)
123
123
        self.assertStatus([
124
 
                '?   bye.c\n',
125
 
                '?   hello.c\n',
126
 
                'P   (ghost) pending@pending-0-0\n',
 
124
            '?   bye.c\n',
 
125
            '?   hello.c\n',
 
126
            'P   (ghost) pending@pending-0-0\n',
127
127
            ],
128
128
            wt, short=True)
129
129
        self.assertStatus([
130
 
                'unknown:\n',
131
 
                '  bye.c\n',
132
 
                '  hello.c\n',
 
130
            'unknown:\n',
 
131
            '  bye.c\n',
 
132
            '  hello.c\n',
133
133
            ],
134
134
            wt, pending=False)
135
135
        self.assertStatus([
136
 
                '?   bye.c\n',
137
 
                '?   hello.c\n',
 
136
            '?   bye.c\n',
 
137
            '?   hello.c\n',
138
138
            ],
139
139
            wt, short=True, pending=False)
140
140
 
149
149
 
150
150
        revs = [RevisionSpec.from_string('0')]
151
151
        self.assertStatus([
152
 
                'added:\n',
153
 
                '  bye.c\n',
154
 
                '  hello.c\n'
 
152
            'added:\n',
 
153
            '  bye.c\n',
 
154
            '  hello.c\n'
155
155
            ],
156
156
            wt,
157
157
            revision=revs)
162
162
 
163
163
        revs.append(RevisionSpec.from_string('1'))
164
164
        self.assertStatus([
165
 
                'added:\n',
166
 
                '  bye.c\n',
167
 
                '  hello.c\n',
 
165
            'added:\n',
 
166
            '  bye.c\n',
 
167
            '  hello.c\n',
168
168
            ],
169
169
            wt,
170
170
            revision=revs)
185
185
        self.assertEndsWith(message, "Empty commit 2\n")
186
186
        wt2.commit("merged")
187
187
        # must be long to make sure we see elipsis at the end
188
 
        wt.commit("Empty commit 3 " +
189
 
                   "blah blah blah blah " * 100)
 
188
        wt.commit("Empty commit 3 "
 
189
                  + "blah blah blah blah " * 100)
190
190
        wt2.merge_from_branch(wt.branch)
191
191
        message = self.status_string(wt2, verbose=True)
192
192
        self.assertStartsWith(message, "pending merges:\n")
200
200
        wt.commit('commit .bzrignore')
201
201
        self.build_tree(['foo.c', 'foo.c~'])
202
202
        self.assertStatus([
203
 
                'unknown:\n',
204
 
                '  foo.c\n',
205
 
                ],
206
 
                wt)
 
203
            'unknown:\n',
 
204
            '  foo.c\n',
 
205
            ],
 
206
            wt)
207
207
        self.assertStatus([
208
 
                '?   foo.c\n',
209
 
                ],
210
 
                wt, short=True)
 
208
            '?   foo.c\n',
 
209
            ],
 
210
            wt, short=True)
211
211
 
212
212
    def test_tree_status_specific_files(self):
213
213
        """Tests branch status with given specific files"""
224
224
        unlink('missing.c')
225
225
 
226
226
        self.assertStatus([
227
 
                'missing:\n',
228
 
                '  missing.c\n',
229
 
                'unknown:\n',
230
 
                '  bye.c\n',
231
 
                '  dir2/\n',
232
 
                '  directory/hello.c\n'
233
 
                ],
234
 
                wt)
 
227
            'missing:\n',
 
228
            '  missing.c\n',
 
229
            'unknown:\n',
 
230
            '  bye.c\n',
 
231
            '  dir2/\n',
 
232
            '  directory/hello.c\n'
 
233
            ],
 
234
            wt)
235
235
 
236
236
        self.assertStatus([
237
 
                '?   bye.c\n',
238
 
                '?   dir2/\n',
239
 
                '?   directory/hello.c\n',
240
 
                '+!  missing.c\n',
241
 
                ],
242
 
                wt, short=True)
 
237
            '?   bye.c\n',
 
238
            '?   dir2/\n',
 
239
            '?   directory/hello.c\n',
 
240
            '+!  missing.c\n',
 
241
            ],
 
242
            wt, short=True)
243
243
 
244
244
        tof = StringIO()
245
245
        self.assertRaises(errors.PathsDoNotExist,
251
251
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
252
252
        tof.seek(0)
253
253
        self.assertEqual(tof.readlines(),
254
 
                          ['unknown:\n',
255
 
                           '  directory/hello.c\n'
256
 
                           ])
 
254
                         ['unknown:\n',
 
255
                          '  directory/hello.c\n'
 
256
                          ])
257
257
        tof = StringIO()
258
258
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
259
259
                         short=True)
264
264
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
265
265
        tof.seek(0)
266
266
        self.assertEqual(tof.readlines(),
267
 
                          ['unknown:\n',
268
 
                           '  dir2/\n'
269
 
                           ])
 
267
                         ['unknown:\n',
 
268
                          '  dir2/\n'
 
269
                          ])
270
270
        tof = StringIO()
271
271
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
272
272
        tof.seek(0)
283
283
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
284
284
        tof.seek(0)
285
285
        self.assertEqual(tof.readlines(),
286
 
                          ['missing:\n',
287
 
                           '  missing.c\n'])
 
286
                         ['missing:\n',
 
287
                          '  missing.c\n'])
288
288
 
289
289
        tof = StringIO()
290
290
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
291
291
                         short=True)
292
292
        tof.seek(0)
293
293
        self.assertEqual(tof.readlines(),
294
 
                          ['+!  missing.c\n'])
 
294
                         ['+!  missing.c\n'])
295
295
 
296
296
    def test_specific_files_conflicts(self):
297
297
        tree = self.make_branch_and_tree('.')
327
327
        wt.add('FILE_D')
328
328
        wt.add('FILE_E')
329
329
        wt.commit('Create five empty files.')
330
 
        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
331
 
        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
 
330
        with open('FILE_B', 'w') as f:
 
331
            f.write('Modification to file FILE_B.')
 
332
        with open('FILE_C', 'w') as f:
 
333
            f.write('Modification to file FILE_C.')
332
334
        unlink('FILE_E')  # FILE_E will be versioned but missing
333
 
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
 
335
        with open('FILE_Q', 'w') as f:
 
336
            f.write('FILE_Q is added but not committed.')
334
337
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
335
338
        open('UNVERSIONED_BUT_EXISTING', 'w')
336
339
        return wt
365
368
 
366
369
        # brz st [--short] NONEXISTENT '
367
370
        expected = [
368
 
          'nonexistent:\n',
369
 
          '  NONEXISTENT\n',
370
 
          ]
 
371
            'nonexistent:\n',
 
372
            '  NONEXISTENT\n',
 
373
            ]
371
374
        out, err = self.run_bzr('status NONEXISTENT', retcode=3)
372
375
        self.assertEqual(expected, out.splitlines(True))
373
376
        self.assertContainsRe(err,
374
377
                              r'.*ERROR: Path\(s\) do not exist: '
375
378
                              'NONEXISTENT.*')
376
379
        expected = [
377
 
          'X:   NONEXISTENT\n',
378
 
          ]
 
380
            'X:   NONEXISTENT\n',
 
381
            ]
379
382
        out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
380
383
        self.assertContainsRe(err,
381
384
                              r'.*ERROR: Path\(s\) do not exist: '
385
388
        # brz st [--short] NONEXISTENT ...others..
386
389
        wt = self._prepare_nonexistent()
387
390
        expected = [
388
 
          'removed:\n',
389
 
          '  FILE_E\n',
390
 
          'modified:\n',
391
 
          '  FILE_B\n',
392
 
          '  FILE_C\n',
393
 
          'nonexistent:\n',
394
 
          '  NONEXISTENT\n',
395
 
          ]
 
391
            'removed:\n',
 
392
            '  FILE_E\n',
 
393
            'modified:\n',
 
394
            '  FILE_B\n',
 
395
            '  FILE_C\n',
 
396
            'nonexistent:\n',
 
397
            '  NONEXISTENT\n',
 
398
            ]
396
399
        out, err = self.run_bzr('status NONEXISTENT '
397
400
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
398
401
                                retcode=3)
401
404
                              r'.*ERROR: Path\(s\) do not exist: '
402
405
                              'NONEXISTENT.*')
403
406
        expected = [
404
 
          ' M  FILE_B\n',
405
 
          ' M  FILE_C\n',
406
 
          ' D  FILE_E\n',
407
 
          'X   NONEXISTENT\n',
408
 
          ]
 
407
            ' M  FILE_B\n',
 
408
            ' M  FILE_C\n',
 
409
            ' D  FILE_E\n',
 
410
            'X   NONEXISTENT\n',
 
411
            ]
409
412
        out, err = self.run_bzr('status --short NONEXISTENT '
410
413
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
411
414
                                retcode=3)
418
421
        # brz st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
419
422
        wt = self._prepare_nonexistent()
420
423
        expected = [
421
 
          'removed:\n',
422
 
          '  FILE_E\n',
423
 
          'modified:\n',
424
 
          '  FILE_B\n',
425
 
          '  FILE_C\n',
426
 
          'nonexistent:\n',
427
 
          '  ANOTHER_NONEXISTENT\n',
428
 
          '  NONEXISTENT\n',
429
 
          ]
 
424
            'removed:\n',
 
425
            '  FILE_E\n',
 
426
            'modified:\n',
 
427
            '  FILE_B\n',
 
428
            '  FILE_C\n',
 
429
            'nonexistent:\n',
 
430
            '  ANOTHER_NONEXISTENT\n',
 
431
            '  NONEXISTENT\n',
 
432
            ]
430
433
        out, err = self.run_bzr('status NONEXISTENT '
431
434
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
432
435
                                'FILE_C FILE_D FILE_E', retcode=3)
435
438
                              r'.*ERROR: Path\(s\) do not exist: '
436
439
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
437
440
        expected = [
438
 
          ' M  FILE_B\n',
439
 
          ' M  FILE_C\n',
440
 
          ' D  FILE_E\n',
441
 
          'X   ANOTHER_NONEXISTENT\n',
442
 
          'X   NONEXISTENT\n',
443
 
          ]
 
441
            ' M  FILE_B\n',
 
442
            ' M  FILE_C\n',
 
443
            ' D  FILE_E\n',
 
444
            'X   ANOTHER_NONEXISTENT\n',
 
445
            'X   NONEXISTENT\n',
 
446
            ]
444
447
        out, err = self.run_bzr('status --short NONEXISTENT '
445
448
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
446
449
                                'FILE_C FILE_D FILE_E', retcode=3)
453
456
        # brz st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
454
457
        wt = self._prepare_nonexistent()
455
458
        expected = [
456
 
          'removed:\n',
457
 
          '  FILE_E\n',
458
 
          'added:\n',
459
 
          '  FILE_Q\n',
460
 
          'modified:\n',
461
 
          '  FILE_B\n',
462
 
          '  FILE_C\n',
463
 
          'unknown:\n',
464
 
          '  UNVERSIONED_BUT_EXISTING\n',
465
 
          'nonexistent:\n',
466
 
          '  NONEXISTENT\n',
467
 
          ]
 
459
            'removed:\n',
 
460
            '  FILE_E\n',
 
461
            'added:\n',
 
462
            '  FILE_Q\n',
 
463
            'modified:\n',
 
464
            '  FILE_B\n',
 
465
            '  FILE_C\n',
 
466
            'unknown:\n',
 
467
            '  UNVERSIONED_BUT_EXISTING\n',
 
468
            'nonexistent:\n',
 
469
            '  NONEXISTENT\n',
 
470
            ]
468
471
        out, err = self.run_bzr('status NONEXISTENT '
469
472
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
470
473
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
473
476
                              r'.*ERROR: Path\(s\) do not exist: '
474
477
                              'NONEXISTENT.*')
475
478
        expected = sorted([
476
 
          '+N  FILE_Q\n',
477
 
          '?   UNVERSIONED_BUT_EXISTING\n',
478
 
          ' D  FILE_E\n',
479
 
          ' M  FILE_C\n',
480
 
          ' M  FILE_B\n',
481
 
          'X   NONEXISTENT\n',
482
 
          ])
 
479
            '+N  FILE_Q\n',
 
480
            '?   UNVERSIONED_BUT_EXISTING\n',
 
481
            ' D  FILE_E\n',
 
482
            ' M  FILE_C\n',
 
483
            ' M  FILE_B\n',
 
484
            'X   NONEXISTENT\n',
 
485
            ])
483
486
        out, err = self.run_bzr('status --short NONEXISTENT '
484
487
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
485
488
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
536
539
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
537
540
 
538
541
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
539
 
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
540
 
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
541
 
        self.assertContainsRe(short_result, "\\?   test1.c\nI   test1.c~\nI   test2.c~\n")
 
542
        self.assertContainsRe(
 
543
            result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
 
544
        short_result = self.run_bzr(
 
545
            'status --short test1.c test1.c~ test2.c~')[0]
 
546
        self.assertContainsRe(
 
547
            short_result, "\\?   test1.c\nI   test1.c~\nI   test2.c~\n")
542
548
 
543
549
    def test_status_write_lock(self):
544
550
        """Test that status works without fetching history and
565
571
        self.build_tree(['bye.c'])
566
572
        wt.add('bye.c')
567
573
        self.assertStatus([
568
 
                'added:\n',
569
 
                '  bye.c\n',
570
 
                '1 shelf exists. See "brz shelve --list" for details.\n',
 
574
            'added:\n',
 
575
            '  bye.c\n',
 
576
            '1 shelf exists. See "brz shelve --list" for details.\n',
571
577
            ],
572
578
            wt)
573
579
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
575
581
        wt.add('eggs.c')
576
582
        wt.add('spam.c')
577
583
        self.assertStatus([
578
 
                'added:\n',
579
 
                '  eggs.c\n',
580
 
                '  spam.c\n',
581
 
                '2 shelves exist. See "brz shelve --list" for details.\n',
 
584
            'added:\n',
 
585
            '  eggs.c\n',
 
586
            '  spam.c\n',
 
587
            '2 shelves exist. See "brz shelve --list" for details.\n',
582
588
            ],
583
589
            wt)
584
590
        self.assertStatus([
585
 
                'added:\n',
586
 
                '  spam.c\n',
 
591
            'added:\n',
 
592
            '  spam.c\n',
587
593
            ],
588
594
            wt,
589
595
            specific_files=['spam.c'])
625
631
 
626
632
        self.build_tree(['world.txt'])
627
633
        result = self.run_bzr("status -r 0")[0]
628
 
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
 
634
        self.assertContainsRe(result, "added:\n  hello.txt\n"
629
635
                                      "unknown:\n  world.txt\n")
630
636
        result2 = self.run_bzr("status -r 0..")[0]
631
637
        self.assertEqual(result2, result)
647
653
 
648
654
        self.build_tree(['world.txt'])
649
655
        result = self.run_bzr("status -S -r 0")[0]
650
 
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
 
656
        self.assertContainsRe(result, "[+]N  hello.txt\n"
651
657
                                      "[?]   world.txt\n")
652
658
        result2 = self.run_bzr("status -S -r 0..")[0]
653
659
        self.assertEqual(result2, result)
711
717
        tree.commit('added file')
712
718
        unlink('file')
713
719
        self.build_tree(['file/'])
714
 
        self.assertStatusContains('kind changed:\n  file \\(file => directory\\)')
 
720
        self.assertStatusContains(
 
721
            'kind changed:\n  file \\(file => directory\\)')
715
722
        tree.rename_one('file', 'directory')
716
 
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
 
723
        self.assertStatusContains('renamed:\n  file/ => directory/\n'
717
724
                                  'modified:\n  directory/\n')
718
725
        rmdir('directory')
719
726
        self.assertStatusContains('removed:\n  file\n')
726
733
        unlink('file')
727
734
        self.build_tree(['file/'])
728
735
        self.assertStatusContains('K  file => file/',
729
 
                                   short=True)
 
736
                                  short=True)
730
737
        tree.rename_one('file', 'directory')
731
738
        self.assertStatusContains('RK  file => directory/',
732
 
                                   short=True)
 
739
                                  short=True)
733
740
        rmdir('directory')
734
741
        self.assertStatusContains('RD  file => directory',
735
 
                                   short=True)
 
742
                                  short=True)
736
743
 
737
744
    def test_status_illegal_revision_specifiers(self):
738
745
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
779
786
            self.build_tree_contents([(filename, b'contents of hello')])
780
787
        except UnicodeEncodeError:
781
788
            raise TestSkipped("can't build unicode working tree in "
782
 
                "filesystem encoding %s" % sys.getfilesystemencoding())
 
789
                              "filesystem encoding %s" % sys.getfilesystemencoding())
783
790
        working_tree.add(filename)
784
791
        return working_tree
785
792
 
805
812
        if not PY3:
806
813
            expected = expected.encode('latin-1')
807
814
        self.assertEqual(stdout, expected)
808