~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_delta.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-08-06 02:31:39 UTC
  • mfrom: (2665.1.2 stricter-run_bzr)
  • Revision ID: pqm@pqm.ubuntu.com-20070806023139-97nrt9mu4qihcdf3
(robertc) Merge Michael Hudson's run_bzr keyword usage fix. (Michael Hudson)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib import (
21
21
    delta as _mod_delta,
22
 
    inventory,
23
22
    tests,
24
23
    )
25
24
 
40
39
    def assertReport(self, expected, file_id='fid', path='path',
41
40
                     versioned_change='unchanged', renamed=False,
42
41
                     modified='unchanged', exe_change=False,
43
 
                     kind=('file', 'file'), old_path=None):
 
42
                     kind=('file', 'file'), old_path=None,
 
43
                     unversioned_filter=None):
44
44
        result = []
45
45
        def result_line(format, *args):
46
46
            result.append(format % args)
47
 
        inv = inventory.Inventory()
48
 
        if old_path is not None:
49
 
            inv.add(inventory.InventoryFile(file_id, old_path,
50
 
                                            inv.root.file_id))
51
 
        reporter = _mod_delta.ChangeReporter(inv, result_line)
52
 
        reporter.report(file_id, path, versioned_change, renamed, modified,
53
 
                         exe_change, kind)
54
 
        self.assertEqualDiff(expected, result[0])
 
47
        reporter = _mod_delta._ChangeReporter(result_line,
 
48
            unversioned_filter=unversioned_filter)
 
49
        reporter.report(file_id, (old_path, path), versioned_change, renamed,
 
50
            modified, exe_change, kind)
 
51
        if expected is not None:
 
52
            self.assertEqualDiff(expected, result[0])
 
53
        else:
 
54
            self.assertEqual([], result)
55
55
 
56
56
    def test_rename(self):
57
57
        self.assertReport('R   old => path', renamed=True, old_path='old')
61
61
 
62
62
    def test_kind(self):
63
63
        self.assertReport(' K  path => path/', modified='kind changed',
64
 
                          kind=('file', 'directory'))
 
64
                          kind=('file', 'directory'), old_path='path')
65
65
        self.assertReport(' K  path/ => path', modified='kind changed',
66
66
                          kind=('directory', 'file'), old_path='old')
67
67
        self.assertReport('RK  old => path/', renamed=True,
78
78
                          modified='created', kind=(None, 'directory'))
79
79
        self.assertReport('+M  path/', versioned_change='added',
80
80
                          modified='modified', kind=(None, 'directory'))
81
 
        self.assertReport('+K  path => path/', versioned_change='added',
82
 
                          modified='kind changed', kind=('file', 'directory'))
83
81
 
84
82
    def test_removal(self):
85
83
        self.assertReport(' D  path/', modified='deleted',
86
84
                          kind=('directory', None), old_path='old')
87
85
        self.assertReport('-   path/', versioned_change='removed',
 
86
                          old_path='path',
88
87
                          kind=(None, 'directory'))
89
88
        self.assertReport('-D  path', versioned_change='removed',
 
89
                          old_path='path',
90
90
                          modified='deleted', kind=('file', 'directory'))
91
91
 
92
92
    def test_modification(self):
93
93
        self.assertReport(' M  path', modified='modified')
94
94
        self.assertReport(' M* path', modified='modified', exe_change=True)
95
95
 
 
96
    def test_unversioned(self):
 
97
        # by default any unversioned file is output
 
98
        self.assertReport('?   subdir/foo~', file_id=None, path='subdir/foo~',
 
99
            old_path=None, versioned_change='unversioned',
 
100
            renamed=False, modified='created', exe_change=False,
 
101
            kind=(None, 'file'))
 
102
        # but we can choose to filter these. Probably that should be done 
 
103
        # close to the tree, but this is a reasonable starting point.
 
104
        self.assertReport(None, file_id=None, path='subdir/foo~',
 
105
            old_path=None, versioned_change='unversioned',
 
106
            renamed=False, modified='created', exe_change=False,
 
107
            kind=(None, 'file'), unversioned_filter=lambda x:True)
 
108
 
96
109
    def assertChangesEqual(self,
97
110
                           file_id='fid',
98
 
                           path='path',
 
111
                           paths=('path', 'path'),
99
112
                           content_change=False,
100
113
                           versioned=(True, True),
101
114
                           parent_id=('pid', 'pid'),
107
120
                           modified='unchanged',
108
121
                           exe_change=False):
109
122
        reporter = InstrumentedReporter()
110
 
        _mod_delta.report_changes([(file_id, path, content_change, versioned,
 
123
        _mod_delta.report_changes([(file_id, paths, content_change, versioned,
111
124
            parent_id, name, kind, executable)], reporter)
112
125
        output = reporter.calls[0]
113
126
        self.assertEqual(file_id, output[0])
114
 
        self.assertEqual(path, output[1])
 
127
        self.assertEqual(paths, output[1])
115
128
        self.assertEqual(versioned_change, output[2])
116
129
        self.assertEqual(renamed, output[3])
117
130
        self.assertEqual(modified, output[4])
159
172
                                content_change=True, name=('old', 'new'),
160
173
                                executable=(False, True))
161
174
 
 
175
    def test_report_unversioned(self):
 
176
        """Unversioned entries are reported well."""
 
177
        self.assertChangesEqual(file_id=None, paths=(None, 'full/path'),
 
178
                           content_change=True,
 
179
                           versioned=(False, False),
 
180
                           parent_id=(None, None),
 
181
                           name=(None, 'path'),
 
182
                           kind=(None, 'file'),
 
183
                           executable=(None, False),
 
184
                           versioned_change='unversioned',
 
185
                           renamed=False,
 
186
                           modified='created',
 
187
                           exe_change=False)
 
188
 
162
189
 
163
190
class TestChangesFrom (tests.TestCaseWithTransport):
164
191
 
197
224
        self.assertEqual(other_delta, delta)
198
225
        self.assertEqualDiff("TreeDelta(added=[], removed=[], renamed=[],"
199
226
            " kind_changed=[(u'filename', 'file-id', 'file', 'directory')],"
200
 
            " modified=[], unchanged=[])", repr(delta))
 
227
            " modified=[], unchanged=[], unversioned=[])", repr(delta))
201
228
        self.assertEqual('K  filename (file => directory) file-id\n',
202
229
                         self.show_string(delta, show_ids=True,
203
230
                         short_status=True))