/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2007-2010, 2016 Canonical Ltd
2225.1.1 by Aaron Bentley
Added revert change display, with tests
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2225.1.1 by Aaron Bentley
Added revert change display, with tests
16
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
17
import os
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
20
    delta as _mod_delta,
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
21
    revision as _mod_revision,
2225.1.1 by Aaron Bentley
Added revert change display, with tests
22
    tests,
23
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
24
from ..sixish import (
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
25
    StringIO,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
26
    )
2225.1.1 by Aaron Bentley
Added revert change display, with tests
27
28
2225.1.2 by Aaron Bentley
Ensure that changes are detected correctly
29
class InstrumentedReporter(object):
30
    def __init__(self):
31
        self.calls = []
32
33
    def report(self, file_id, path, versioned, renamed, modified, exe_change,
34
               kind):
35
        self.calls.append((file_id, path, versioned, renamed, modified,
36
                           exe_change, kind))
37
2225.1.4 by Aaron Bentley
PEP8 cleanup
38
2225.1.1 by Aaron Bentley
Added revert change display, with tests
39
class TestReportChanges(tests.TestCase):
2225.1.4 by Aaron Bentley
PEP8 cleanup
40
    """Test the new change reporting infrastructure"""
2225.1.1 by Aaron Bentley
Added revert change display, with tests
41
2225.1.3 by Aaron Bentley
change method names to assertFoo
42
    def assertReport(self, expected, file_id='fid', path='path',
43
                     versioned_change='unchanged', renamed=False,
44
                     modified='unchanged', exe_change=False,
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
45
                     kind=('file', 'file'), old_path=None,
3586.1.30 by Ian Clatworthy
add view support to change reporting
46
                     unversioned_filter=None, view_info=None):
47
        if expected is None:
48
            expected_lines = None
49
        else:
50
            expected_lines = [expected]
51
        self.assertReportLines(expected_lines, file_id, path,
52
                     versioned_change, renamed,
53
                     modified, exe_change,
54
                     kind, old_path,
55
                     unversioned_filter, view_info)
56
57
    def assertReportLines(self, expected_lines, file_id='fid', path='path',
58
                     versioned_change='unchanged', renamed=False,
59
                     modified='unchanged', exe_change=False,
60
                     kind=('file', 'file'), old_path=None,
61
                     unversioned_filter=None, view_info=None):
2225.1.1 by Aaron Bentley
Added revert change display, with tests
62
        result = []
63
        def result_line(format, *args):
64
            result.append(format % args)
1551.10.25 by Aaron Bentley
Make ChangeReporter private
65
        reporter = _mod_delta._ChangeReporter(result_line,
3586.1.30 by Ian Clatworthy
add view support to change reporting
66
            unversioned_filter=unversioned_filter, view_info=view_info)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
67
        reporter.report(file_id, (old_path, path), versioned_change, renamed,
68
            modified, exe_change, kind)
3586.1.30 by Ian Clatworthy
add view support to change reporting
69
        if expected_lines is not None:
5422.3.8 by Martin Pool
Try for a better failure message in test_delta
70
            self.assertEqualDiff('\n'.join(expected_lines), '\n'.join(result))
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
71
        else:
72
            self.assertEqual([], result)
2225.1.1 by Aaron Bentley
Added revert change display, with tests
73
74
    def test_rename(self):
2225.1.3 by Aaron Bentley
change method names to assertFoo
75
        self.assertReport('R   old => path', renamed=True, old_path='old')
76
        self.assertReport('    path')
1551.10.12 by Aaron Bentley
Handle simultaneous creation+rename
77
        self.assertReport('RN  old => path', renamed=True, old_path='old',
78
                          modified='created', kind=(None, 'file'))
2225.1.1 by Aaron Bentley
Added revert change display, with tests
79
80
    def test_kind(self):
2225.1.3 by Aaron Bentley
change method names to assertFoo
81
        self.assertReport(' K  path => path/', modified='kind changed',
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
82
                          kind=('file', 'directory'), old_path='path')
