/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-17 23:37:24 UTC
  • mto: (0.64.114 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090217233724-y6q12cyoyln6vkh6
code & tests for file copying

Show diffs side-by-side

added added

removed removed

Lines of Context:
178
178
            expected_added=[('b',)])
179
179
 
180
180
 
 
181
class TestCopy(TestCaseForGenericProcessor):
 
182
 
 
183
    def file_command_iter(self, src_path, dest_path):
 
184
        def command_list():
 
185
            author = ['', 'bugs@a.com', time.time(), time.timezone]
 
186
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
 
187
            def files_one():
 
188
                yield commands.FileModifyCommand(src_path, 'file', False,
 
189
                        None, "aaa")
 
190
            yield commands.CommitCommand('head', '1', author,
 
191
                committer, "commit 1", None, [], files_one)
 
192
            def files_two():
 
193
                yield commands.FileCopyCommand(src_path, dest_path)
 
194
            yield commands.CommitCommand('head', '2', author,
 
195
                committer, "commit 2", ":1", [], files_two)
 
196
        return command_list
 
197
 
 
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
    def test_copy_file_in_root(self):
 
205
        handler, branch = self.get_handler()
 
206
        src_path = 'a'
 
207
        dest_path = 'b'
 
208
        handler.process(self.file_command_iter(src_path, dest_path))
 
209
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
210
            expected_added=[(dest_path,)])
 
211
        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)
 
216
 
 
217
    def test_copy_file_in_subdir(self):
 
218
        handler, branch = self.get_handler()
 
219
        src_path = 'a/a'
 
220
        dest_path = 'a/b'
 
221
        handler.process(self.file_command_iter(src_path, dest_path))
 
222
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
223
            expected_added=[(dest_path,)])
 
224
        self.assertContent(branch, revtree2, dest_path, "aaa")
 
225
 
 
226
    def test_copy_file_to_new_dir(self):
 
227
        handler, branch = self.get_handler()
 
228
        src_path = 'a/a'
 
229
        dest_path = 'b/a'
 
230
        handler.process(self.file_command_iter(src_path, dest_path))
 
231
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
232
            expected_added=[('b',), (dest_path,)])
 
233
        self.assertContent(branch, revtree2, dest_path, "aaa")
 
234
 
 
235
 
181
236
class TestFileKinds(TestCaseForGenericProcessor):
182
237
 
183
238
    def get_command_iter(self, path, kind, content):