42
42
# to use None to mean "don't check this".
43
43
def assertChanges(self, branch, revno, expected_added=[],
44
44
expected_removed=[], expected_modified=[],
45
expected_renamed=[], expected_kind_changed=[]):
46
46
"""Check the changes introduced in a revision of a branch.
48
48
This method checks that a revision introduces expected changes.
62
62
been modified in the delta.
63
63
expected_renamed: a list of (old_path, new_path) tuples that
64
64
must have been renamed in the delta.
65
expected_kind_changed: a list of (path, old_kind, new_kind) tuples
66
that must have been changed in the delta.
65
67
:return: revtree1, revtree2
67
69
repo = branch.repository
68
70
revtree1 = repo.revision_tree(branch.get_rev_id(revno - 1))
69
71
revtree2 = repo.revision_tree(branch.get_rev_id(revno))
70
72
changes = revtree2.changes_from(revtree1)
71
self.check_changes(changes, expected_added, expected_removed,
72
expected_modified, expected_renamed)
73
self._check_changes(changes, expected_added, expected_removed,
74
expected_modified, expected_renamed, expected_kind_changed)
73
75
return revtree1, revtree2
75
def check_changes(self, changes, expected_added=[],
77
def _check_changes(self, changes, expected_added=[],
76
78
expected_removed=[], expected_modified=[],
79
expected_renamed=[], expected_kind_changed=[]):
78
80
"""Check the changes in a TreeDelta
80
82
This method checks that the TreeDelta contains the expected
94
96
been modified in the delta.
95
97
expected_renamed: a list of (old_path, new_path) tuples that
96
98
must have been renamed in the delta.
99
expected_kind_changed: a list of (path, old_kind, new_kind) tuples
100
that must have been changed in the delta.
98
102
renamed = changes.renamed
99
103
added = changes.added
100
104
removed = changes.removed
101
105
modified = changes.modified
106
kind_changed = changes.kind_changed
102
107
if expected_renamed is not None:
103
108
self.assertEquals(len(renamed), len(expected_renamed),
104
109
"%s is renamed, expected %s" % (renamed, expected_renamed))
129
134
modified_files = [(item[0],) for item in modified]
130
135
for expected_modified_entry in expected_modified:
131
136
self.assertTrue(expected_modified_entry in modified_files,
132
"%s is not modified, %s are" % (str(expected_modified_entry),
137
"%s is not modified, %s are" % (
138
str(expected_modified_entry), modified_files))
139
if expected_kind_changed is not None:
140
self.assertEquals(len(kind_changed), len(expected_kind_changed),
141
"%s is kind-changed, expected %s" % (kind_changed,
142
expected_kind_changed))
143
kind_changed_files = [(item[0], item[2], item[3])
144
for item in kind_changed]
145
for expected_kind_changed_entry in expected_kind_changed:
146
self.assertTrue(expected_kind_changed_entry in
147
kind_changed_files, "%s is not kind-changed, %s are" % (
148
str(expected_kind_changed_entry), kind_changed_files))
135
150
def assertContent(self, branch, tree, path, content):
136
151
file_id = tree.inventory.path2id(path)
152
167
class TestModify(TestCaseForGenericProcessor):
154
def file_command_iter(self, path, kind='file'):
169
def file_command_iter(self, path, kind='file', content='aaa',
170
to_kind=None, to_content='bbb'):
155
173
def command_list():
156
174
author = ['', 'bugs@a.com', time.time(), time.timezone]
157
175
committer = ['', 'elmer@a.com', time.time(), time.timezone]
159
177
yield commands.FileModifyCommand(path, kind, False,
161
179
yield commands.CommitCommand('head', '1', author,
162
180
committer, "commit 1", None, [], files_one)
164
yield commands.FileModifyCommand(path, kind, False,
182
yield commands.FileModifyCommand(path, to_kind, False,
166
184
yield commands.CommitCommand('head', '2', author,
167
185
committer, "commit 2", ":1", [], files_two)
168
186
return command_list
213
231
self.assertSymlinkTarget(branch, revtree1, path, "aaa")
214
232
self.assertSymlinkTarget(branch, revtree2, path, "bbb")
234
def test_modify_file_becomes_symlink(self):
235
handler, branch = self.get_handler()
237
handler.process(self.file_command_iter(path,
238
kind='file', to_kind='symlink'))
239
revtree0, revtree1 = self.assertChanges(branch, 1,
240
expected_added=[('a',), (path,)])
241
revtree1, revtree2 = self.assertChanges(branch, 2,
242
expected_kind_changed=[(path, 'file', 'symlink')])
243
self.assertContent(branch, revtree1, path, "aaa")
244
self.assertSymlinkTarget(branch, revtree2, path, "bbb")
246
def test_modify_symlink_becomes_file(self):
247
handler, branch = self.get_handler()
249
handler.process(self.file_command_iter(path,
250
kind='symlink', to_kind='file'))
251
revtree0, revtree1 = self.assertChanges(branch, 1,
252
expected_added=[('a',), (path,)])
253
revtree1, revtree2 = self.assertChanges(branch, 2,
254
expected_kind_changed=[(path, 'symlink', 'file')])
255
self.assertSymlinkTarget(branch, revtree1, path, "aaa")
256
self.assertContent(branch, revtree2, path, "bbb")
217
259
class TestDelete(TestCaseForGenericProcessor):