/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/test_delta.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:
50
50
        else:
51
51
            expected_lines = [expected]
52
52
        self.assertReportLines(expected_lines, file_id, path,
53
 
                     versioned_change, renamed,
54
 
                     modified, exe_change,
55
 
                     kind, old_path,
56
 
                     unversioned_filter, view_info)
 
53
                               versioned_change, renamed,
 
54
                               modified, exe_change,
 
55
                               kind, old_path,
 
56
                               unversioned_filter, view_info)
57
57
 
58
58
    def assertReportLines(self, expected_lines, file_id=b'fid', path='path',
59
 
                     versioned_change='unchanged', renamed=False,
60
 
                     modified='unchanged', exe_change=False,
61
 
                     kind=('file', 'file'), old_path=None,
62
 
                     unversioned_filter=None, view_info=None):
 
59
                          versioned_change='unchanged', renamed=False,
 
60
                          modified='unchanged', exe_change=False,
 
61
                          kind=('file', 'file'), old_path=None,
 
62
                          unversioned_filter=None, view_info=None):
63
63
        result = []
 
64
 
64
65
        def result_line(format, *args):
65
66
            result.append(format % args)
66
67
        reporter = _mod_delta._ChangeReporter(result_line,
67
 
            unversioned_filter=unversioned_filter, view_info=view_info)
 
68
                                              unversioned_filter=unversioned_filter, view_info=view_info)
68
69
        reporter.report(file_id, (old_path, path), versioned_change, renamed,
69
 
            modified, exe_change, kind)
 
70
                        modified, exe_change, kind)
70
71
        if expected_lines is not None:
71
72
            self.assertEqualDiff('\n'.join(expected_lines), '\n'.join(result))
72
73
        else:
86
87
        self.assertReport('RK  old => path/', renamed=True,
87
88
                          modified='kind changed',
88
89
                          kind=('file', 'directory'), old_path='old')
 
90
 
89
91
    def test_new(self):
90
92
        self.assertReport(' N  path/', modified='created',
91
93
                          kind=(None, 'directory'))
115
117
    def test_unversioned(self):
116
118
        # by default any unversioned file is output
117
119
        self.assertReport('?   subdir/foo~', file_id=None, path='subdir/foo~',
118
 
            old_path=None, versioned_change='unversioned',
119
 
            renamed=False, modified='created', exe_change=False,
120
 
            kind=(None, 'file'))
 
120
                          old_path=None, versioned_change='unversioned',
 
121
                          renamed=False, modified='created', exe_change=False,
 
122
                          kind=(None, 'file'))
121
123
        # but we can choose to filter these. Probably that should be done
122
124
        # close to the tree, but this is a reasonable starting point.
123
125
        self.assertReport(None, file_id=None, path='subdir/foo~',
124
 
            old_path=None, versioned_change='unversioned',
125
 
            renamed=False, modified='created', exe_change=False,
126
 
            kind=(None, 'file'), unversioned_filter=lambda x:True)
 
126
                          old_path=None, versioned_change='unversioned',
 
127
                          renamed=False, modified='created', exe_change=False,
 
128
                          kind=(None, 'file'), unversioned_filter=lambda x: True)
127
129
 
128
130
    def test_missing(self):
129
131
        self.assertReport('+!  missing.c', file_id=None, path='missing.c',
130
 
             old_path=None, versioned_change='added',
131
 
             renamed=False, modified='missing', exe_change=False,
132
 
             kind=(None, None))
 
132
                          old_path=None, versioned_change='added',
 
133
                          renamed=False, modified='missing', exe_change=False,
 
134
                          kind=(None, None))
133
135
 
134
136
    def test_view_filtering(self):
135
137
        # If a file in within the view, it should appear in the output
137
139
            "Operating on whole tree but only reporting on 'my' view.",
138
140
            " M  path"]
139
141
        self.assertReportLines(expected_lines, modified='modified',
140
 
            view_info=('my', ['path']))
 
142
                               view_info=('my', ['path']))
141
143
        # If a file in outside the view, it should not appear in the output
142
144
        expected_lines = [
143
145
            "Operating on whole tree but only reporting on 'my' view."]
144
146
        self.assertReportLines(expected_lines, modified='modified',
145
 
            path="foo", view_info=('my', ['path']))
 
147
                               path="foo", view_info=('my', ['path']))
146
148
 
147
149
    def assertChangesEqual(self,
148
150
                           file_id=b'fid',
159
161
                           exe_change=False):
160
162
        reporter = InstrumentedReporter()
161
163
        _mod_delta.report_changes([(file_id, paths, content_change, versioned,
162
 
            parent_id, name, kind, executable)], reporter)
 
164
                                    parent_id, name, kind, executable)], reporter)
