~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Frank Aspell
  • Date: 2009-02-17 11:40:05 UTC
  • mto: (4054.1.1 doc)
  • mto: This revision was merged to the branch mainline in revision 4056.
  • Revision ID: frankaspell@googlemail.com-20090217114005-ojufrp6rqht664um
Fixed typos.

Fixed some typos in bzr doc's using "aspell -l en -c FILENAME".

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
18
from cStringIO import StringIO
41
41
                     versioned_change='unchanged', renamed=False,
42
42
                     modified='unchanged', exe_change=False,
43
43
                     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):
 
44
                     unversioned_filter=None):
60
45
        result = []
61
46
        def result_line(format, *args):
62
47
            result.append(format % args)
63
48
        reporter = _mod_delta._ChangeReporter(result_line,
64
 
            unversioned_filter=unversioned_filter, view_info=view_info)
 
49
            unversioned_filter=unversioned_filter)
65
50
        reporter.report(file_id, (old_path, path), versioned_change, renamed,
66
51
            modified, exe_change, kind)
67
 
        if expected_lines is not None:
68
 
            for i in range(len(expected_lines)):
69
 
                self.assertEqualDiff(expected_lines[i], result[i])
 
52
        if expected is not None:
 
53
            self.assertEqualDiff(expected, result[0])
70
54
        else:
71
55
            self.assertEqual([], result)
72
56
 
116
100
            old_path=None, versioned_change='unversioned',
117
101
            renamed=False, modified='created', exe_change=False,
118
102
            kind=(None, 'file'))
119
 
        # but we can choose to filter these. Probably that should be done
 
103
        # but we can choose to filter these. Probably that should be done 
120
104
        # close to the tree, but this is a reasonable starting point.
121
105
        self.assertReport(None, file_id=None, path='subdir/foo~',
122
106
            old_path=None, versioned_change='unversioned',
123
107
            renamed=False, modified='created', exe_change=False,
124
108
            kind=(None, 'file'), unversioned_filter=lambda x:True)
125
109
 
126
 
    def test_view_filtering(self):
127
 
        # If a file in within the view, it should appear in the output
128
 
        expected_lines = [
129
 
            "Operating on whole tree but only reporting on 'my' view.",
130
 
            " M  path"]
131
 
        self.assertReportLines(expected_lines, modified='modified',
132
 
            view_info=('my',['path']))
133
 
        # If a file in outside the view, it should not appear in the output
134
 
        expected_lines = [
135
 
            "Operating on whole tree but only reporting on 'my' view."]
136
 
        self.assertReportLines(expected_lines, modified='modified',
137
 
            path="foo", view_info=('my',['path']))
138
 
 
139
110
    def assertChangesEqual(self,
140
111
                           file_id='fid',
141
112
                           paths=('path', 'path'),
221
192
 
222
193
    def show_string(self, delta, *args,  **kwargs):
223
194
        to_file = StringIO()
224
 
        _mod_delta.report_delta(to_file, delta, *args, **kwargs)
 
195
        delta.show(to_file, *args, **kwargs)
225
196
        return to_file.getvalue()
226
197
 
227
198
    def test_kind_change(self):
307
278
    def test_delta_show_short_status_no_filter(self):
308
279
        d, long_status, short_status = self._get_delta()
309
280
        out = StringIO()
310
 
        _mod_delta.report_delta(out, d, short_status=True)
 
281
        d.show(out, short_status=True)
311
282
        self.assertEquals(short_status, out.getvalue())
312
283
 
313
284
    def test_delta_show_long_status_no_filter(self):
314
285
        d, long_status, short_status = self._get_delta()
315
286
        out = StringIO()
316
 
        _mod_delta.report_delta(out, d, short_status=False)
 
287
        d.show(out, short_status=False)
317
288
        self.assertEquals(long_status, out.getvalue())
318
289
 
319
290
    def test_delta_show_no_filter(self):
321
292
        out = StringIO()
322
293
        def not_a_filter(path, file_id):
323
294
            return True
324
 
        _mod_delta.report_delta(out, d, short_status=True, filter=not_a_filter)
 
295
        d.show(out, short_status=True, filter=not_a_filter)
325
296
        self.assertEquals(short_status, out.getvalue())
326
297
 
327
298
    def test_delta_show_short_status_single_file_filter(self):
329
300
        out = StringIO()
330
301
        def only_f2(path, file_id):
331
302
            return path == 'f2'
332
 
        _mod_delta.report_delta(out, d, short_status=True, filter=only_f2)
 
303
        d.show(out, short_status=True, filter=only_f2)
333
304
        self.assertEquals("A  f2\n", out.getvalue())
334
305
 
335
306
    def test_delta_show_long_status_single_file_filter(self):
337
308
        out = StringIO()
338
309
        def only_f2(path, file_id):
339
310
            return path == 'f2'
340
 
        _mod_delta.report_delta(out, d, short_status=False, filter=only_f2)
 
311
        d.show(out, short_status=False, filter=only_f2)
341
312
        self.assertEquals("added:\n  f2\n", out.getvalue())
342
313
 
343
314
    def test_delta_show_short_status_single_file_id_filter(self):
345
316
        out = StringIO()
346
317
        def only_f2_id(path, file_id):
347
318
            return file_id == 'f2-id'
348
 
        _mod_delta.report_delta(out, d, short_status=True, filter=only_f2_id)
 
319
        d.show(out, short_status=True, filter=only_f2_id)
349
320
        self.assertEquals("A  f2\n", out.getvalue())
350
321