2225.1.3 by Aaron Bentley
change method names to assertFoo
83
        self.assertReport(' K  path/ => path', modified='kind changed',
84
                          kind=('directory', 'file'), old_path='old')
85
        self.assertReport('RK  old => path/', renamed=True,
2225.1.5 by Aaron Bentley
Clean up whitespace changes
86
                          modified='kind changed',
2225.1.3 by Aaron Bentley
change method names to assertFoo
87
                          kind=('file', 'directory'), old_path='old')
2225.1.1 by Aaron Bentley
Added revert change display, with tests
88
    def test_new(self):
2225.1.3 by Aaron Bentley
change method names to assertFoo
89
        self.assertReport(' N  path/', modified='created',
90
                          kind=(None, 'directory'))
91
        self.assertReport('+   path/', versioned_change='added',
92
                          modified='unchanged', kind=(None, 'directory'))
1551.10.11 by Aaron Bentley
Handle case where file-id only is added
93
        self.assertReport('+   path', versioned_change='added',
94
                          modified='unchanged', kind=(None, None))
2225.1.3 by Aaron Bentley
change method names to assertFoo
95
        self.assertReport('+N  path/', versioned_change='added',
96
                          modified='created', kind=(None, 'directory'))
97
        self.assertReport('+M  path/', versioned_change='added',
98
                          modified='modified', kind=(None, 'directory'))
2225.1.1 by Aaron Bentley
Added revert change display, with tests
99
100
    def test_removal(self):
2225.1.3 by Aaron Bentley
change method names to assertFoo
101
        self.assertReport(' D  path/', modified='deleted',
102
                          kind=('directory', None), old_path='old')
103
        self.assertReport('-   path/', versioned_change='removed',
2255.2.232 by Robert Collins
Make WorkingTree4 report support for references based on the repositories capabilities.
104
                          old_path='path',
2225.1.3 by Aaron Bentley
change method names to assertFoo
105
                          kind=(None, 'directory'))
106
        self.assertReport('-D  path', versioned_change='removed',
2255.2.232 by Robert Collins
Make WorkingTree4 report support for references based on the repositories capabilities.
107
                          old_path='path',
2225.1.3 by Aaron Bentley
change method names to assertFoo
108
                          modified='deleted', kind=('file', 'directory'))
2225.1.1 by Aaron Bentley
Added revert change display, with tests
109
110
    def test_modification(self):
2225.1.3 by Aaron Bentley
change method names to assertFoo
111
        self.assertReport(' M  path', modified='modified')
112
        self.assertReport(' M* path', modified='modified', exe_change=True)
2225.1.2 by Aaron Bentley
Ensure that changes are detected correctly
113
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
114
    def test_unversioned(self):
115
        # by default any unversioned file is output
