~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Aaron Bentley
  • Date: 2007-06-11 14:59:52 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070611145952-cwt4480gphdhen6l
Get installation started

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
 
from cStringIO import StringIO
 
18
from StringIO import StringIO
19
19
 
20
20
from bzrlib import (
21
21
    delta as _mod_delta,
22
 
    revision as _mod_revision,
23
22
    tests,
24
23
    )
25
24
 
41
40
                     versioned_change='unchanged', renamed=False,
42
41
                     modified='unchanged', exe_change=False,
43
42
                     kind=('file', 'file'), old_path=None,
44
 
                     unversioned_filter=None, view_info=None):
45
 
        if expected is None:
46
 
            expected_lines = None
47
 
        else:
48
 
            expected_lines = [expected]
49
 
        self.assertReportLines(expected_lines, file_id, path,
50
 
                     versioned_change, renamed,
51
 
                     modified, exe_change,
52
 
                     kind, old_path,
53
 
                     unversioned_filter, view_info)
54
 
 
55
 
    def assertReportLines(self, expected_lines, file_id='fid', path='path',
56
 
                     versioned_change='unchanged', renamed=False,
57
 
                     modified='unchanged', exe_change=False,
58
 
                     kind=('file', 'file'), old_path=None,
59
 
                     unversioned_filter=None, view_info=None):
 
43
                     unversioned_filter=None):
60
44
        result = []
61
45
        def result_line(format, *args):
62
46
            result.append(format % args)
63
47
        reporter = _mod_delta._ChangeReporter(result_line,
64
 
            unversioned_filter=unversioned_filter, view_info=view_info)
 
48
            unversioned_filter=unversioned_filter)
65
49
        reporter.report(file_id, (old_path, path), versioned_change, renamed,
66
50
            modified, exe_change, kind)
67
 
        if expected_lines is not None:
68
 
            self.assertEqualDiff('\n'.join(expected_lines), '\n'.join(result))
 
51
        if expected is not None:
 
52
            self.assertEqualDiff(expected, result[0])
69
53
        else:
70
54
            self.assertEqual([], result)
71
55
 
115
99
            old_path=None, versioned_change='unversioned',
116
100
            renamed=False, modified='created', exe_change=False,
117
101
            kind=(None, 'file'))
118
 
        # but we can choose to filter these. Probably that should be done
 
102
        # but we can choose to filter these. Probably that should be done 
119
103
        # close to the tree, but this is a reasonable starting point.
120
104
        self.assertReport(None, file_id=None, path='subdir/foo~',
121
105
            old_path=None, versioned_change='unversioned',
122
106
            renamed=False, modified='created', exe_change=False,
123
107
            kind=(None, 'file'), unversioned_filter=lambda x:True)
124
108
 
125
 
    def test_missing(self):
126
 
        self.assertReport('+!  missing.c', file_id=None, path='missing.c',
127
 
             old_path=None, versioned_change='added',
128
 
             renamed=False, modified='missing', exe_change=False,
129
 
             kind=(None, None))
130
 
 
131
 
    def test_view_filtering(self):
132
 
        # If a file in within the view, it should appear in the output
133
 
        expected_lines = [
134
 
            "Operating on whole tree but only reporting on 'my' view.",
135
 
            " M  path"]
136
 
        self.assertReportLines(expected_lines, modified='modified',
137
 
            view_info=('my',['path']))
138
 
        # If a file in outside the view, it should not appear in the output
139
 
        expected_lines = [
140
 
            "Operating on whole tree but only reporting on 'my' view."]
141
 
        self.assertReportLines(expected_lines, modified='modified',
142
 
            path="foo", view_info=('my',['path']))
143
 
 
144
109
    def assertChangesEqual(self,
145
110
                           file_id='fid',
146
111
                           paths=('path', 'path'),
222
187
                           exe_change=False)
223
188
 
224
189
 
225
 
class TestChangesFrom(tests.TestCaseWithTransport):
 
190
class TestChangesFrom (tests.TestCaseWithTransport):
226
191
 
227
192
    def show_string(self, delta, *args,  **kwargs):
228
193
        to_file = StringIO()
229
 
        _mod_delta.report_delta(to_file, delta, *args, **kwargs)
 
