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