116
        self.assertReport('?   subdir/foo~', file_id=None, path='subdir/foo~',
117
            old_path=None, versioned_change='unversioned',
118
            renamed=False, modified='created', exe_change=False,
119
            kind=(None, 'file'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
120
        # but we can choose to filter these. Probably that should be done
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
121
        # close to the tree, but this is a reasonable starting point.
122
        self.assertReport(None, file_id=None, path='subdir/foo~',
123
            old_path=None, versioned_change='unversioned',
124
            renamed=False, modified='created', exe_change=False,
125
            kind=(None, 'file'), unversioned_filter=lambda x:True)
126
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
127
    def test_missing(self):
128
        self.assertReport('+!  missing.c', file_id=None, path='missing.c',
129
             old_path=None, versioned_change='added',
130
             renamed=False, modified='missing', exe_change=False,
131
             kind=(None, None))
132
3586.1.30 by Ian Clatworthy
add view support to change reporting
133
    def test_view_filtering(self):
134
        # If a file in within the view, it should appear in the output
135
        expected_lines = [
136
            "Operating on whole tree but only reporting on 'my' view.",
137
            " M  path"]
138
        self.assertReportLines(expected_lines, modified='modified',
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
139
            view_info=('my', ['path']))
3586.1.30 by Ian Clatworthy
add view support to change reporting
140
        # If a file in outside the view, it should not appear in the output
141
        expected_lines = [
142
            "Operating on whole tree but only reporting on 'my' view."]
143
        self.assertReportLines(expected_lines, modified='modified',
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
144
            path="foo", view_info=('my', ['path']))
3586.1.30 by Ian Clatworthy
add view support to change reporting
145
2225.1.3 by Aaron Bentley
change method names to assertFoo
146
    def assertChangesEqual(self,
147
                           file_id='fid',
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
148
                           paths=('path', 'path'),
2225.1.3 by Aaron Bentley
change method names to assertFoo
149
                           content_change=False,
150
                           versioned=(True, True),
151
                           parent_id=('pid', 'pid'),
152
                           name=('name', 'name'),
153
                           kind=('file', 'file'),
154
                           executable=(False, False),
155
                           versioned_change='unchanged',
156
                           renamed=False,
157
                           modified='unchanged',
158
                           exe_change=False):
2225.1.2 by Aaron Bentley
Ensure that changes are detected correctly
159
        reporter = InstrumentedReporter()
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
160
        _mod_delta.report_changes([(file_id, paths, content_change, versioned,
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
161
            parent_id, name, kind, executable)], reporter)
2225.1.2 by Aaron Bentley
Ensure that changes are detected correctly
162
        output = reporter.calls[0]
163
        self.assertEqual(file_id, output[0])
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
164
        self.assertEqual(paths, output[1])
2225.1.2 by Aaron Bentley
Ensure that changes are detected correctly
165
        self.assertEqual(versioned_change, output[2])
166
        self.assertEqual(renamed, output[3])
167
        self.assertEqual(modified, output[4])
168
        self.assertEqual(exe_change, output[5])
169
        self.assertEqual(kind, output[6])
170
171
    def test_report_changes(self):
172
        """Test change detection of report_changes"""
173
        #Ensure no changes are detected by default
2225.1.3 by Aaron Bentley
change method names to assertFoo
174
        self.assertChangesEqual(modified='unchanged', renamed=False,
175
                                versioned_change='unchanged',
176
                                exe_change=False)
177
        self.assertChangesEqual(modified='kind changed',
178
                                kind=('file', 'directory'))
179
        self.assertChangesEqual(modified='created', kind=(None, 'directory'))
180
        self.assertChangesEqual(modified='deleted', kind=('directory', None))
181
        self.assertChangesEqual(content_change=True, modified='modified')
182
        self.assertChangesEqual(renamed=True, name=('old', 'new'))
183
        self.assertChangesEqual(renamed=True,
184
                                parent_id=('old-parent', 'new-parent'))
185
        self.assertChangesEqual(versioned_change='added',
186
                                versioned=(False, True))
187
        self.assertChangesEqual(versioned_change='removed',
188
                                versioned=(True, False))
2225.1.2 by Aaron Bentley
Ensure that changes are detected correctly
189
        # execute bit is only detected as "changed" if the file is and was
190
        # a regular file.
2225.1.3 by Aaron Bentley
change method names to assertFoo
191
        self.assertChangesEqual(exe_change=True, executable=(True, False))
192
        self.assertChangesEqual(exe_change=False, executable=(True, False),
193
                                kind=('directory', 'directory'))
194
        self.assertChangesEqual(exe_change=False, modified='kind changed',
195
                                executable=(False, True),
196
                                kind=('directory', 'file'))
1551.11.3 by Aaron Bentley
Use tree transform to emit upcoming change list
197
        self.assertChangesEqual(parent_id=('pid', None))
2225.1.2 by Aaron Bentley
Ensure that changes are detected correctly
198
199
        # Now make sure they all work together
2225.1.3 by Aaron Bentley
change method names to assertFoo
200
        self.assertChangesEqual(versioned_change='removed',
201
                                modified='deleted', versioned=(True, False),
202
                                kind=('directory', None))
203
        self.assertChangesEqual(versioned_change='removed',
204
                                modified='created', versioned=(True, False),
205
                                kind=(None, 'file'))
206
        self.assertChangesEqual(versioned_change='removed',
207
                                modified='modified', renamed=True,
208
                                exe_change=True, versioned=(True, False),
209
                                content_change=True, name=('old', 'new'),
210
                                executable=(False, True))
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
211
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
212
    def test_report_unversioned(self):
213
        """Unversioned entries are reported well."""
214
        self.assertChangesEqual(file_id=None, paths=(None, 'full/path'),
215
                           content_change=True,
216
                           versioned=(False, False),
217
                           parent_id=(None, None),
218
                           name=(None, 'path'),
219
                           kind=(None, 'file'),
220
                           executable=(None, False),
221
                           versioned_change='unversioned',
222
                           renamed=False,
223
                           modified='created',
224
                           exe_change=False)
225
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
226
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
227
class TestChangesFrom(tests.TestCaseWithTransport):
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
228
229
    def show_string(self, delta, *args,  **kwargs):
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
230
        to_file = StringIO()
5076.4.8 by Arnaud Jeansen
Correct last delta.show() call in test_delta
231
        _mod_delta.report_delta(to_file, delta, *args, **kwargs)
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
232
        return to_file.getvalue()
233
234
    def test_kind_change(self):
235
        """Doing a status when a file has changed kind should work"""
236
        tree = self.make_branch_and_tree('.')
237
        self.build_tree(['filename'])
6855.3.1 by Jelmer Vernooij
Several more fixes.
238
        tree.add('filename', b'file-id')
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
239
        tree.commit('added filename')
240
        os.unlink('filename')
241
        self.build_tree(['filename/'])
242
        delta = tree.changes_from(tree.basis_tree())
6855.3.1 by Jelmer Vernooij
Several more fixes.
243
        self.assertEqual([('filename', b'file-id', 'file', 'directory')],
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
244
                         delta.kind_changed)
245
        self.assertEqual([], delta.added)
246
        self.assertEqual([], delta.removed)
247
        self.assertEqual([], delta.renamed)
248
        self.assertEqual([], delta.modified)
249
        self.assertEqual([], delta.unchanged)
250
        self.assertTrue(delta.has_changed())
6855.3.1 by Jelmer Vernooij
Several more fixes.
251
        self.assertTrue(delta.touches_file_id(b'file-id'))
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
252
        self.assertEqual('kind changed:\n  filename (file => directory)\n',
253
                         self.show_string(delta))
254
        other_delta = _mod_delta.TreeDelta()
255
        self.assertNotEqual(other_delta, delta)
6855.3.1 by Jelmer Vernooij
Several more fixes.
256
        other_delta.kind_changed = [('filename', b'file-id', 'file',
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
257
                                     'symlink')]
258
        self.assertNotEqual(other_delta, delta)
6855.3.1 by Jelmer Vernooij
Several more fixes.
259
        other_delta.kind_changed = [('filename', b'file-id', 'file',
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
260
                                     'directory')]
261
        self.assertEqual(other_delta, delta)
262
        self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
6855.3.3 by Jelmer Vernooij
Fix tests on python2.
263
            " kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
264
            " modified=[], unchanged=[], unversioned=[])", repr(delta))
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
265
        self.assertEqual('K  filename (file => directory) file-id\n',
266
                         self.show_string(delta, show_ids=True,
267
                         short_status=True))
268
269
        tree.rename_one('filename', 'dirname')
270
        delta = tree.changes_from(tree.basis_tree())
271
        self.assertEqual([], delta.kind_changed)
272
        # This loses the fact that kind changed, remembering it as a
273
        # modification
6855.3.1 by Jelmer Vernooij
Several more fixes.
274
        self.assertEqual([('filename', 'dirname', b'file-id', 'directory',
1551.10.6 by Aaron Bentley
Support kind changes in tree deltas
275
                           True, False)], delta.renamed)
276
        self.assertTrue(delta.has_changed())
6855.3.1 by Jelmer Vernooij
Several more fixes.
277
        self.assertTrue(delta.touches_file_id(b'file-id'))
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
278
279
280
class TestDeltaShow(tests.TestCaseWithTransport):
281
282
    def _get_delta(self):
283
        # We build the delta from a real tree to avoid depending on internal
284
        # implementation details.
285
        wt = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
286
        self.build_tree_contents([('branch/f1', b'1\n'),
287
                                  ('branch/f2', b'2\n'),
288
                                  ('branch/f3', b'3\n'),
289
                                  ('branch/f4', b'4\n'),
290
                                  ('branch/f5', b'5\n'),
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
291
                                  ('branch/dir/',),
292
                                 ])
293
        wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
294
               [b'f1-id', b'f2-id', b'f3-id', b'f4-id', b'dir-id'])