163
165
        output = reporter.calls[0]
164
166
        self.assertEqual(file_id, output[0])
165
167
        self.assertEqual(paths, output[1])
171
173
 
172
174
    def test_report_changes(self):
173
175
        """Test change detection of report_changes"""
174
 
        #Ensure no changes are detected by default
 
176
        # Ensure no changes are detected by default
175
177
        self.assertChangesEqual(modified='unchanged', renamed=False,
176
178
                                versioned_change='unchanged',
177
179
                                exe_change=False)
213
215
    def test_report_unversioned(self):
214
216
        """Unversioned entries are reported well."""
215
217
        self.assertChangesEqual(file_id=None, paths=(None, 'full/path'),
216
 
                           content_change=True,
217
 
                           versioned=(False, False),
218
 
                           parent_id=(None, None),
219
 
                           name=(None, 'path'),
220
 
                           kind=(None, 'file'),
221
 
                           executable=(None, False),
222
 
                           versioned_change='unversioned',
223
 
                           renamed=False,
224
 
                           modified='created',
225
 
                           exe_change=False)
 
218
                                content_change=True,
 
219
                                versioned=(False, False),
 
220
                                parent_id=(None, None),
 
221
                                name=(None, 'path'),
 
222
                                kind=(None, 'file'),
 
223
                                executable=(None, False),
 
224
                                versioned_change='unversioned',
 
225
                                renamed=False,
 
226
                                modified='created',
 
227
                                exe_change=False)
226
228
 
227
229
 
228
230
class TestChangesFrom(tests.TestCaseWithTransport):
229
231
 
230
 
    def show_string(self, delta, *args,  **kwargs):
 
232
    def show_string(self, delta, *args, **kwargs):
231
233
        to_file = StringIO()
232
234
        _mod_delta.report_delta(to_file, delta, *args, **kwargs)
233
235
        return to_file.getvalue()
262
264
        self.assertEqual(other_delta, delta)
263
265
        if PY3:
264
266
            self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
265
 
                " kind_changed=[('filename', b'file-id', 'file', 'directory')],"
266
 
                " modified=[], unchanged=[], unversioned=[])", repr(delta))
 
267
                                 " kind_changed=[('filename', b'file-id', 'file', 'directory')],"
 
268
                                 " modified=[], unchanged=[], unversioned=[])", repr(delta))
267
269
        else:
268
270
            self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
269
 
                " kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
270
 
                " modified=[], unchanged=[], unversioned=[])", repr(delta))
 
271
                                 " kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
 
272
                                 " modified=[], unchanged=[], unversioned=[])", repr(delta))
271
273
 
272
274
        self.assertEqual('K  filename (file => directory) file-id\n',
273
275
                         self.show_string(delta, show_ids=True,
274
 
                         short_status=True))
 
276
                                          short_status=True))
275
277
 
276
278
        tree.rename_one('filename', 'dirname')
277
279
        delta = tree.changes_from(tree.basis_tree())
296
298
                                  ('branch/f4', b'4\n'),
297
299
                                  ('branch/f5', b'5\n'),
298
300
                                  ('branch/dir/',),
299
 
                                 ])
 
301
                                  ])
300
302
        wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
301
303
               [b'f1-id', b'f2-id', b'f3-id', b'f4-id', b'dir-id'])
302
304
        wt.commit('commit one', rev_id=b'1')
341
343
    def test_predicate_always(self):
342
344
        d, long_status, short_status = self._get_delta()
343
345
        out = StringIO()
 
346
 
344
347
        def always(path, file_id):
345
348
            return True
346
349
        _mod_delta.report_delta(out, d, short_status=True, predicate=always)
349
352
    def test_short_status_path_predicate(self):
350
353
        d, long_status, short_status = self._get_delta()
351
354
        out = StringIO()
 
355
 
352
356
        def only_f2(path, file_id):
353
357
            return path == 'f2'
354
358
        _mod_delta.report_delta(out, d, short_status=True, predicate=only_f2)
357
361
    def test_long_status_path_predicate(self):
358
362
        d, long_status, short_status = self._get_delta()
359
363
        out = StringIO()
 
364
 
360
365
        def only_f2(path, file_id):
361
366
            return path == 'f2'
362
367
        _mod_delta.report_delta(out, d, short_status=False, predicate=only_f2)
365
370
    def test_long_status_id_predicate(self):
366
371
        d, long_status, short_status = self._get_delta()
367
372
        out = StringIO()
 
373
 
368
374
        def only_f2_id(path, file_id):
369
375
            return file_id == b'f2-id'
370
376
        _mod_delta.report_delta(out, d, predicate=only_f2_id)
371
377
        self.assertEqual("added:\n  f2\n", out.getvalue())
372