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