/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.65.4 by James Westby
Make the rename handling more robust.
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
import time
18
19
from bzrlib import (
20
    branch,
21
    tests,
22
    )
23
24
from bzrlib.plugins.fastimport import (
25
    commands,
26
    errors,
27
    )
28
29
from bzrlib.plugins.fastimport.processors import (
30
    generic_processor,
31
    )
32
33
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
34
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
0.65.4 by James Westby
Make the rename handling more robust.
35
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
36
    branch_format = "pack-0.92"
37
0.65.4 by James Westby
Make the rename handling more robust.
38
    def get_handler(self):
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
39
        branch = self.make_branch('.', format=self.branch_format)
0.64.196 by Ian Clatworthy
get tests passing again
40
        handler = generic_processor.GenericProcessor(branch.bzrdir,
41
            prune_empty_dirs=False)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
42
        return handler, branch
0.65.4 by James Westby
Make the rename handling more robust.
43
44
    # FIXME: [] as a default is bad, as it is mutable, but I want
45
    # to use None to mean "don't check this".
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
46
    def assertChanges(self, branch, revno, expected_added=[],
47
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
48
            expected_renamed=[], expected_kind_changed=[]):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
49
        """Check the changes introduced in a revision of a branch.
50
51
        This method checks that a revision introduces expected changes.
52
        The required changes are passed in as a list, where
53
        each entry contains the needed information about the change.
54
55
        If you do not wish to assert anything about a particular
56
        category then pass None instead.
57
58
        branch: The branch.
59
        revno: revision number of revision to check.
60
        expected_added: a list of (filename,) tuples that must have
61
            been added in the delta.
62
        expected_removed: a list of (filename,) tuples that must have
63
            been removed in the delta.
64
        expected_modified: a list of (filename,) tuples that must have
65
            been modified in the delta.
66
        expected_renamed: a list of (old_path, new_path) tuples that
67
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
68
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
69
            that must have been changed in the delta.
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
70
        :return: revtree1, revtree2
71
        """
72
        repo = branch.repository
0.80.1 by Ian Clatworthy
basic units tests for filemodify
73
        revtree1 = repo.revision_tree(branch.get_rev_id(revno - 1))
74
        revtree2 = repo.revision_tree(branch.get_rev_id(revno))
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
75
        changes = revtree2.changes_from(revtree1)
0.80.3 by Ian Clatworthy
file <-> symlink change tests
76
        self._check_changes(changes, expected_added, expected_removed,
77
            expected_modified, expected_renamed, expected_kind_changed)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
78
        return revtree1, revtree2
79
0.80.3 by Ian Clatworthy
file <-> symlink change tests
80
    def _check_changes(self, changes, expected_added=[],
0.65.4 by James Westby
Make the rename handling more robust.
81
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
82
            expected_renamed=[], expected_kind_changed=[]):
0.65.4 by James Westby
Make the rename handling more robust.
83
        """Check the changes in a TreeDelta
84
85
        This method checks that the TreeDelta contains the expected
86
        modifications between the two trees that were used to generate
87
        it. The required changes are passed in as a list, where
88
        each entry contains the needed information about the change.
89
90
        If you do not wish to assert anything about a particular
91
        category then pass None instead.
92
93
        changes: The TreeDelta to check.
94
        expected_added: a list of (filename,) tuples that must have
95
            been added in the delta.
96
        expected_removed: a list of (filename,) tuples that must have
97
            been removed in the delta.
98
        expected_modified: a list of (filename,) tuples that must have
99
            been modified in the delta.
100
        expected_renamed: a list of (old_path, new_path) tuples that
101
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
102
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
103
            that must have been changed in the delta.
0.65.4 by James Westby
Make the rename handling more robust.
104
        """
105
        renamed = changes.renamed
106
        added = changes.added
107
        removed = changes.removed
108
        modified = changes.modified
0.80.3 by Ian Clatworthy
file <-> symlink change tests
109
        kind_changed = changes.kind_changed
0.65.4 by James Westby
Make the rename handling more robust.
110
        if expected_renamed is not None:
111
            self.assertEquals(len(renamed), len(expected_renamed),
0.74.1 by John Arbash Meinel
Change the rename code to create a new text entry.
112
                "%s is renamed, expected %s" % (renamed, expected_renamed))