295
        wt.commit('commit one', rev_id=b'1')
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
296
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
297
        # TODO add rename,removed,etc. here?
298
        wt.add('f5')
299
        os.unlink('branch/f5')
300
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
301
        long_status = """added:
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
302
  dir/
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
303
  f1
304
  f2
305
  f3
306
  f4
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
307
missing:
308
  f5
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
309
"""
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
310
        short_status = """A  dir/
311
A  f1
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
312
A  f2
313
A  f3
314
A  f4
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
315
!  f5
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
316
"""
317
318
        repo = wt.branch.repository
319
        d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
320
        return d, long_status, short_status
321
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
322
    def test_short_status(self):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
323
        d, long_status, short_status = self._get_delta()
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
324
        out = StringIO()
5076.4.5 by Arnaud Jeansen
Ported test_delta to the report_delta method
325
        _mod_delta.report_delta(out, d, short_status=True)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
326
        self.assertEqual(short_status, out.getvalue())
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
327
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
328
    def test_long_status(self):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
329
        d, long_status, short_status = self._get_delta()
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
330
        out = StringIO()
5076.4.5 by Arnaud Jeansen
Ported test_delta to the report_delta method
331
        _mod_delta.report_delta(out, d, short_status=False)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
332
        self.assertEqual(long_status, out.getvalue())
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
333
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
334
    def test_predicate_always(self):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