194
        delta.show(to_file, *args, **kwargs)
230
195
        return to_file.getvalue()
231
196
 
232
197
    def test_kind_change(self):
273
238
                           True, False)], delta.renamed)
274
239
        self.assertTrue(delta.has_changed())
275
240
        self.assertTrue(delta.touches_file_id('file-id'))
276
 
 
277
 
 
278
 
class TestDeltaShow(tests.TestCaseWithTransport):
279
 
 
280
 
    def _get_delta(self):
281
 
        # We build the delta from a real tree to avoid depending on internal
282
 
        # implementation details.
283
 
        wt = self.make_branch_and_tree('branch')
284
 
        self.build_tree_contents([('branch/f1', '1\n'),
285
 
                                  ('branch/f2', '2\n'),
286
 
                                  ('branch/f3', '3\n'),
287
 
                                  ('branch/f4', '4\n'),
288
 
                                  ('branch/f5', '5\n'),
289
 
                                  ('branch/dir/',),
290
 
                                 ])
291
 
        wt.add(['f1', 'f2', 'f3', 'f4', 'dir'],
292
 
               ['f1-id', 'f2-id', 'f3-id', 'f4-id', 'dir-id'])
293
 
        wt.commit('commit one', rev_id='1')
294
 
 
295
 
        # TODO add rename,removed,etc. here?
296
 
        wt.add('f5')
297
 
        os.unlink('branch/f5')
298
 
 
299
 
        long_status = """added:
300
 
  dir/
301
 
  f1
302
 
  f2
303
 
  f3
304
 
  f4
305
 
missing:
306
 
  f5
307
 
"""
308
 
        short_status = """A  dir/
309
 
A  f1
310
 
A  f2
311
 
A  f3
312
 
A  f4
313
 
!  f5
314
 
"""
315
 
 
316
 
        repo = wt.branch.repository
317
 
        d = wt.changes_from(repo.revision_tree(_mod_revision.NULL_REVISION))
318
 
        return d, long_status, short_status
319
 
 
320
 
    def test_delta_show_short_status_no_filter(self):
321
 
        d, long_status, short_status = self._get_delta()
322
 
        out = StringIO()
323
 
        _mod_delta.report_delta(out, d, short_status=True)
324
 
        self.assertEquals(short_status, out.getvalue())
325
 
 
326
 
    def test_delta_show_long_status_no_filter(self):
327
 
        d, long_status, short_status = self._get_delta()
328
 
        out = StringIO()
329
 
        _mod_delta.report_delta(out, d, short_status=False)
330
 
        self.assertEquals(long_status, out.getvalue())
331
 
 
332
 
    def test_delta_show_no_filter(self):
333
 
        d, long_status, short_status = self._get_delta()
334
 
        out = StringIO()
335
 
        def not_a_filter(path, file_id):
336
 
            return True
337
 
        _mod_delta.report_delta(out, d, short_status=True, filter=not_a_filter)
338
 
        self.assertEquals(short_status, out.getvalue())
339
 
 
340
 
    def test_delta_show_short_status_single_file_filter(self):
341
 
        d, long_status, short_status = self._get_delta()
342
 
        out = StringIO()
343
 
        def only_f2(path, file_id):
344
 
            return path == 'f2'
345
 
        _mod_delta.report_delta(out, d, short_status=True, filter=only_f2)
346
 
        self.assertEquals("A  f2\n", out.getvalue())
347
 
 
348
 
    def test_delta_show_long_status_single_file_filter(self):
349
 
        d, long_status, short_status = self._get_delta()
350
 
        out = StringIO()
351
 
        def only_f2(path, file_id):
352
 
            return path == 'f2'
353
 
        _mod_delta.report_delta(out, d, short_status=False, filter=only_f2)
354
 
        self.assertEquals("added:\n  f2\n", out.getvalue())
355
 
 
356
 
    def test_delta_show_short_status_single_file_id_filter(self):
357
 
        d, long_status, short_status = self._get_delta()
358
 
        out = StringIO()
359
 
        def only_f2_id(path, file_id):
360
 
            return file_id == 'f2-id'
361
 
        _mod_delta.report_delta(out, d, short_status=True, filter=only_f2_id)
362
 
        self.assertEquals("A  f2\n", out.getvalue())
363