24
class InstrumentedReporter(object):
28
def report(self, file_id, path, versioned, renamed, modified, exe_change,
30
self.calls.append((file_id, path, versioned, renamed, modified,
24
33
class TestReportChanges(tests.TestCase):
26
def reportEqual(self, expected, file_id='fid', path='path',
35
def reportEqual(self, expected, file_id='fid', path='path',
27
36
versioned_change='unchanged', renamed=False,
28
modified='unchanged', exe_change=False,
37
modified='unchanged', exe_change=False,
29
38
kind=('file', 'file'), old_path=None):
31
40
def result_line(format, *args):
32
41
result.append(format % args)
33
42
inv = inventory.Inventory()
34
43
if old_path is not None:
35
inv.add(inventory.InventoryFile(file_id, old_path,
44
inv.add(inventory.InventoryFile(file_id, old_path,
37
46
reporter = delta.ChangeReporter(inv, result_line)
38
reporter.report(file_id, path, versioned_change, renamed, modified,
47
reporter.report(file_id, path, versioned_change, renamed, modified,
40
49
self.assertEqualDiff(expected, result[0])
52
61
modified='kind changed', kind=('file', 'directory'),
54
63
def test_new(self):
55
self.reportEqual(' N path/', modified='created',
64
self.reportEqual(' N path/', modified='created',
56
65
kind=(None, 'directory'))
57
self.reportEqual('+ path/', versioned_change='added',
66
self.reportEqual('+ path/', versioned_change='added',
58
67
modified='unchanged', kind=(None, 'directory'))
59
self.reportEqual('+N path/', versioned_change='added',
68
self.reportEqual('+N path/', versioned_change='added',
60
69
modified='created', kind=(None, 'directory'))
61
self.reportEqual('+M path/', versioned_change='added',
70
self.reportEqual('+M path/', versioned_change='added',
62
71
modified='modified', kind=(None, 'directory'))
63
self.reportEqual('+K path => path/', versioned_change='added',
72
self.reportEqual('+K path => path/', versioned_change='added',
64
73
modified='kind changed', kind=('file', 'directory'))
66
75
def test_removal(self):
67
76
self.reportEqual(' D path/', modified='deleted',
68
77
kind=('directory', None), old_path='old')
69
self.reportEqual('- path/', versioned_change='removed',
78
self.reportEqual('- path/', versioned_change='removed',
70
79
kind=(None, 'directory'))
71
self.reportEqual('-D path', versioned_change='removed',
80
self.reportEqual('-D path', versioned_change='removed',
72
81
modified='deleted', kind=('file', 'directory'))
74
83
def test_modification(self):
75
84
self.reportEqual(' M path', modified='modified')
76
85
self.reportEqual(' M* path', modified='modified', exe_change=True)
87
def report_changes_equal(self,
91
versioned=(True, True),
92
parent_id=('pid', 'pid'),
93
name=('name', 'name'),
94
kind=('file', 'file'),
95
executable=(False, False),
96
versioned_change='unchanged',
100
reporter = InstrumentedReporter()
101
delta.report_changes([(file_id, path, content_change, versioned,
102
parent_id, name, kind, executable)], reporter)
103
output = reporter.calls[0]
104
self.assertEqual(file_id, output[0])
105
self.assertEqual(path, output[1])
106
self.assertEqual(versioned_change, output[2])
107
self.assertEqual(renamed, output[3])
108
self.assertEqual(modified, output[4])
109
self.assertEqual(exe_change, output[5])
110
self.assertEqual(kind, output[6])
112
def test_report_changes(self):
113
"""Test change detection of report_changes"""
114
#Ensure no changes are detected by default
115
self.report_changes_equal(modified='unchanged', renamed=False,
116
versioned_change='unchanged',
118
self.report_changes_equal(modified='kind changed',
119
kind=('file', 'directory'))
120
self.report_changes_equal(modified='created',
121
kind=(None, 'directory'))
122
self.report_changes_equal(modified='deleted',
123
kind=('directory', None))
124
self.report_changes_equal(content_change=True, modified='modified')
125
self.report_changes_equal(renamed=True, name=('old', 'new'))
126
self.report_changes_equal(renamed=True,
127
parent_id=('old-parent', 'new-parent'))
128
self.report_changes_equal(versioned_change='added',
129
versioned=(False, True))
130
self.report_changes_equal(versioned_change='removed',
131
versioned=(True, False))
132
# execute bit is only detected as "changed" if the file is and was
134
self.report_changes_equal(exe_change=True,
135
executable=(True, False))
136
self.report_changes_equal(exe_change=False,
137
executable=(True, False),
138
kind=('directory', 'directory'))
139
self.report_changes_equal(exe_change=False, modified='kind changed',
140
executable=(False, True),
141
kind=('directory', 'file'))
143
# Now make sure they all work together
144
self.report_changes_equal(versioned_change='removed',
146
versioned=(True, False),
147
kind=('directory', None))
148
self.report_changes_equal(versioned_change='removed',
150
versioned=(True, False),
152
self.report_changes_equal(versioned_change='removed',
156
versioned=(True, False),
159
executable=(False, True)