335
        d, long_status, short_status = self._get_delta()
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
336
        out = StringIO()
337
        def always(path, file_id):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
338
            return True
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
339
        _mod_delta.report_delta(out, d, short_status=True, predicate=always)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
340
        self.assertEqual(short_status, out.getvalue())
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
341
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
342
    def test_short_status_path_predicate(self):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
343
        d, long_status, short_status = self._get_delta()
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
344
        out = StringIO()
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
345
        def only_f2(path, file_id):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
346
            return path == 'f2'
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
347
        _mod_delta.report_delta(out, d, short_status=True, predicate=only_f2)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
348
        self.assertEqual("A  f2\n", out.getvalue())
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
349
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
350
    def test_long_status_path_predicate(self):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
351
        d, long_status, short_status = self._get_delta()
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
352
        out = StringIO()
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
353
        def only_f2(path, file_id):
3874.3.5 by Vincent Ladeuil
Add a 'path_filter' parameter to delta.show().
354
            return path == 'f2'
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
355
        _mod_delta.report_delta(out, d, short_status=False, predicate=only_f2)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
356
        self.assertEqual("added:\n  f2\n", out.getvalue())
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
357
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
358
    def test_long_status_id_predicate(self):
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
359
        d, long_status, short_status = self._get_delta()
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
360
        out = StringIO()
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
361
        def only_f2_id(path, file_id):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
362
            return file_id == b'f2-id'
6631.4.1 by Martin
Rename report_delta param from filter to predicate with tests and release notes
363
        _mod_delta.report_delta(out, d, predicate=only_f2_id)
364
        self.assertEqual("added:\n  f2\n", out.getvalue())
3874.3.6 by Vincent Ladeuil
Make the filter work for paths and file ids.
365