0.65.4 by James Westby
Make the rename handling more robust.
113
            renamed_files = [(item[0], item[1]) for item in renamed]
114
            for expected_renamed_entry in expected_renamed:
115
                self.assertTrue(expected_renamed_entry in renamed_files,
116
                    "%s is not renamed, %s are" % (str(expected_renamed_entry),
117
                        renamed_files))
118
        if expected_added is not None:
119
            self.assertEquals(len(added), len(expected_added),
120
                "%s is added" % str(added))
121
            added_files = [(item[0],) for item in added]
122
            for expected_added_entry in expected_added:
123
                self.assertTrue(expected_added_entry in added_files,
124
                    "%s is not added, %s are" % (str(expected_added_entry),
125
                        added_files))
126
        if expected_removed is not None:
127
            self.assertEquals(len(removed), len(expected_removed),
128
                "%s is removed" % str(removed))
129
            removed_files = [(item[0],) for item in removed]
130
            for expected_removed_entry in expected_removed:
131
                self.assertTrue(expected_removed_entry in removed_files,
132
                    "%s is not removed, %s are" % (str(expected_removed_entry),
133
                        removed_files))
134
        if expected_modified is not None:
135
            self.assertEquals(len(modified), len(expected_modified),
136
                "%s is modified" % str(modified))
137
            modified_files = [(item[0],) for item in modified]
138
            for expected_modified_entry in expected_modified:
139
                self.assertTrue(expected_modified_entry in modified_files,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
140
                    "%s is not modified, %s are" % (
141
                    str(expected_modified_entry), modified_files))
142
        if expected_kind_changed is not None:
143
            self.assertEquals(len(kind_changed), len(expected_kind_changed),
144
                "%s is kind-changed, expected %s" % (kind_changed,
145
                    expected_kind_changed))
146
            kind_changed_files = [(item[0], item[2], item[3])
147
                for item in kind_changed]
148
            for expected_kind_changed_entry in expected_kind_changed:
149
                self.assertTrue(expected_kind_changed_entry in
150
                    kind_changed_files, "%s is not kind-changed, %s are" % (
151
                    str(expected_kind_changed_entry), kind_changed_files))
0.65.4 by James Westby
Make the rename handling more robust.
152
0.80.1 by Ian Clatworthy
basic units tests for filemodify
153
    def assertContent(self, branch, tree, path, content):
154
        file_id = tree.inventory.path2id(path)
155
        branch.lock_read()
156
        self.addCleanup(branch.unlock)
157
        self.assertEqual(tree.get_file_text(file_id), content)
158
159
    def assertSymlinkTarget(self, branch, tree, path, target):
160
        file_id = tree.inventory.path2id(path)
161
        branch.lock_read()
162
        self.addCleanup(branch.unlock)
163
        self.assertEqual(tree.get_symlink_target(file_id), target)
164
0.80.4 by Ian Clatworthy
file executable off <-> on tests
165
    def assertExecutable(self, branch, tree, path, executable):
166
        file_id = tree.inventory.path2id(path)
167
        branch.lock_read()
168
        self.addCleanup(branch.unlock)
169
        self.assertEqual(tree.is_executable(file_id), executable)
170
0.80.1 by Ian Clatworthy
basic units tests for filemodify
171
    def assertRevisionRoot(self, revtree, path):
172
        self.assertEqual(revtree.get_revision_id(),
173
                         revtree.inventory.root.children[path].revision)
