34
class TestRename(tests.TestCaseWithTransport):
34
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
36
36
def get_handler(self):
37
37
branch = self.make_branch('.')
38
38
handler = generic_processor.GenericProcessor(branch.bzrdir)
39
return (handler, branch)
41
def get_command_iter(self, old_path, new_path):
43
author = ['', 'bugs@a.com', time.time(), time.timezone]
44
committer = ['', 'elmer@a.com', time.time(), time.timezone]
46
yield commands.FileModifyCommand(old_path, 'file', False,
48
yield commands.CommitCommand('head', '1', author,
49
committer, "commit 1", None, [], files_one)
51
yield commands.FileRenameCommand(old_path, new_path)
52
yield commands.CommitCommand('head', '2', author,
53
committer, "commit 2", ":1", [], files_two)
39
return handler, branch
56
41
# FIXME: [] as a default is bad, as it is mutable, but I want
57
42
# to use None to mean "don't check this".
43
def assertChanges(self, branch, revno, expected_added=[],
44
expected_removed=[], expected_modified=[],
46
"""Check the changes introduced in a revision of a branch.
48
This method checks that a revision introduces expected changes.
49
The required changes are passed in as a list, where
50
each entry contains the needed information about the change.
52
If you do not wish to assert anything about a particular
53
category then pass None instead.
56
revno: revision number of revision to check.
57
expected_added: a list of (filename,) tuples that must have
58
been added in the delta.
59
expected_removed: a list of (filename,) tuples that must have
60
been removed in the delta.
61
expected_modified: a list of (filename,) tuples that must have
62
been modified in the delta.
63
expected_renamed: a list of (old_path, new_path) tuples that
64
must have been renamed in the delta.
65
:return: revtree1, revtree2
67
repo = branch.repository
68
revtree1 = repo.revision_tree(branch.revision_history()[revno - 1])
69
revtree2 = repo.revision_tree(branch.revision_history()[revno])
70
changes = revtree2.changes_from(revtree1)
71
self.check_changes(changes, expected_added, expected_removed,
72
expected_modified, expected_renamed)
73
return revtree1, revtree2
58
75
def check_changes(self, changes, expected_added=[],
59
76
expected_removed=[], expected_modified=[],
60
77
expected_renamed=[]):
115
132
"%s is not modified, %s are" % (str(expected_modified_entry),
136
class TestRename(TestCaseForGenericProcessor):
138
def get_command_iter(self, old_path, new_path):
140
author = ['', 'bugs@a.com', time.time(), time.timezone]
141
committer = ['', 'elmer@a.com', time.time(), time.timezone]
143
yield commands.FileModifyCommand(old_path, 'file', False,
145
yield commands.CommitCommand('head', '1', author,
146
committer, "commit 1", None, [], files_one)
148
yield commands.FileRenameCommand(old_path, new_path)
149
yield commands.CommitCommand('head', '2', author,
150
committer, "commit 2", ":1", [], files_two)
118
153
def test_rename_in_root(self):
119
(handler, branch) = self.get_handler()
154
handler, branch = self.get_handler()
122
command_list = self.get_command_iter(old_path, new_path)
123
handler.process(command_list)
124
repo = branch.repository
125
revtree1 = repo.revision_tree(branch.revision_history()[0])
126
revtree2 = repo.revision_tree(branch.revision_history()[1])
127
changes = revtree2.changes_from(revtree1)
157
handler.process(self.get_command_iter(old_path, new_path))
158
revtree1, revtree2 = self.assertChanges(branch, 1,
159
expected_renamed=[(old_path, new_path)])
128
160
self.assertEqual(revtree1.get_revision_id(),
129
161
revtree1.inventory.root.children['a'].revision)
130
162
self.assertEqual(revtree2.get_revision_id(),
131
163
revtree2.inventory.root.children['b'].revision)
132
self.check_changes(changes, expected_renamed=[(old_path, new_path)])
134
165
def test_rename_in_subdir(self):
135
(handler, branch) = self.get_handler()
166
handler, branch = self.get_handler()
138
command_list = self.get_command_iter(old_path, new_path)
139
handler.process(command_list)
140
repo = branch.repository
141
revtree1 = repo.revision_tree(branch.revision_history()[0])
142
revtree2 = repo.revision_tree(branch.revision_history()[1])
143
changes = revtree2.changes_from(revtree1)
144
self.check_changes(changes, expected_renamed=[(old_path, new_path)])
169
handler.process(self.get_command_iter(old_path, new_path))
170
self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)])
146
172
def test_move_to_new_dir(self):
147
(handler, branch) = self.get_handler()
173
handler, branch = self.get_handler()
150
command_list = self.get_command_iter(old_path, new_path)
151
handler.process(command_list)
152
repo = branch.repository
153
revtree1 = repo.revision_tree(branch.revision_history()[0])
154
revtree2 = repo.revision_tree(branch.revision_history()[1])
155
changes = revtree2.changes_from(revtree1)
156
self.check_changes(changes, expected_renamed=[(old_path, new_path)],
176
handler.process(self.get_command_iter(old_path, new_path))
177
self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)],
157
178
expected_added=[('b',)])
160
class TestFileKinds(tests.TestCaseWithTransport):
162
def get_handler(self):
163
branch = self.make_branch('.')
164
handler = generic_processor.GenericProcessor(branch.bzrdir)
165
return (handler, branch)
181
class TestFileKinds(TestCaseForGenericProcessor):
167
183
def get_command_iter(self, path, kind, content):
168
184
def command_list():
175
191
return command_list
177
193
def test_import_plainfile(self):
178
(handler, branch) = self.get_handler()
179
command_list = self.get_command_iter('foo', 'file', 'aaa')
194
handler, branch = self.get_handler()
195
handler.process(self.get_command_iter('foo', 'file', 'aaa'))
181
197
def test_import_symlink(self):
182
(handler, branch) = self.get_handler()
183
command_list = self.get_command_iter('foo', 'symlink', 'bar')
184
handler.process(command_list)
198
handler, branch = self.get_handler()
199
handler.process(self.get_command_iter('foo', 'symlink', 'bar'))