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):
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,
51
reporter = _mod_delta.ChangeReporter(inv, result_line)
52
reporter.report(file_id, path, versioned_change, renamed, modified,
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])
54
self.assertEqual([], result)
56
56
def test_rename(self):
57
57
self.assertReport('R old => path', renamed=True, old_path='old')
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'))
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',
88
87
kind=(None, 'directory'))
89
88
self.assertReport('-D path', versioned_change='removed',
90
90
modified='deleted', kind=('file', 'directory'))
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)
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,
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)
96
109
def assertChangesEqual(self,
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))
175
def test_report_unversioned(self):
176
"""Unversioned entries are reported well."""
177
self.assertChangesEqual(file_id=None, paths=(None, 'full/path'),
179
versioned=(False, False),
180
parent_id=(None, None),
183
executable=(None, False),
184
versioned_change='unversioned',
163
190
class TestChangesFrom (tests.TestCaseWithTransport):
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))