174
175
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
176
class TestImportToPackModify(TestCaseForGenericProcessor):
0.80.1 by Ian Clatworthy
basic units tests for filemodify
177
0.80.3 by Ian Clatworthy
file <-> symlink change tests
178
    def file_command_iter(self, path, kind='file', content='aaa',
0.80.4 by Ian Clatworthy
file executable off <-> on tests
179
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
180
        # Revno 1: create a file or symlink
181
        # Revno 2: modify it
0.80.3 by Ian Clatworthy
file <-> symlink change tests
182
        if to_kind is None:
183
            to_kind = kind
0.80.4 by Ian Clatworthy
file executable off <-> on tests
184
        if to_executable is None:
185
            to_executable = executable
0.80.1 by Ian Clatworthy
basic units tests for filemodify
186
        def command_list():
187
            author = ['', 'bugs@a.com', time.time(), time.timezone]
188
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
189
            def files_one():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
190
                yield commands.FileModifyCommand(path, kind, executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
191
                        None, content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
192
            yield commands.CommitCommand('head', '1', author,
193
                committer, "commit 1", None, [], files_one)
194
            def files_two():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
195
                yield commands.FileModifyCommand(path, to_kind, to_executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
196
                        None, to_content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
197
            yield commands.CommitCommand('head', '2', author,
198
                committer, "commit 2", ":1", [], files_two)
199
        return command_list
200
201
    def test_modify_file_in_root(self):
202
        handler, branch = self.get_handler()
203
        path = 'a'
204
        handler.process(self.file_command_iter(path))
205
        revtree0, revtree1 = self.assertChanges(branch, 1,
206
            expected_added=[(path,)])
207
        revtree1, revtree2 = self.assertChanges(branch, 2,
208
            expected_modified=[(path,)])
209
        self.assertContent(branch, revtree1, path, "aaa")
210
        self.assertContent(branch, revtree2, path, "bbb")
211
        self.assertRevisionRoot(revtree1, path)
212
        self.assertRevisionRoot(revtree2, path)
213
214
    def test_modify_file_in_subdir(self):
215
        handler, branch = self.get_handler()
216
        path = 'a/a'
217
        handler.process(self.file_command_iter(path))
218
        revtree0, revtree1 = self.assertChanges(branch, 1,
219
            expected_added=[('a',), (path,)])
220
        revtree1, revtree2 = self.assertChanges(branch, 2,
221
            expected_modified=[(path,)])
222
        self.assertContent(branch, revtree1, path, "aaa")
223
        self.assertContent(branch, revtree2, path, "bbb")
224
225
    def test_modify_symlink_in_root(self):
226
        handler, branch = self.get_handler()
227
        path = 'a'
228
        handler.process(self.file_command_iter(path, kind='symlink'))
229
        revtree1, revtree2 = self.assertChanges(branch, 2,
230
            expected_modified=[(path,)])
231
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
232
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
233
        self.assertRevisionRoot(revtree1, path)
234
        self.assertRevisionRoot(revtree2, path)
235
236
    def test_modify_symlink_in_subdir(self):
237
        handler, branch = self.get_handler()
238
        path = 'a/a'
239
        handler.process(self.file_command_iter(path, kind='symlink'))
240
        revtree0, revtree1 = self.assertChanges(branch, 1,
241
            expected_added=[('a',), (path,)])
242
        revtree1, revtree2 = self.assertChanges(branch, 2,
243
            expected_modified=[(path,)])
244
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
245
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
246
0.80.3 by Ian Clatworthy
file <-> symlink change tests
247
    def test_modify_file_becomes_symlink(self):
248
        handler, branch = self.get_handler()
249
        path = 'a/a'
250
        handler.process(self.file_command_iter(path,
251
            kind='file', to_kind='symlink'))
252
        revtree0, revtree1 = self.assertChanges(branch, 1,
253
            expected_added=[('a',), (path,)])
254
        revtree1, revtree2 = self.assertChanges(branch, 2,
255
            expected_kind_changed=[(path, 'file', 'symlink')])
256
        self.assertContent(branch, revtree1, path, "aaa")
257
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
258
259
    def test_modify_symlink_becomes_file(self):
260
        handler, branch = self.get_handler()
261
        path = 'a/a'
262
        handler.process(self.file_command_iter(path,
263
            kind='symlink', to_kind='file'))
264
        revtree0, revtree1 = self.assertChanges(branch, 1,
265
            expected_added=[('a',), (path,)])
266
        revtree1, revtree2 = self.assertChanges(branch, 2,
267
            expected_kind_changed=[(path, 'symlink', 'file')])
268
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
269
        self.assertContent(branch, revtree2, path, "bbb")
270
0.80.4 by Ian Clatworthy
file executable off <-> on tests
271
    def test_modify_file_now_executable(self):
272
        handler, branch = self.get_handler()
273
        path = 'a/a'
274
        handler.process(self.file_command_iter(path,
275
            executable=False, to_executable=True, to_content='aaa'))
276
        revtree0, revtree1 = self.assertChanges(branch, 1,
277
            expected_added=[('a',), (path,)])
278
        revtree1, revtree2 = self.assertChanges(branch, 2,
279
            expected_modified=[(path,)])
280
        self.assertExecutable(branch, revtree1, path, False)
281
        self.assertExecutable(branch, revtree2, path, True)
282
283
    def test_modify_file_no_longer_executable(self):
284
        handler, branch = self.get_handler()
285
        path = 'a/a'
286
        handler.process(self.file_command_iter(path,
287
            executable=True, to_executable=False, to_content='aaa'))
288
        revtree0, revtree1 = self.assertChanges(branch, 1,
289
            expected_added=[('a',), (path,)])
290
        revtree1, revtree2 = self.assertChanges(branch, 2,
291
            expected_modified=[(path,)])
292
        self.assertExecutable(branch, revtree1, path, True)
293
        self.assertExecutable(branch, revtree2, path, False)
294
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
295
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
296
class TestImportToPackModifyTricky(TestCaseForGenericProcessor):
0.80.5 by Ian Clatworthy
file/symlink <-> directory change tests & fix
297
298
    def file_command_iter(self, path1, path2, kind='file'):
299
        # Revno 1: create a file or symlink in a directory
300
        # Revno 2: create a second file that implicitly deletes the
301
        # first one because either:
302
        # * the new file is a in directory with the old file name
303
        # * the new file has the same name as the directory of the first
304
        def command_list():
305
            author = ['', 'bugs@a.com', time.time(), time.timezone]
306
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
307
            def files_one():
308
                yield commands.FileModifyCommand(path1, kind, False,
309
                        None, "aaa")
310
            yield commands.CommitCommand('head', '1', author,
311
                committer, "commit 1", None, [], files_one)
312
            def files_two():
313
                yield commands.FileModifyCommand(path2, kind, False,
314
                        None, "bbb")
315
            yield commands.CommitCommand('head', '2', author,
316
                committer, "commit 2", ":1", [], files_two)
317
        return command_list
318
319
320
    def test_modify_file_becomes_directory(self):
321
        handler, branch = self.get_handler()
322
        path1 = 'a/b'
323
        path2 = 'a/b/c'
324
        handler.process(self.file_command_iter(path1, path2))
325
        revtree0, revtree1 = self.assertChanges(branch, 1,
326
            expected_added=[('a',), (path1,)])
327
        revtree1, revtree2 = self.assertChanges(branch, 2,
328
            expected_added=[(path2,)],
329
            expected_kind_changed=[(path1, 'file', 'directory')])
330
        self.assertContent(branch, revtree1, path1, "aaa")
331
        self.assertContent(branch, revtree2, path2, "bbb")
332
333
    def test_modify_directory_becomes_file(self):
334
        handler, branch = self.get_handler()
335
        path1 = 'a/b/c'
336
        path2 = 'a/b'
337
        handler.process(self.file_command_iter(path1, path2))
338
        revtree0, revtree1 = self.assertChanges(branch, 1,
339
            expected_added=[('a',), ('a/b',), (path1,)])
340
        revtree1, revtree2 = self.assertChanges(branch, 2,
341
            expected_removed=[(path1,),],
342
            expected_kind_changed=[(path2, 'directory', 'file')])
343
        self.assertContent(branch, revtree1, path1, "aaa")
344
        self.assertContent(branch, revtree2, path2, "bbb")
345
346
    def test_modify_symlink_becomes_directory(self):
347
        handler, branch = self.get_handler()
348
        path1 = 'a/b'
349
        path2 = 'a/b/c'
350
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
351
        revtree0, revtree1 = self.assertChanges(branch, 1,
352
            expected_added=[('a',), (path1,)])
353
        revtree1, revtree2 = self.assertChanges(branch, 2,
354
            expected_added=[(path2,)],
355
            expected_kind_changed=[(path1, 'symlink', 'directory')])
356
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
357
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
358
359
    def test_modify_directory_becomes_symlink(self):
360
        handler, branch = self.get_handler()
361
        path1 = 'a/b/c'
362
        path2 = 'a/b'
363
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
364
        revtree0, revtree1 = self.assertChanges(branch, 1,
365
            expected_added=[('a',), ('a/b',), (path1,)])
366
        revtree1, revtree2 = self.assertChanges(branch, 2,
367
            expected_removed=[(path1,),],
368
            expected_kind_changed=[(path2, 'directory', 'symlink')])
369
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
370
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
371
372
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
373
class TestImportToPackDelete(TestCaseForGenericProcessor):
0.80.2 by Ian Clatworthy
basic delete tests
374
375
    def file_command_iter(self, path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
376
        # Revno 1: create a file or symlink
377
        # Revno 2: delete it
0.80.2 by Ian Clatworthy
basic delete tests
378
        def command_list():
379
            author = ['', 'bugs@a.com', time.time(), time.timezone]
380
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
381
            def files_one():
382
                yield commands.FileModifyCommand(path, kind, False,
383
                        None, "aaa")
384
            yield commands.CommitCommand('head', '1', author,
385
                committer, "commit 1", None, [], files_one)
386
            def files_two():
387
                yield commands.FileDeleteCommand(path)
388
            yield commands.CommitCommand('head', '2', author,
389
                committer, "commit 2", ":1", [], files_two)
390
        return command_list
391
392
    def test_delete_file_in_root(self):
393
        handler, branch = self.get_handler()
394
        path = 'a'
395
        handler.process(self.file_command_iter(path))
396
        revtree0, revtree1 = self.assertChanges(branch, 1,
397
            expected_added=[(path,)])
398
        revtree1, revtree2 = self.assertChanges(branch, 2,
399
            expected_removed=[(path,)])
400
        self.assertContent(branch, revtree1, path, "aaa")
401
        self.assertRevisionRoot(revtree1, path)
402
403
    def test_delete_file_in_subdir(self):
404
        handler, branch = self.get_handler()
405
        path = 'a/a'
406
        handler.process(self.file_command_iter(path))
407
        revtree0, revtree1 = self.assertChanges(branch, 1,
408
            expected_added=[('a',), (path,)])
409
        revtree1, revtree2 = self.assertChanges(branch, 2,
410
            expected_removed=[(path,)])
411
        self.assertContent(branch, revtree1, path, "aaa")
412
413
    def test_delete_symlink_in_root(self):
414
        handler, branch = self.get_handler()
415
        path = 'a'
416
        handler.process(self.file_command_iter(path, kind='symlink'))
417
        revtree1, revtree2 = self.assertChanges(branch, 2,
418
            expected_removed=[(path,)])
419
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
420
        self.assertRevisionRoot(revtree1, path)
421
422
    def test_delete_symlink_in_subdir(self):
423
        handler, branch = self.get_handler()
424
        path = 'a/a'
425
        handler.process(self.file_command_iter(path, kind='symlink'))
426
        revtree0, revtree1 = self.assertChanges(branch, 1,
427
            expected_added=[('a',), (path,)])
428
        revtree1, revtree2 = self.assertChanges(branch, 2,
429
            expected_removed=[(path,)])
430
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
431
432
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
433
class TestImportToPackDeleteDirectory(TestCaseForGenericProcessor):
0.80.7 by Ian Clatworthy
add directory delete test
434
435
    def file_command_iter(self, paths, dir):
436
        # Revno 1: create multiple files
437
        # Revno 2: delete a directory holding those files
438
        def command_list():
439
            author = ['', 'bugs@a.com', time.time(), time.timezone]
440
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
441
            def files_one():
442
                for i, path in enumerate(paths):
443
                    yield commands.FileModifyCommand(path, 'file', False,
444
                            None, "aaa%d" % i)
445
            yield commands.CommitCommand('head', '1', author,
446
                committer, "commit 1", None, [], files_one)
447
            def files_two():
448
                yield commands.FileDeleteCommand(dir)
449
            yield commands.CommitCommand('head', '2', author,
450
                committer, "commit 2", ":1", [], files_two)
451
        return command_list
452
453
    def test_delete_dir(self):
454
        handler, branch = self.get_handler()
455
        paths = ['a/b/c', 'a/b/d', 'a/b/e/f', 'a/g']
456
        dir = 'a/b'
457
        handler.process(self.file_command_iter(paths, dir))
458
        revtree0, revtree1 = self.assertChanges(branch, 1,
459
            expected_added=[
460
                ('a',), ('a/b',), ('a/b/c',),
461
                ('a/b/d',),
462
                ('a/b/e',), ('a/b/e/f',),
463
                ('a/g',),
464
                ])
465
        revtree1, revtree2 = self.assertChanges(branch, 2,
466
            expected_removed=[
467
                ('a/b',), ('a/b/c',),
468
                ('a/b/d',),
469
                ('a/b/e',), ('a/b/e/f',),
470
                ])
471
472
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
473
class TestImportToPackRename(TestCaseForGenericProcessor):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
474
475
    def get_command_iter(self, old_path, new_path):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
476
        # Revno 1: create a file or symlink
477
        # Revno 2: rename it
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
478
        def command_list():
479
            author = ['', 'bugs@a.com', time.time(), time.timezone]
480
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
481
            def files_one():
482
                yield commands.FileModifyCommand(old_path, 'file', False,
483
                        None, "aaa")
484
            yield commands.CommitCommand('head', '1', author,
485
                committer, "commit 1", None, [], files_one)
486
            def files_two():
487
                yield commands.FileRenameCommand(old_path, new_path)
488
            yield commands.CommitCommand('head', '2', author,
489
                committer, "commit 2", ":1", [], files_two)
490
        return command_list
491
0.65.4 by James Westby
Make the rename handling more robust.
492
    def test_rename_in_root(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
493
        handler, branch = self.get_handler()
0.65.4 by James Westby
Make the rename handling more robust.
494
        old_path = 'a'
495
        new_path = 'b'
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
496
        handler.process(self.get_command_iter(old_path, new_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
497
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
498
            expected_renamed=[(old_path, new_path)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
499
        self.assertRevisionRoot(revtree1, old_path)
500
        self.assertRevisionRoot(revtree2, new_path)
0.65.4 by James Westby
Make the rename handling more robust.
501
502
    def test_rename_in_subdir(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
503
        handler, branch = self.get_handler()
0.65.4 by James Westby
Make the rename handling more robust.
504
        old_path = 'a/a'
505
        new_path = 'a/b'
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
506
        handler.process(self.get_command_iter(old_path, new_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
507
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
0.65.4 by James Westby
Make the rename handling more robust.
508
509
    def test_move_to_new_dir(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
510
        handler, branch = self.get_handler()
0.65.4 by James Westby
Make the rename handling more robust.
511
        old_path = 'a/a'
512
        new_path = 'b/a'
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
513
        handler.process(self.get_command_iter(old_path, new_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
514
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)],
0.65.4 by James Westby
Make the rename handling more robust.
515
            expected_added=[('b',)])
0.64.74 by Ian Clatworthy
fix symlink importing
516
517
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
518
class TestImportToPackRenameTricky(TestCaseForGenericProcessor):
0.80.6 by Ian Clatworthy
file/symlink <-> directory rename tests
519
520
    def file_command_iter(self, path1, old_path2, new_path2, kind='file'):
521
        # Revno 1: create two files or symlinks in a directory
522
        # Revno 2: rename the second file so that it implicitly deletes the
523
        # first one because either:
524
        # * the new file is a in directory with the old file name
525
        # * the new file has the same name as the directory of the first
526
        def command_list():
527
            author = ['', 'bugs@a.com', time.time(), time.timezone]
528
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
529
            def files_one():
530
                yield commands.FileModifyCommand(path1, kind, False,
531
                        None, "aaa")
532
                yield commands.FileModifyCommand(old_path2, kind, False,
533
                        None, "bbb")
534
            yield commands.CommitCommand('head', '1', author,
535
                committer, "commit 1", None, [], files_one)
536
            def files_two():
537
                yield commands.FileRenameCommand(old_path2, new_path2)
538
            yield commands.CommitCommand('head', '2', author,
539
                committer, "commit 2", ":1", [], files_two)
540
        return command_list
541
542
543
    def test_rename_file_becomes_directory(self):
544
        handler, branch = self.get_handler()
545
        old_path2 = 'foo'
546
        path1     = 'a/b'
547
        new_path2 = 'a/b/c'
548
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
549
        revtree0, revtree1 = self.assertChanges(branch, 1,
550
            expected_added=[('a',), (path1,), (old_path2,)])
551
        revtree1, revtree2 = self.assertChanges(branch, 2,
552
            expected_renamed=[(old_path2, new_path2)],
553
            expected_kind_changed=[(path1, 'file', 'directory')])
554
        self.assertContent(branch, revtree1, path1, "aaa")
555
        self.assertContent(branch, revtree2, new_path2, "bbb")
556
557
    def test_rename_directory_becomes_file(self):
558
        handler, branch = self.get_handler()
559
        old_path2 = 'foo'
560
        path1     = 'a/b/c'
561
        new_path2 = 'a/b'
562
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
563
        revtree0, revtree1 = self.assertChanges(branch, 1,
564
            expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
565
        revtree1, revtree2 = self.assertChanges(branch, 2,
566
            expected_renamed=[(old_path2, new_path2)],
567
            expected_removed=[(path1,), (new_path2,)])
568
        self.assertContent(branch, revtree1, path1, "aaa")
569
        self.assertContent(branch, revtree2, new_path2, "bbb")
570
571
    def test_rename_symlink_becomes_directory(self):
572
        handler, branch = self.get_handler()
573
        old_path2 = 'foo'
574
        path1     = 'a/b'
575
        new_path2 = 'a/b/c'
576
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
577
            'symlink'))
578
        revtree0, revtree1 = self.assertChanges(branch, 1,
579
            expected_added=[('a',), (path1,), (old_path2,)])
580
        revtree1, revtree2 = self.assertChanges(branch, 2,
581
            expected_renamed=[(old_path2, new_path2)],
582
            expected_kind_changed=[(path1, 'symlink', 'directory')])
583
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
584
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
585
586
    def test_rename_directory_becomes_symlink(self):
587
        handler, branch = self.get_handler()
588
        old_path2 = 'foo'
589
        path1     = 'a/b/c'
590
        new_path2 = 'a/b'
591
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
592
            'symlink'))
593
        revtree0, revtree1 = self.assertChanges(branch, 1,
594
            expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
595
        revtree1, revtree2 = self.assertChanges(branch, 2,
596
            expected_renamed=[(old_path2, new_path2)],
597
            expected_removed=[(path1,), (new_path2,)])
598
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
599
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
600
601
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
602
class TestImportToPackCopy(TestCaseForGenericProcessor):
0.76.2 by Ian Clatworthy
code & tests for file copying
603
0.80.1 by Ian Clatworthy
basic units tests for filemodify
604
    def file_command_iter(self, src_path, dest_path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
605
        # Revno 1: create a file or symlink
606
        # Revno 2: copy it
0.76.2 by Ian Clatworthy
code & tests for file copying
607
        def command_list():
608
            author = ['', 'bugs@a.com', time.time(), time.timezone]
609
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
610
            def files_one():
0.80.1 by Ian Clatworthy
basic units tests for filemodify
611
                yield commands.FileModifyCommand(src_path, kind, False,
0.76.2 by Ian Clatworthy
code & tests for file copying
612
                        None, "aaa")
613
            yield commands.CommitCommand('head', '1', author,
614
                committer, "commit 1", None, [], files_one)
615
            def files_two():
616
                yield commands.FileCopyCommand(src_path, dest_path)
617
            yield commands.CommitCommand('head', '2', author,
618
                committer, "commit 2", ":1", [], files_two)
619
        return command_list
620
621
    def test_copy_file_in_root(self):
622
        handler, branch = self.get_handler()
623
        src_path = 'a'
624
        dest_path = 'b'
625
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
626
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
627
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
628
        self.assertContent(branch, revtree1, src_path, "aaa")
629
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
630
        self.assertContent(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
631
        self.assertRevisionRoot(revtree1, src_path)
632
        self.assertRevisionRoot(revtree2, dest_path)
0.76.2 by Ian Clatworthy
code & tests for file copying
633
634
    def test_copy_file_in_subdir(self):
635
        handler, branch = self.get_handler()
636
        src_path = 'a/a'
637
        dest_path = 'a/b'
638
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
639
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
640
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
641
        self.assertContent(branch, revtree1, src_path, "aaa")
642
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
643
        self.assertContent(branch, revtree2, dest_path, "aaa")
644
645
    def test_copy_file_to_new_dir(self):
646
        handler, branch = self.get_handler()
647
        src_path = 'a/a'
648
        dest_path = 'b/a'
649
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
650
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
651
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
652
        self.assertContent(branch, revtree1, src_path, "aaa")
653
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
654
        self.assertContent(branch, revtree2, dest_path, "aaa")
655
0.76.3 by Ian Clatworthy
symlink copying tests
656
    def test_copy_symlink_in_root(self):
657
        handler, branch = self.get_handler()
658
        src_path = 'a'
659
        dest_path = 'b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
660
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
661
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
662
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
663
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
664
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
665
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
666
        self.assertRevisionRoot(revtree1, src_path)
667
        self.assertRevisionRoot(revtree2, dest_path)
0.76.3 by Ian Clatworthy
symlink copying tests
668
669
    def test_copy_symlink_in_subdir(self):
670
        handler, branch = self.get_handler()
671
        src_path = 'a/a'
672
        dest_path = 'a/b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
673
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
674
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
675
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
676
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
677
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
678
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
679
680
    def test_copy_symlink_to_new_dir(self):
681
        handler, branch = self.get_handler()
682
        src_path = 'a/a'
683
        dest_path = 'b/a'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
684
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
685
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
686
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
687
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
688
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
689
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
690
0.76.2 by Ian Clatworthy
code & tests for file copying
691
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
692
class TestImportToPackFileKinds(TestCaseForGenericProcessor):
0.64.74 by Ian Clatworthy
fix symlink importing
693
694
    def get_command_iter(self, path, kind, content):
695
        def command_list():
696
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
697
            def files_one():
698
                yield commands.FileModifyCommand(path, kind, False,
699
                        None, content)
700
            yield commands.CommitCommand('head', '1', None,
701
                committer, "commit 1", None, [], files_one)
702
        return command_list
703
704
    def test_import_plainfile(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
705
        handler, branch = self.get_handler()
706
        handler.process(self.get_command_iter('foo', 'file', 'aaa'))
0.64.74 by Ian Clatworthy
fix symlink importing
707
708
    def test_import_symlink(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
709
        handler, branch = self.get_handler()
710
        handler.process(self.get_command_iter('foo', 'symlink', 'bar'))
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
711
712
713
### TODO: Parameterise tests rather than below hack
714
0.85.2 by Ian Clatworthy
improve per-file graph generation
715
class TestImportToRichRootModify(TestImportToPackModify):
716
    branch_format = "1.9-rich-root"
717
718
class TestImportToRichRootModifyTricky(TestImportToPackModifyTricky):
719
    branch_format = "1.9-rich-root"
720
721
class TestImportToRichRootDelete(TestImportToPackDelete):
722
    branch_format = "1.9-rich-root"
723
724
class TestImportToRichRootDeleteDirectory(TestImportToPackDeleteDirectory):
725
    branch_format = "1.9-rich-root"
726
727
class TestImportToRichRootRename(TestImportToPackRename):
728
    branch_format = "1.9-rich-root"
729
730
class TestImportToRichRootRenameTricky(TestImportToPackRenameTricky):
731
    branch_format = "1.9-rich-root"
732
733
class TestImportToRichRootCopy(TestImportToPackCopy):
734
    branch_format = "1.9-rich-root"
735
736
class TestImportToRichRootFileKinds(TestImportToPackFileKinds):
737
    branch_format = "1.9-rich-root"
738
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
739
try:
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
740
    from bzrlib.repofmt.groupcompress_repo import RepositoryFormatCHK1
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
741
742
    class TestImportToChkModify(TestImportToPackModify):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
743
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
744
745
    class TestImportToChkModifyTricky(TestImportToPackModifyTricky):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
746
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
747
748
    class TestImportToChkDelete(TestImportToPackDelete):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
749
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
750
751
    class TestImportToChkDeleteDirectory(TestImportToPackDeleteDirectory):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
752
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
753
754
    class TestImportToChkRename(TestImportToPackRename):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
755
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
756
757
    class TestImportToChkRenameTricky(TestImportToPackRenameTricky):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
758
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
759
760
    class TestImportToChkCopy(TestImportToPackCopy):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
761
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
762
763
    class TestImportToChkFileKinds(TestImportToPackFileKinds):
0.64.179 by Ian Clatworthy
upgrade tests to use --development6-rich-root
764
        branch_format = "development6-rich-root"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
765
766
except ImportError:
767
    pass