/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: Martin
  • Date: 2017-06-09 16:31:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6673.
  • Revision ID: gzlist@googlemail.com-20170609163149-liveiasey25480q6
Make InventoryDeltaError use string formatting, and repr for fileids

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2010, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
 
from cStringIO import StringIO
19
18
 
20
 
from bzrlib import (
 
19
from .. import (
21
20
    delta as _mod_delta,
22
21
    revision as _mod_revision,
23
22
    tests,
24
23
    )
 
24
from ..sixish import (
 
25
    StringIO,
 
26
    )
25
27
 
26
28
 
27
29
class InstrumentedReporter(object):
65
67
        reporter.report(file_id, (old_path, path), versioned_change, renamed,
66
68
            modified, exe_change, kind)
67
69
        if expected_lines is not None:
68
 
            for i in range(len(expected_lines)):
69
 
                self.assertEqualDiff(expected_lines[i], result[i])
 
70
            self.assertEqualDiff('\n'.join(expected_lines), '\n'.join(result))
70
71
        else:
71
72
            self.assertEqual([], result)
72
73
 
123
124
            renamed=False, modified='created', exe_change=False,
124
125
            kind=(None, 'file'), unversioned_filter=lambda x:True)
125
126
 
 
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
 
126
133
    def test_view_filtering(self):
127
134
        # If a file in within the view, it should appear in the output
128
135
        expected_lines = [
280
287
                                  ('branch/f2', '2\n'),
281
288
                                  ('branch/f3', '3\n'),
282
289
                                  ('branch/f4', '4\n'),
 
290
                                  ('branch/f5', '5\n'),
283
291
                                  ('branch/dir/',),
284
292
                                 ])
285
293
        wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
286
294
               ['f1-id', 'f2-id', 'f3-id', 'f4-id', 'dir-id'])
287
295
        wt.commit('commit one', rev_id='1')
288
296
 
 
297
        # TODO add rename,removed,etc. here?
 
298
        wt.add('f5')
 
299
        os.unlink('branch/f5')
 
300
 
289
301
        long_status = """added:
290
302
  dir/
291
303
  f1
292
304
  f2
293
305
  f3
294
306
  f4
 
307
missing:
 
308
  f5
295
309
"""
296
310
        short_status = """A  dir/
297
311
A  f1
298
312
A  f2
299
313
A  f3
300
314
A  f4
 
315
!  f5
301
316
"""
302
317
 
303
318
        repo = wt.branch.repository
304
319
        d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
305
320
        return d, long_status, short_status
306
321
 
307
 
    def test_delta_show_short_status_no_filter(self):
 
322
    def test_short_status(self):
308
323
        d, long_status, short_status = self._get_delta()
309
324
        out = StringIO()
310
325
        _mod_delta.report_delta(out, d, short_status=True)
311
 
        self.assertEquals(short_status, out.getvalue())
 
326
        self.assertEqual(short_status, out.getvalue())
312
327
 
313
 
    def test_delta_show_long_status_no_filter(self):
 
328
    def test_long_status(self):
314
329
        d, long_status, short_status = self._get_delta()
315
330
        out = StringIO()
316
331
        _mod_delta.report_delta(out, d, short_status=False)
317
 
        self.assertEquals(long_status, out.getvalue())
 
332
        self.assertEqual(long_status, out.getvalue())
318
333
 
319
 
    def test_delta_show_no_filter(self):
 
334
    def test_predicate_always(self):
320
335
        d, long_status, short_status = self._get_delta()
321
336
        out = StringIO()
322
 
        def not_a_filter(path, file_id):
 
337
        def always(path, file_id):
323
338
            return True
324
 
        _mod_delta.report_delta(out, d, short_status=True, filter=not_a_filter)
325
 
        self.assertEquals(short_status, out.getvalue())
326
 
 
327
 
    def test_delta_show_short_status_single_file_filter(self):
328
 
        d, long_status, short_status = self._get_delta()
329
 
        out = StringIO()
330
 
        def only_f2(path, file_id):
331
 
            return path == 'f2'
332
 
        _mod_delta.report_delta(out, d, short_status=True, filter=only_f2)
333
 
        self.assertEquals("A  f2\n", out.getvalue())
334
 
 
335
 
    def test_delta_show_long_status_single_file_filter(self):
336
 
        d, long_status, short_status = self._get_delta()
337
 
        out = StringIO()
338
 
        def only_f2(path, file_id):
339
 
            return path == 'f2'
340
 
        _mod_delta.report_delta(out, d, short_status=False, filter=only_f2)
341
 
        self.assertEquals("added:\n  f2\n", out.getvalue())
342
 
 
343
 
    def test_delta_show_short_status_single_file_id_filter(self):
 
339
        _mod_delta.report_delta(out, d, short_status=True, predicate=always)
 
340
        self.assertEqual(short_status, out.getvalue())
 
341
 
 
342
    def test_short_status_path_predicate(self):
 
343
        d, long_status, short_status = self._get_delta()
 
344
        out = StringIO()
 
345
        def only_f2(path, file_id):
 
346
            return path == 'f2'
 
347
        _mod_delta.report_delta(out, d, short_status=True, predicate=only_f2)
 
348
        self.assertEqual("A  f2\n", out.getvalue())
 
349
 
 
350
    def test_long_status_path_predicate(self):
 
351
        d, long_status, short_status = self._get_delta()
 
352
        out = StringIO()
 
353
        def only_f2(path, file_id):
 
354
            return path == 'f2'
 
355
        _mod_delta.report_delta(out, d, short_status=False, predicate=only_f2)
 
356
        self.assertEqual("added:\n  f2\n", out.getvalue())
 
357
 
 
358
    def test_long_status_id_predicate(self):
344
359
        d, long_status, short_status = self._get_delta()
345
360
        out = StringIO()
346
361
        def only_f2_id(path, file_id):
347
362
            return file_id == 'f2-id'
348
 
        _mod_delta.report_delta(out, d, short_status=True, filter=only_f2_id)
349
 
        self.assertEquals("A  f2\n", out.getvalue())
 
363
        _mod_delta.report_delta(out, d, predicate=only_f2_id)
 
364
        self.assertEqual("added:\n  f2\n", out.getvalue())
350
365