/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_generic_processor.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-20 00:58:27 UTC
  • mto: (0.64.124 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090220005827-wujxlvzanfesqnji
basic units tests for filemodify

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        :return: revtree1, revtree2
66
66
        """
67
67
        repo = branch.repository
68
 
        revtree1 = repo.revision_tree(branch.revision_history()[revno - 1])
69
 
        revtree2 = repo.revision_tree(branch.revision_history()[revno])
 
68
        revtree1 = repo.revision_tree(branch.get_rev_id(revno - 1))
 
69
        revtree2 = repo.revision_tree(branch.get_rev_id(revno))
70
70
        changes = revtree2.changes_from(revtree1)
71
71
        self.check_changes(changes, expected_added, expected_removed,
72
72
            expected_modified, expected_renamed)
132
132
                    "%s is not modified, %s are" % (str(expected_modified_entry),
133
133
                        modified_files))
134
134
 
 
135
    def assertContent(self, branch, tree, path, content):
 
136
        file_id = tree.inventory.path2id(path)
 
137
        branch.lock_read()
 
138
        self.addCleanup(branch.unlock)
 
139
        self.assertEqual(tree.get_file_text(file_id), content)
 
140
 
 
141
    def assertSymlinkTarget(self, branch, tree, path, target):
 
142
        file_id = tree.inventory.path2id(path)
 
143
        branch.lock_read()
 
144
        self.addCleanup(branch.unlock)
 
145
        self.assertEqual(tree.get_symlink_target(file_id), target)
 
146
 
 
147
    def assertRevisionRoot(self, revtree, path):
 
148
        self.assertEqual(revtree.get_revision_id(),
 
149
                         revtree.inventory.root.children[path].revision)
 
150
 
 
151
 
 
152
class TestModify(TestCaseForGenericProcessor):
 
153
 
 
154
    def file_command_iter(self, path, kind='file'):
 
155
        def command_list():
 
156
            author = ['', 'bugs@a.com', time.time(), time.timezone]
 
157
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
 
158
            def files_one():
 
159
                yield commands.FileModifyCommand(path, kind, False,
 
160
                        None, "aaa")
 
161
            yield commands.CommitCommand('head', '1', author,
 
162
                committer, "commit 1", None, [], files_one)
 
163
            def files_two():
 
164
                yield commands.FileModifyCommand(path, kind, False,
 
165
                        None, "bbb")
 
166
            yield commands.CommitCommand('head', '2', author,
 
167
                committer, "commit 2", ":1", [], files_two)
 
168
        return command_list
 
169
 
 
170
    def test_modify_file_in_root(self):
 
171
        handler, branch = self.get_handler()
 
172
        path = 'a'
 
173
        handler.process(self.file_command_iter(path))
 
174
        revtree0, revtree1 = self.assertChanges(branch, 1,
 
175
            expected_added=[(path,)])
 
176
        revtree1, revtree2 = self.assertChanges(branch, 2,
 
177
            expected_modified=[(path,)])
 
178
        self.assertContent(branch, revtree1, path, "aaa")
 
179
        self.assertContent(branch, revtree2, path, "bbb")
 
180
        self.assertRevisionRoot(revtree1, path)
 
181
        self.assertRevisionRoot(revtree2, path)
 
182
 
 
183
    def test_modify_file_in_subdir(self):
 
184
        handler, branch = self.get_handler()
 
185
        path = 'a/a'
 
186
        handler.process(self.file_command_iter(path))
 
187
        revtree0, revtree1 = self.assertChanges(branch, 1,
 
188
            expected_added=[('a',), (path,)])
 
189
        revtree1, revtree2 = self.assertChanges(branch, 2,
 
190
            expected_modified=[(path,)])
 
191
        self.assertContent(branch, revtree1, path, "aaa")
 
192
        self.assertContent(branch, revtree2, path, "bbb")
 
193
 
 
194
    def test_modify_symlink_in_root(self):
 
195
        handler, branch = self.get_handler()
 
196
        path = 'a'
 
197
        handler.process(self.file_command_iter(path, kind='symlink'))
 
198
        revtree1, revtree2 = self.assertChanges(branch, 2,
 
199
            expected_modified=[(path,)])
 
200
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
 
201
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
 
202
        self.assertRevisionRoot(revtree1, path)
 
203
        self.assertRevisionRoot(revtree2, path)
 
204
 
 
205
    def test_modify_symlink_in_subdir(self):
 
206
        handler, branch = self.get_handler()
 
207
        path = 'a/a'
 
208
        handler.process(self.file_command_iter(path, kind='symlink'))
 
209
        revtree0, revtree1 = self.assertChanges(branch, 1,
 
210
            expected_added=[('a',), (path,)])
 
211
        revtree1, revtree2 = self.assertChanges(branch, 2,
 
212
            expected_modified=[(path,)])
 
213
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
 
214
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
 
215
 
135
216
 
136
217
class TestRename(TestCaseForGenericProcessor):
137
218
 
155
236
        old_path = 'a'
156
237
        new_path = 'b'
157
238
        handler.process(self.get_command_iter(old_path, new_path))
158
 
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
239
        revtree1, revtree2 = self.assertChanges(branch, 2,
159
240
            expected_renamed=[(old_path, new_path)])
160
 
        self.assertEqual(revtree1.get_revision_id(),
161
 
                         revtree1.inventory.root.children['a'].revision)
162
 
        self.assertEqual(revtree2.get_revision_id(),
163
 
                         revtree2.inventory.root.children['b'].revision)
 
241
        self.assertRevisionRoot(revtree1, old_path)
 
242
        self.assertRevisionRoot(revtree2, new_path)
164
243
 
165
244
    def test_rename_in_subdir(self):
166
245
        handler, branch = self.get_handler()
167
246
        old_path = 'a/a'
168
247
        new_path = 'a/b'
169
248
        handler.process(self.get_command_iter(old_path, new_path))
170
 
        self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)])
 
249
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
171
250
 
172
251
    def test_move_to_new_dir(self):
173
252
        handler, branch = self.get_handler()
174
253
        old_path = 'a/a'
175
254
        new_path = 'b/a'
176
255
        handler.process(self.get_command_iter(old_path, new_path))
177
 
        self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)],
 
256
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)],
178
257
            expected_added=[('b',)])
179
258
 
180
259
 
181
260
class TestCopy(TestCaseForGenericProcessor):
182
261
 
183
 
    def file_command_iter(self, src_path, dest_path):
 
262
    def file_command_iter(self, src_path, dest_path, kind='file'):
184
263
        def command_list():
185
264
            author = ['', 'bugs@a.com', time.time(), time.timezone]
186
265
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
187
266
            def files_one():
188
 
                yield commands.FileModifyCommand(src_path, 'file', False,
 
267
                yield commands.FileModifyCommand(src_path, kind, False,
189
268
                        None, "aaa")
190
269
            yield commands.CommitCommand('head', '1', author,
191
270
                committer, "commit 1", None, [], files_one)
195
274
                committer, "commit 2", ":1", [], files_two)
196
275
        return command_list
197
276
 
198
 
    def assertContent(self, branch, tree, path, content):
199
 
        file_id = tree.inventory.path2id(path)
200
 
        branch.lock_read()
201
 
        self.addCleanup(branch.unlock)
202
 
        self.assertEqual(tree.get_file_text(file_id), content)
203
 
 
204
277
    def test_copy_file_in_root(self):
205
278
        handler, branch = self.get_handler()
206
279
        src_path = 'a'
207
280
        dest_path = 'b'
208
281
        handler.process(self.file_command_iter(src_path, dest_path))
209
 
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
282
        revtree1, revtree2 = self.assertChanges(branch, 2,
210
283
            expected_added=[(dest_path,)])
 
284
        self.assertContent(branch, revtree1, src_path, "aaa")
 
285
        self.assertContent(branch, revtree2, src_path, "aaa")
211
286
        self.assertContent(branch, revtree2, dest_path, "aaa")
212
 
        self.assertEqual(revtree1.get_revision_id(),
213
 
                         revtree1.inventory.root.children['a'].revision)
214
 
        self.assertEqual(revtree2.get_revision_id(),
215
 
                         revtree2.inventory.root.children['b'].revision)
 
287
        self.assertRevisionRoot(revtree1, src_path)
 
288
        self.assertRevisionRoot(revtree2, dest_path)
216
289
 
217
290
    def test_copy_file_in_subdir(self):
218
291
        handler, branch = self.get_handler()
219
292
        src_path = 'a/a'
220
293
        dest_path = 'a/b'
221
294
        handler.process(self.file_command_iter(src_path, dest_path))
222
 
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
295
        revtree1, revtree2 = self.assertChanges(branch, 2,
223
296
            expected_added=[(dest_path,)])
 
297
        self.assertContent(branch, revtree1, src_path, "aaa")
 
298
        self.assertContent(branch, revtree2, src_path, "aaa")
224
299
        self.assertContent(branch, revtree2, dest_path, "aaa")
225
300
 
226
301
    def test_copy_file_to_new_dir(self):
228
303
        src_path = 'a/a'
229
304
        dest_path = 'b/a'
230
305
        handler.process(self.file_command_iter(src_path, dest_path))
231
 
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
306
        revtree1, revtree2 = self.assertChanges(branch, 2,
232
307
            expected_added=[('b',), (dest_path,)])
 
308
        self.assertContent(branch, revtree1, src_path, "aaa")
 
309
        self.assertContent(branch, revtree2, src_path, "aaa")
233
310
        self.assertContent(branch, revtree2, dest_path, "aaa")
234
311
 
235
 
    def symlink_command_iter(self, src_path, dest_path):
236
 
        def command_list():
237
 
            author = ['', 'bugs@a.com', time.time(), time.timezone]
238
 
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
239
 
            def files_one():
240
 
                yield commands.FileModifyCommand(src_path, 'symlink', False,
241
 
                        None, "aaa")
242
 
            yield commands.CommitCommand('head', '1', author,
243
 
                committer, "commit 1", None, [], files_one)
244
 
            def files_two():
245
 
                yield commands.FileCopyCommand(src_path, dest_path)
246
 
            yield commands.CommitCommand('head', '2', author,
247
 
                committer, "commit 2", ":1", [], files_two)
248
 
        return command_list
249
 
 
250
 
    def assertSymlinkTarget(self, branch, tree, path, target):
251
 
        file_id = tree.inventory.path2id(path)
252
 
        branch.lock_read()
253
 
        self.addCleanup(branch.unlock)
254
 
        self.assertEqual(tree.get_symlink_target(file_id), target)
255
 
 
256
312
    def test_copy_symlink_in_root(self):
257
313
        handler, branch = self.get_handler()
258
314
        src_path = 'a'
259
315
        dest_path = 'b'
260
 
        handler.process(self.symlink_command_iter(src_path, dest_path))
261
 
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
316
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
 
317
        revtree1, revtree2 = self.assertChanges(branch, 2,
262
318
            expected_added=[(dest_path,)])
 
319
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
 
320
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
263
321
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
264
 
        self.assertEqual(revtree1.get_revision_id(),
265
 
                         revtree1.inventory.root.children['a'].revision)
266
 
        self.assertEqual(revtree2.get_revision_id(),
267
 
                         revtree2.inventory.root.children['b'].revision)
 
322
        self.assertRevisionRoot(revtree1, src_path)
 
323
        self.assertRevisionRoot(revtree2, dest_path)
268
324
 
269
325
    def test_copy_symlink_in_subdir(self):
270
326
        handler, branch = self.get_handler()
271
327
        src_path = 'a/a'
272
328
        dest_path = 'a/b'
273
 
        handler.process(self.symlink_command_iter(src_path, dest_path))
274
 
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
329
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
 
330
        revtree1, revtree2 = self.assertChanges(branch, 2,
275
331
            expected_added=[(dest_path,)])
 
332
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
 
333
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
276
334
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
277
335
 
278
336
    def test_copy_symlink_to_new_dir(self):
279
337
        handler, branch = self.get_handler()
280
338
        src_path = 'a/a'
281
339
        dest_path = 'b/a'
282
 
        handler.process(self.symlink_command_iter(src_path, dest_path))
283
 
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
340
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
 
341
        revtree1, revtree2 = self.assertChanges(branch, 2,
284
342
            expected_added=[('b',), (dest_path,)])
 
343
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
 
344
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
285
345
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
286
346
 
287
347