/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.115.2 by John Arbash Meinel
Change to multiplying tests rather than manually.
34
def load_tests(standard_tests, module, loader):
35
    """Parameterize tests for all versions of groupcompress."""
36
    scenarios = [
37
        ('pack-0.92', {'branch_format': 'pack-0.92'}),
38
        ('1.9-rich-root', {'branch_format': '1.9-rich-root'}),
39
    ]
40
    try:
41
        from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
42
        scenarios.append(('2a', {'branch_format': '2a'}))
43
    except ImportError:
44
        pass
45
    suite = loader.suiteClass()
46
    result = tests.multiply_tests(standard_tests, scenarios, suite)
47
    return result
48
49
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
50
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
0.65.4 by James Westby
Make the rename handling more robust.
51
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
52
    branch_format = "pack-0.92"
53
0.65.4 by James Westby
Make the rename handling more robust.
54
    def get_handler(self):
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
55
        branch = self.make_branch('.', format=self.branch_format)
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
56
        handler = generic_processor.GenericProcessor(branch.bzrdir)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
57
        return handler, branch
0.65.4 by James Westby
Make the rename handling more robust.
58
59
    # FIXME: [] as a default is bad, as it is mutable, but I want
60
    # to use None to mean "don't check this".
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
61
    def assertChanges(self, branch, revno, expected_added=[],
62
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
63
            expected_renamed=[], expected_kind_changed=[]):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
64
        """Check the changes introduced in a revision of a branch.
65
66
        This method checks that a revision introduces expected changes.
67
        The required changes are passed in as a list, where
68
        each entry contains the needed information about the change.
69
70
        If you do not wish to assert anything about a particular
71
        category then pass None instead.
72
73
        branch: The branch.
74
        revno: revision number of revision to check.
75
        expected_added: a list of (filename,) tuples that must have
76
            been added in the delta.
77
        expected_removed: a list of (filename,) tuples that must have
78
            been removed in the delta.
79
        expected_modified: a list of (filename,) tuples that must have
80
            been modified in the delta.
81
        expected_renamed: a list of (old_path, new_path) tuples that
82
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
83
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
84
            that must have been changed in the delta.
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
85
        :return: revtree1, revtree2
86
        """
87
        repo = branch.repository
0.80.1 by Ian Clatworthy
basic units tests for filemodify
88
        revtree1 = repo.revision_tree(branch.get_rev_id(revno - 1))
89
        revtree2 = repo.revision_tree(branch.get_rev_id(revno))
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
90
        changes = revtree2.changes_from(revtree1)
0.80.3 by Ian Clatworthy
file <-> symlink change tests
91
        self._check_changes(changes, expected_added, expected_removed,
92
            expected_modified, expected_renamed, expected_kind_changed)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
93
        return revtree1, revtree2
94
0.80.3 by Ian Clatworthy
file <-> symlink change tests
95
    def _check_changes(self, changes, expected_added=[],
0.65.4 by James Westby
Make the rename handling more robust.
96
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
97
            expected_renamed=[], expected_kind_changed=[]):
0.65.4 by James Westby
Make the rename handling more robust.
98
        """Check the changes in a TreeDelta
99
100
        This method checks that the TreeDelta contains the expected
101
        modifications between the two trees that were used to generate
102
        it. The required changes are passed in as a list, where
103
        each entry contains the needed information about the change.
104
105
        If you do not wish to assert anything about a particular
106
        category then pass None instead.
107
108
        changes: The TreeDelta to check.
109
        expected_added: a list of (filename,) tuples that must have
110
            been added in the delta.
111
        expected_removed: a list of (filename,) tuples that must have
112
            been removed in the delta.
113
        expected_modified: a list of (filename,) tuples that must have
114
            been modified in the delta.
115
        expected_renamed: a list of (old_path, new_path) tuples that
116
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
117
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
118
            that must have been changed in the delta.
0.65.4 by James Westby
Make the rename handling more robust.
119
        """
120
        renamed = changes.renamed
121
        added = changes.added
122
        removed = changes.removed
123
        modified = changes.modified
0.80.3 by Ian Clatworthy
file <-> symlink change tests
124
        kind_changed = changes.kind_changed
0.65.4 by James Westby
Make the rename handling more robust.
125
        if expected_renamed is not None:
126
            self.assertEquals(len(renamed), len(expected_renamed),
0.74.1 by John Arbash Meinel
Change the rename code to create a new text entry.
127
                "%s is renamed, expected %s" % (renamed, expected_renamed))
0.65.4 by James Westby
Make the rename handling more robust.
128
            renamed_files = [(item[0], item[1]) for item in renamed]
129
            for expected_renamed_entry in expected_renamed:
130
                self.assertTrue(expected_renamed_entry in renamed_files,
131
                    "%s is not renamed, %s are" % (str(expected_renamed_entry),
132
                        renamed_files))
133
        if expected_added is not None:
134
            self.assertEquals(len(added), len(expected_added),
135
                "%s is added" % str(added))
136
            added_files = [(item[0],) for item in added]
137
            for expected_added_entry in expected_added:
138
                self.assertTrue(expected_added_entry in added_files,
139
                    "%s is not added, %s are" % (str(expected_added_entry),
140
                        added_files))
141
        if expected_removed is not None:
142
            self.assertEquals(len(removed), len(expected_removed),
143
                "%s is removed" % str(removed))
144
            removed_files = [(item[0],) for item in removed]
145
            for expected_removed_entry in expected_removed:
146
                self.assertTrue(expected_removed_entry in removed_files,
147
                    "%s is not removed, %s are" % (str(expected_removed_entry),
148
                        removed_files))
149
        if expected_modified is not None:
150
            self.assertEquals(len(modified), len(expected_modified),
151
                "%s is modified" % str(modified))
152
            modified_files = [(item[0],) for item in modified]
153
            for expected_modified_entry in expected_modified:
154
                self.assertTrue(expected_modified_entry in modified_files,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
155
                    "%s is not modified, %s are" % (
156
                    str(expected_modified_entry), modified_files))
157
        if expected_kind_changed is not None:
158
            self.assertEquals(len(kind_changed), len(expected_kind_changed),
159
                "%s is kind-changed, expected %s" % (kind_changed,
160
                    expected_kind_changed))
161
            kind_changed_files = [(item[0], item[2], item[3])
162
                for item in kind_changed]
163
            for expected_kind_changed_entry in expected_kind_changed:
164
                self.assertTrue(expected_kind_changed_entry in
165
                    kind_changed_files, "%s is not kind-changed, %s are" % (
166
                    str(expected_kind_changed_entry), kind_changed_files))
0.65.4 by James Westby
Make the rename handling more robust.
167
0.80.1 by Ian Clatworthy
basic units tests for filemodify
168
    def assertContent(self, branch, tree, path, content):
169
        file_id = tree.inventory.path2id(path)
170
        branch.lock_read()
171
        self.addCleanup(branch.unlock)
172
        self.assertEqual(tree.get_file_text(file_id), content)
173
174
    def assertSymlinkTarget(self, branch, tree, path, target):
175
        file_id = tree.inventory.path2id(path)
176
        branch.lock_read()
177
        self.addCleanup(branch.unlock)
178
        self.assertEqual(tree.get_symlink_target(file_id), target)
179
0.80.4 by Ian Clatworthy
file executable off <-> on tests
180
    def assertExecutable(self, branch, tree, path, executable):
181
        file_id = tree.inventory.path2id(path)
182
        branch.lock_read()
183
        self.addCleanup(branch.unlock)
184
        self.assertEqual(tree.is_executable(file_id), executable)
185
0.80.1 by Ian Clatworthy
basic units tests for filemodify
186
    def assertRevisionRoot(self, revtree, path):
187
        self.assertEqual(revtree.get_revision_id(),
188
                         revtree.inventory.root.children[path].revision)
189
190
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
191
class TestImportToPackModify(TestCaseForGenericProcessor):
0.80.1 by Ian Clatworthy
basic units tests for filemodify
192
0.80.3 by Ian Clatworthy
file <-> symlink change tests
193
    def file_command_iter(self, path, kind='file', content='aaa',
0.80.4 by Ian Clatworthy
file executable off <-> on tests
194
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
195
        # Revno 1: create a file or symlink
196
        # Revno 2: modify it
0.80.3 by Ian Clatworthy
file <-> symlink change tests
197
        if to_kind is None:
198
            to_kind = kind
0.80.4 by Ian Clatworthy
file executable off <-> on tests
199
        if to_executable is None:
200
            to_executable = executable
0.80.1 by Ian Clatworthy
basic units tests for filemodify
201
        def command_list():
202
            author = ['', 'bugs@a.com', time.time(), time.timezone]
203
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
204
            def files_one():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
205
                yield commands.FileModifyCommand(path, kind, executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
206
                        None, content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
207
            yield commands.CommitCommand('head', '1', author,
208
                committer, "commit 1", None, [], files_one)
209
            def files_two():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
210
                yield commands.FileModifyCommand(path, to_kind, to_executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
211
                        None, to_content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
212
            yield commands.CommitCommand('head', '2', author,
213
                committer, "commit 2", ":1", [], files_two)
214
        return command_list
215
216
    def test_modify_file_in_root(self):
217
        handler, branch = self.get_handler()
218
        path = 'a'
219
        handler.process(self.file_command_iter(path))
220
        revtree0, revtree1 = self.assertChanges(branch, 1,
221
            expected_added=[(path,)])
222
        revtree1, revtree2 = self.assertChanges(branch, 2,
223
            expected_modified=[(path,)])
224
        self.assertContent(branch, revtree1, path, "aaa")
225
        self.assertContent(branch, revtree2, path, "bbb")
226
        self.assertRevisionRoot(revtree1, path)
227
        self.assertRevisionRoot(revtree2, path)
228
229
    def test_modify_file_in_subdir(self):
230
        handler, branch = self.get_handler()
231
        path = 'a/a'
232
        handler.process(self.file_command_iter(path))
233
        revtree0, revtree1 = self.assertChanges(branch, 1,
234
            expected_added=[('a',), (path,)])
235
        revtree1, revtree2 = self.assertChanges(branch, 2,
236
            expected_modified=[(path,)])
237
        self.assertContent(branch, revtree1, path, "aaa")
238
        self.assertContent(branch, revtree2, path, "bbb")
239
240
    def test_modify_symlink_in_root(self):
241
        handler, branch = self.get_handler()
242
        path = 'a'
243
        handler.process(self.file_command_iter(path, kind='symlink'))
244
        revtree1, revtree2 = self.assertChanges(branch, 2,
245
            expected_modified=[(path,)])
246
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
247
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
248
        self.assertRevisionRoot(revtree1, path)
249
        self.assertRevisionRoot(revtree2, path)
250
251
    def test_modify_symlink_in_subdir(self):
252
        handler, branch = self.get_handler()
253
        path = 'a/a'
254
        handler.process(self.file_command_iter(path, kind='symlink'))
255
        revtree0, revtree1 = self.assertChanges(branch, 1,
256
            expected_added=[('a',), (path,)])
257
        revtree1, revtree2 = self.assertChanges(branch, 2,
258
            expected_modified=[(path,)])
259
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
260
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
261
0.80.3 by Ian Clatworthy
file <-> symlink change tests
262
    def test_modify_file_becomes_symlink(self):
263
        handler, branch = self.get_handler()
264
        path = 'a/a'
265
        handler.process(self.file_command_iter(path,
266
            kind='file', to_kind='symlink'))
267
        revtree0, revtree1 = self.assertChanges(branch, 1,
268
            expected_added=[('a',), (path,)])
269
        revtree1, revtree2 = self.assertChanges(branch, 2,
270
            expected_kind_changed=[(path, 'file', 'symlink')])
271
        self.assertContent(branch, revtree1, path, "aaa")
272
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
273
274
    def test_modify_symlink_becomes_file(self):
275
        handler, branch = self.get_handler()
276
        path = 'a/a'
277
        handler.process(self.file_command_iter(path,
278
            kind='symlink', to_kind='file'))
279
        revtree0, revtree1 = self.assertChanges(branch, 1,
280
            expected_added=[('a',), (path,)])
281
        revtree1, revtree2 = self.assertChanges(branch, 2,
282
            expected_kind_changed=[(path, 'symlink', 'file')])
283
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
284
        self.assertContent(branch, revtree2, path, "bbb")
285
0.80.4 by Ian Clatworthy
file executable off <-> on tests
286
    def test_modify_file_now_executable(self):
287
        handler, branch = self.get_handler()
288
        path = 'a/a'
289
        handler.process(self.file_command_iter(path,
290
            executable=False, to_executable=True, to_content='aaa'))
291
        revtree0, revtree1 = self.assertChanges(branch, 1,
292
            expected_added=[('a',), (path,)])
293
        revtree1, revtree2 = self.assertChanges(branch, 2,
294
            expected_modified=[(path,)])
295
        self.assertExecutable(branch, revtree1, path, False)
296
        self.assertExecutable(branch, revtree2, path, True)
297
298
    def test_modify_file_no_longer_executable(self):
299
        handler, branch = self.get_handler()
300
        path = 'a/a'
301
        handler.process(self.file_command_iter(path,
302
            executable=True, to_executable=False, to_content='aaa'))
303
        revtree0, revtree1 = self.assertChanges(branch, 1,
304
            expected_added=[('a',), (path,)])
305
        revtree1, revtree2 = self.assertChanges(branch, 2,
306
            expected_modified=[(path,)])
307
        self.assertExecutable(branch, revtree1, path, True)
308
        self.assertExecutable(branch, revtree2, path, False)
309
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
310
0.99.5 by Ian Clatworthy
handle adding the same file twice in the one commit
311
class TestImportToPackModifyTwice(TestCaseForGenericProcessor):
312
    """This tests when the same file is modified twice in the one commit.
313
    
314
    Note: hg-fast-export produces data like this on occasions.
315
    """
316
317
    def file_command_iter(self, path, kind='file', content='aaa',
318
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
319
        # Revno 1: create a file twice
320
        if to_kind is None:
321
            to_kind = kind
322
        if to_executable is None:
323
            to_executable = executable
324
        def command_list():
325
            author = ['', 'bugs@a.com', time.time(), time.timezone]
326
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
327
            def files_one():
328
                yield commands.FileModifyCommand(path, kind, executable,
329
                        None, content)
330
                yield commands.FileModifyCommand(path, to_kind, to_executable,
331
                        None, to_content)
332
            yield commands.CommitCommand('head', '1', author,
333
                committer, "commit 1", None, [], files_one)
334
        return command_list
335
336
    def test_modify_file_twice_in_root(self):
337
        handler, branch = self.get_handler()
338
        path = 'a'
339
        handler.process(self.file_command_iter(path))
340
        revtree0, revtree1 = self.assertChanges(branch, 1,
341
            expected_added=[(path,)])
342
        self.assertContent(branch, revtree1, path, "aaa")
343
        self.assertRevisionRoot(revtree1, path)
344
345
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
346
class TestImportToPackModifyTricky(TestCaseForGenericProcessor):
0.80.5 by Ian Clatworthy
file/symlink <-> directory change tests & fix
347
348
    def file_command_iter(self, path1, path2, kind='file'):
349
        # Revno 1: create a file or symlink in a directory
350
        # Revno 2: create a second file that implicitly deletes the
351
        # first one because either:
352
        # * the new file is a in directory with the old file name
353
        # * the new file has the same name as the directory of the first
354
        def command_list():
355
            author = ['', 'bugs@a.com', time.time(), time.timezone]
356
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
357
            def files_one():
358
                yield commands.FileModifyCommand(path1, kind, False,
359
                        None, "aaa")
360
            yield commands.CommitCommand('head', '1', author,
361
                committer, "commit 1", None, [], files_one)
362
            def files_two():
363
                yield commands.FileModifyCommand(path2, kind, False,
364
                        None, "bbb")
365
            yield commands.CommitCommand('head', '2', author,
366
                committer, "commit 2", ":1", [], files_two)
367
        return command_list
368
369
370
    def test_modify_file_becomes_directory(self):
371
        handler, branch = self.get_handler()
372
        path1 = 'a/b'
373
        path2 = 'a/b/c'
374
        handler.process(self.file_command_iter(path1, path2))
375
        revtree0, revtree1 = self.assertChanges(branch, 1,
376
            expected_added=[('a',), (path1,)])
377
        revtree1, revtree2 = self.assertChanges(branch, 2,
378
            expected_added=[(path2,)],
379
            expected_kind_changed=[(path1, 'file', 'directory')])
380
        self.assertContent(branch, revtree1, path1, "aaa")
381
        self.assertContent(branch, revtree2, path2, "bbb")
382
383
    def test_modify_directory_becomes_file(self):
384
        handler, branch = self.get_handler()
385
        path1 = 'a/b/c'
386
        path2 = 'a/b'
387
        handler.process(self.file_command_iter(path1, path2))
388
        revtree0, revtree1 = self.assertChanges(branch, 1,
389
            expected_added=[('a',), ('a/b',), (path1,)])
390
        revtree1, revtree2 = self.assertChanges(branch, 2,
391
            expected_removed=[(path1,),],
392
            expected_kind_changed=[(path2, 'directory', 'file')])
393
        self.assertContent(branch, revtree1, path1, "aaa")
394
        self.assertContent(branch, revtree2, path2, "bbb")
395
396
    def test_modify_symlink_becomes_directory(self):
397
        handler, branch = self.get_handler()
398
        path1 = 'a/b'
399
        path2 = 'a/b/c'
400
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
401
        revtree0, revtree1 = self.assertChanges(branch, 1,
402
            expected_added=[('a',), (path1,)])
403
        revtree1, revtree2 = self.assertChanges(branch, 2,
404
            expected_added=[(path2,)],
405
            expected_kind_changed=[(path1, 'symlink', 'directory')])
406
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
407
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
408
409
    def test_modify_directory_becomes_symlink(self):
410
        handler, branch = self.get_handler()
411
        path1 = 'a/b/c'
412
        path2 = 'a/b'
413
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
414
        revtree0, revtree1 = self.assertChanges(branch, 1,
415
            expected_added=[('a',), ('a/b',), (path1,)])
416
        revtree1, revtree2 = self.assertChanges(branch, 2,
417
            expected_removed=[(path1,),],
418
            expected_kind_changed=[(path2, 'directory', 'symlink')])
419
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
420
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
421
422
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
423
class TestImportToPackDelete(TestCaseForGenericProcessor):
0.80.2 by Ian Clatworthy
basic delete tests
424
425
    def file_command_iter(self, path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
426
        # Revno 1: create a file or symlink
427
        # Revno 2: delete it
0.80.2 by Ian Clatworthy
basic delete tests
428
        def command_list():
429
            author = ['', 'bugs@a.com', time.time(), time.timezone]
430
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
431
            def files_one():
432
                yield commands.FileModifyCommand(path, kind, False,
433
                        None, "aaa")
434
            yield commands.CommitCommand('head', '1', author,
435
                committer, "commit 1", None, [], files_one)
436
            def files_two():
437
                yield commands.FileDeleteCommand(path)
438
            yield commands.CommitCommand('head', '2', author,
439
                committer, "commit 2", ":1", [], files_two)
440
        return command_list
441
442
    def test_delete_file_in_root(self):
443
        handler, branch = self.get_handler()
444
        path = 'a'
445
        handler.process(self.file_command_iter(path))
446
        revtree0, revtree1 = self.assertChanges(branch, 1,
447
            expected_added=[(path,)])
448
        revtree1, revtree2 = self.assertChanges(branch, 2,
449
            expected_removed=[(path,)])
450
        self.assertContent(branch, revtree1, path, "aaa")
451
        self.assertRevisionRoot(revtree1, path)
452
453
    def test_delete_file_in_subdir(self):
454
        handler, branch = self.get_handler()
455
        path = 'a/a'
456
        handler.process(self.file_command_iter(path))
457
        revtree0, revtree1 = self.assertChanges(branch, 1,
458
            expected_added=[('a',), (path,)])
459
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
460
            expected_removed=[('a',), (path,)])
0.80.2 by Ian Clatworthy
basic delete tests
461
        self.assertContent(branch, revtree1, path, "aaa")
462
463
    def test_delete_symlink_in_root(self):
464
        handler, branch = self.get_handler()
465
        path = 'a'
466
        handler.process(self.file_command_iter(path, kind='symlink'))
467
        revtree1, revtree2 = self.assertChanges(branch, 2,
468
            expected_removed=[(path,)])
469
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
470
        self.assertRevisionRoot(revtree1, path)
471
472
    def test_delete_symlink_in_subdir(self):
473
        handler, branch = self.get_handler()
474
        path = 'a/a'
475
        handler.process(self.file_command_iter(path, kind='symlink'))
476
        revtree0, revtree1 = self.assertChanges(branch, 1,
477
            expected_added=[('a',), (path,)])
478
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
479
            expected_removed=[('a',), (path,)])
0.80.2 by Ian Clatworthy
basic delete tests
480
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
481
0.96.2 by Ian Clatworthy
test and fix for implicit directory delete recursing up
482
    def test_delete_file_in_deep_subdir(self):
483
        handler, branch = self.get_handler()
484
        path = 'a/b/c/d'
485
        handler.process(self.file_command_iter(path))
486
        revtree0, revtree1 = self.assertChanges(branch, 1,
487
            expected_added=[('a',), ('a/b',), ('a/b/c',), (path,)])
488
        revtree1, revtree2 = self.assertChanges(branch, 2,
489
            expected_removed=[('a',), ('a/b',), ('a/b/c',), (path,)])
490
        self.assertContent(branch, revtree1, path, "aaa")
491
0.80.2 by Ian Clatworthy
basic delete tests
492
0.99.7 by Ian Clatworthy
handle a delete of a newly added file
493
class TestImportToPackDeleteNew(TestCaseForGenericProcessor):
494
    """Test deletion of a newly added file."""
495
496
    def file_command_iter(self, path, kind='file'):
497
        # Revno 1: create a file or symlink then delete it
498
        def command_list():
499
            author = ['', 'bugs@a.com', time.time(), time.timezone]
500
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
501
            def files_one():
502
                yield commands.FileModifyCommand(path, kind, False,
503
                        None, "aaa")
504
                yield commands.FileDeleteCommand(path)
505
            yield commands.CommitCommand('head', '1', author,
506
                committer, "commit 1", None, [], files_one)
507
        return command_list
508
509
    def test_delete_new_file_in_root(self):
510
        handler, branch = self.get_handler()
511
        path = 'a'
512
        handler.process(self.file_command_iter(path))
513
        revtree0, revtree1 = self.assertChanges(branch, 1,)
514
515
    def test_delete_new_file_in_subdir(self):
516
        handler, branch = self.get_handler()
517
        path = 'a/a'
518
        handler.process(self.file_command_iter(path))
519
        revtree0, revtree1 = self.assertChanges(branch, 1,)
520
521
    def test_delete_new_symlink_in_root(self):
522
        handler, branch = self.get_handler()
523
        path = 'a'
524
        handler.process(self.file_command_iter(path, kind='symlink'))
525
        revtree0, revtree1 = self.assertChanges(branch, 1,)
526
527
    def test_delete_new_symlink_in_subdir(self):
528
        handler, branch = self.get_handler()
529
        path = 'a/a'
530
        handler.process(self.file_command_iter(path, kind='symlink'))
531
        revtree0, revtree1 = self.assertChanges(branch, 1,)
532
533
    def test_delete_new_file_in_deep_subdir(self):
534
        handler, branch = self.get_handler()
535
        path = 'a/b/c/d'
536
        handler.process(self.file_command_iter(path))
537
        revtree0, revtree1 = self.assertChanges(branch, 1,)
538
539
0.101.1 by Tom Widmer
Add test cases to check deletions from multiple levels in a tree still cause pruning of empty dirs to happen correctly.
540
class TestImportToPackDeleteMultiLevel(TestCaseForGenericProcessor):
541
542
    def file_command_iter(self, paths, paths_to_delete):
543
        # Revno 1: create multiple files
544
        # Revno 2: delete multiple files
545
        def command_list():
546
            author = ['', 'bugs@a.com', time.time(), time.timezone]
547
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
548
            def files_one():
549
                for i, path in enumerate(paths):
550
                    yield commands.FileModifyCommand(path, 'file', False,
551
                            None, "aaa%d" % i)
552
            yield commands.CommitCommand('head', '1', author,
553
                committer, "commit 1", None, [], files_one)
554
            def files_two():
555
                for path in paths_to_delete:
556
                    yield commands.FileDeleteCommand(path)
557
            yield commands.CommitCommand('head', '2', author,
558
                committer, "commit 2", ":1", [], files_two)
559
        return command_list
560
561
    def test_delete_files_in_multiple_levels(self):
562
        handler, branch = self.get_handler()
563
        paths = ['a/b/c', 'a/b/d/e']
564
        paths_to_delete = ['a/b/c', 'a/b/d/e']
565
        handler.process(self.file_command_iter(paths, paths_to_delete))
566
        revtree0, revtree1 = self.assertChanges(branch, 1,
567
            expected_added=[
568
                ('a',), ('a/b',), ('a/b/c',),
569
                ('a/b/d',), ('a/b/d/e',),
570
                ])
571
        revtree1, revtree2 = self.assertChanges(branch, 2,
572
            expected_removed=[
573
                ('a',), ('a/b',), ('a/b/c',),
574
                ('a/b/d',), ('a/b/d/e',),
575
                ])
576
577
    def test_delete_file_single_level(self):
578
        handler, branch = self.get_handler()
579
        paths = ['a/b/c', 'a/b/d/e']
580
        paths_to_delete = ['a/b/d/e']
581
        handler.process(self.file_command_iter(paths, paths_to_delete))
582
        revtree0, revtree1 = self.assertChanges(branch, 1,
583
            expected_added=[
584
                ('a',), ('a/b',), ('a/b/c',),
585
                ('a/b/d',), ('a/b/d/e',),
586
                ])
587
        revtree1, revtree2 = self.assertChanges(branch, 2,
588
            expected_removed=[
589
                ('a/b/d',), ('a/b/d/e',),
590
                ])
591
592
    def test_delete_file_complex_level(self):
593
        handler, branch = self.get_handler()
594
        paths = ['a/b/c', 'a/b/d/e', 'a/f/g', 'a/h', 'a/b/d/i/j']
595
        paths_to_delete = ['a/b/c', 'a/b/d/e', 'a/f/g', 'a/b/d/i/j']
596
        handler.process(self.file_command_iter(paths, paths_to_delete))
597
        revtree0, revtree1 = self.assertChanges(branch, 1,
598
            expected_added=[
599
                ('a',), ('a/b',), ('a/b/c',),
600
                ('a/b/d',), ('a/b/d/e',),
601
                ('a/f',), ('a/f/g',),
602
                ('a/h',),
603
                ('a/b/d/i',), ('a/b/d/i/j',),
604
                ])
605
        revtree1, revtree2 = self.assertChanges(branch, 2,
606
            expected_removed=[
607
                ('a/b',), ('a/b/c',),
608
                ('a/b/d',), ('a/b/d/e',),
609
                ('a/f',), ('a/f/g',),
610
                ('a/b/d/i',), ('a/b/d/i/j',),
611
                ])
612
0.99.13 by Ian Clatworthy
Handle delete then add of a file/symlink in the one commit
613
class TestImportToPackDeleteThenAdd(TestCaseForGenericProcessor):
614
    """Test delete followed by an add. Merges can cause this."""
615
616
    def file_command_iter(self, path, kind='file', content='aaa',
617
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
618
        # Revno 1: create a file or symlink
619
        # Revno 2: delete it and add it
620
        if to_kind is None:
621
            to_kind = kind
622
        if to_executable is None:
623
            to_executable = executable
624
        def command_list():
625
            author = ['', 'bugs@a.com', time.time(), time.timezone]
626
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
627
            def files_one():
628
                yield commands.FileModifyCommand(path, kind, executable,
629
                        None, content)
630
            yield commands.CommitCommand('head', '1', author,
631
                committer, "commit 1", None, [], files_one)
632
            def files_two():
633
                yield commands.FileDeleteCommand(path)
634
                yield commands.FileModifyCommand(path, to_kind, to_executable,
635
                        None, to_content)
636
            yield commands.CommitCommand('head', '2', author,
637
                committer, "commit 2", ":1", [], files_two)
638
        return command_list
639
640
    def test_delete_then_add_file_in_root(self):
641
        handler, branch = self.get_handler()
642
        path = 'a'
643
        handler.process(self.file_command_iter(path))
644
        revtree0, revtree1 = self.assertChanges(branch, 1,
645
            expected_added=[(path,)])
646
        revtree1, revtree2 = self.assertChanges(branch, 2,
647
            expected_removed=[(path,)],
648
            expected_added=[(path,)])
649
        self.assertContent(branch, revtree1, path, "aaa")
650
        self.assertContent(branch, revtree2, path, "bbb")
651
        self.assertRevisionRoot(revtree1, path)
652
        self.assertRevisionRoot(revtree2, path)
653
654
    def test_delete_then_add_file_in_subdir(self):
655
        handler, branch = self.get_handler()
656
        path = 'a/a'
657
        handler.process(self.file_command_iter(path))
658
        revtree0, revtree1 = self.assertChanges(branch, 1,
659
            expected_added=[('a',), (path,)])
660
        revtree1, revtree2 = self.assertChanges(branch, 2,
661
            expected_removed=[(path,)],
662
            expected_added=[(path,)])
663
        self.assertContent(branch, revtree1, path, "aaa")
664
        self.assertContent(branch, revtree2, path, "bbb")
665
666
    def test_delete_then_add_symlink_in_root(self):
667
        handler, branch = self.get_handler()
668
        path = 'a'
669
        handler.process(self.file_command_iter(path, kind='symlink'))
670
        revtree1, revtree2 = self.assertChanges(branch, 2,
671
            expected_removed=[(path,)],
672
            expected_added=[(path,)])
673
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
674
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
675
        self.assertRevisionRoot(revtree1, path)
676
        self.assertRevisionRoot(revtree2, path)
677
678
    def test_delete_then_add_symlink_in_subdir(self):
679
        handler, branch = self.get_handler()
680
        path = 'a/a'
681
        handler.process(self.file_command_iter(path, kind='symlink'))
682
        revtree0, revtree1 = self.assertChanges(branch, 1,
683
            expected_added=[('a',), (path,)])
684
        revtree1, revtree2 = self.assertChanges(branch, 2,
685
            expected_removed=[(path,)],
686
            expected_added=[(path,)])
687
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
688
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
689
690
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
691
class TestImportToPackDeleteDirectory(TestCaseForGenericProcessor):
0.80.7 by Ian Clatworthy
add directory delete test
692
693
    def file_command_iter(self, paths, dir):
694
        # Revno 1: create multiple files
695
        # Revno 2: delete a directory holding those files
696
        def command_list():
697
            author = ['', 'bugs@a.com', time.time(), time.timezone]
698
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
699
            def files_one():
700
                for i, path in enumerate(paths):
701
                    yield commands.FileModifyCommand(path, 'file', False,
702
                            None, "aaa%d" % i)
703
            yield commands.CommitCommand('head', '1', author,
704
                committer, "commit 1", None, [], files_one)
705
            def files_two():
706
                yield commands.FileDeleteCommand(dir)
707
            yield commands.CommitCommand('head', '2', author,
708
                committer, "commit 2", ":1", [], files_two)
709
        return command_list
710
711
    def test_delete_dir(self):
712
        handler, branch = self.get_handler()
713
        paths = ['a/b/c', 'a/b/d', 'a/b/e/f', 'a/g']
714
        dir = 'a/b'
715
        handler.process(self.file_command_iter(paths, dir))
716
        revtree0, revtree1 = self.assertChanges(branch, 1,
717
            expected_added=[
718
                ('a',), ('a/b',), ('a/b/c',),
719
                ('a/b/d',),
720
                ('a/b/e',), ('a/b/e/f',),
721
                ('a/g',),
722
                ])
723
        revtree1, revtree2 = self.assertChanges(branch, 2,
724
            expected_removed=[
725
                ('a/b',), ('a/b/c',),
726
                ('a/b/d',),
727
                ('a/b/e',), ('a/b/e/f',),
728
                ])
729
730
0.99.21 by Ian Clatworthy
Handle deleting a directory then adding a file within it in the same commit
731
class TestImportToPackDeleteDirectoryThenAddFile(TestCaseForGenericProcessor):
732
    """Test deleting a directory then adding a file in the same commit."""
733
734
    def file_command_iter(self, paths, dir, new_path, kind='file'):
735
        # Revno 1: create files in a directory
736
        # Revno 2: delete the directory then add a file into it
737
        def command_list():
738
            author = ['', 'bugs@a.com', time.time(), time.timezone]
739
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
740
            def files_one():
741
                for i, path in enumerate(paths):
742
                    yield commands.FileModifyCommand(path, kind, False,
743
                            None, "aaa%d" % i)
744
            yield commands.CommitCommand('head', '1', author,
745
                committer, "commit 1", None, [], files_one)
746
            def files_two():
747
                yield commands.FileDeleteCommand(dir)
748
                yield commands.FileModifyCommand(new_path, kind, False,
749
                        None, "bbb")
750
            yield commands.CommitCommand('head', '2', author,
751
                committer, "commit 2", ":1", [], files_two)
752
        return command_list
753
754
    def test_delete_dir_then_add_file(self):
755
        handler, branch = self.get_handler()
756
        paths = ['a/b/c', 'a/b/d']
757
        dir = 'a/b'
758
        new_path = 'a/b/z'
759
        handler.process(self.file_command_iter(paths, dir, new_path))
760
        revtree0, revtree1 = self.assertChanges(branch, 1,
761
            expected_added=[('a',), ('a/b',), ('a/b/c',), ('a/b/d',),])
762
        revtree1, revtree2 = self.assertChanges(branch, 2,
763
            expected_removed=[('a/b',), ('a/b/c',), ('a/b/d',)],
764
            expected_added=[('a/b',), ('a/b/z',)])
765
        self.assertContent(branch, revtree2, new_path, "bbb")
766
767
    def test_delete_dir_then_add_symlink(self):
768
        handler, branch = self.get_handler()
769
        paths = ['a/b/c', 'a/b/d']
770
        dir = 'a/b'
771
        new_path = 'a/b/z'
772
        handler.process(self.file_command_iter(paths, dir, new_path, 'symlink'))
773
        revtree0, revtree1 = self.assertChanges(branch, 1,
774
            expected_added=[('a',), ('a/b',), ('a/b/c',), ('a/b/d',),])
775
        revtree1, revtree2 = self.assertChanges(branch, 2,
776
            expected_removed=[('a/b',), ('a/b/c',), ('a/b/d',)],
777
            expected_added=[('a/b',), ('a/b/z',)])
778
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
779
780
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
781
class TestImportToPackRename(TestCaseForGenericProcessor):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
782
0.99.16 by Ian Clatworthy
add tests for symlink renaming
783
    def get_command_iter(self, old_path, new_path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
784
        # Revno 1: create a file or symlink
785
        # Revno 2: rename it
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
786
        def command_list():
787
            author = ['', 'bugs@a.com', time.time(), time.timezone]
788
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
789
            def files_one():
0.99.16 by Ian Clatworthy
add tests for symlink renaming
790
                yield commands.FileModifyCommand(old_path, kind, False,
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
791
                        None, "aaa")
792
            yield commands.CommitCommand('head', '1', author,
793
                committer, "commit 1", None, [], files_one)
794
            def files_two():
795
                yield commands.FileRenameCommand(old_path, new_path)
796
            yield commands.CommitCommand('head', '2', author,
797
                committer, "commit 2", ":1", [], files_two)
798
        return command_list
799
0.99.16 by Ian Clatworthy
add tests for symlink renaming
800
    def test_rename_file_in_root(self):
801
        handler, branch = self.get_handler()
802
        old_path = 'a'
803
        new_path = 'b'
804
        handler.process(self.get_command_iter(old_path, new_path))
805
        revtree1, revtree2 = self.assertChanges(branch, 2,
806
            expected_renamed=[(old_path, new_path)])
807
        self.assertRevisionRoot(revtree1, old_path)
808
        self.assertRevisionRoot(revtree2, new_path)
809
810
    def test_rename_symlink_in_root(self):
811
        handler, branch = self.get_handler()
812
        old_path = 'a'
813
        new_path = 'b'
814
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
815
        revtree1, revtree2 = self.assertChanges(branch, 2,
816
            expected_renamed=[(old_path, new_path)])
817
        self.assertRevisionRoot(revtree1, old_path)
818
        self.assertRevisionRoot(revtree2, new_path)
819
820
    def test_rename_file_in_subdir(self):
821
        handler, branch = self.get_handler()
822
        old_path = 'a/a'
823
        new_path = 'a/b'
824
        handler.process(self.get_command_iter(old_path, new_path))
825
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
826
827
    def test_rename_symlink_in_subdir(self):
828
        handler, branch = self.get_handler()
829
        old_path = 'a/a'
830
        new_path = 'a/b'
831
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
832
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
833
834
    def test_rename_file_to_new_dir(self):
835
        handler, branch = self.get_handler()
836
        old_path = 'a/a'
837
        new_path = 'b/a'
838
        handler.process(self.get_command_iter(old_path, new_path))
839
        self.assertChanges(branch, 2,
840
            expected_renamed=[(old_path, new_path)],
841
            expected_added=[('b',)],
842
            expected_removed=[('a',)])
843
844
    def test_rename_symlink_to_new_dir(self):
845
        handler, branch = self.get_handler()
846
        old_path = 'a/a'
847
        new_path = 'b/a'
848
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
849
        self.assertChanges(branch, 2,
850
            expected_renamed=[(old_path, new_path)],
851
            expected_added=[('b',)],
852
            expected_removed=[('a',)])
0.64.74 by Ian Clatworthy
fix symlink importing
853
854
0.99.6 by Ian Clatworthy
Handle rename of a just added file
855
class TestImportToPackRenameNew(TestCaseForGenericProcessor):
0.99.8 by Ian Clatworthy
handle copy of a newly added file
856
    """Test rename of a newly added file."""
0.99.6 by Ian Clatworthy
Handle rename of a just added file
857
0.99.16 by Ian Clatworthy
add tests for symlink renaming
858
    def get_command_iter(self, old_path, new_path, kind='file'):
0.99.6 by Ian Clatworthy
Handle rename of a just added file
859
        # Revno 1: create a file and rename it
860
        def command_list():
861
            author = ['', 'bugs@a.com', time.time(), time.timezone]
862
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
863
            def files_one():
0.99.16 by Ian Clatworthy
add tests for symlink renaming
864
                yield commands.FileModifyCommand(old_path, kind, False,
0.99.6 by Ian Clatworthy
Handle rename of a just added file
865
                        None, "aaa")
866
                yield commands.FileRenameCommand(old_path, new_path)
867
            yield commands.CommitCommand('head', '1', author,
868
                committer, "commit 1", None, [], files_one)
869
        return command_list
870
0.99.16 by Ian Clatworthy
add tests for symlink renaming
871
    def test_rename_new_file_in_root(self):
872
        handler, branch = self.get_handler()
873
        old_path = 'a'
874
        new_path = 'b'
875
        handler.process(self.get_command_iter(old_path, new_path))
876
        revtree0, revtree1 = self.assertChanges(branch, 1,
877
            expected_added=[(new_path,)])
878
        self.assertRevisionRoot(revtree1, new_path)
879
880
    def test_rename_new_symlink_in_root(self):
881
        handler, branch = self.get_handler()
882
        old_path = 'a'
883
        new_path = 'b'
884
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
885
        revtree0, revtree1 = self.assertChanges(branch, 1,
886
            expected_added=[(new_path,)])
887
        self.assertRevisionRoot(revtree1, new_path)
888
889
    def test_rename_new_file_in_subdir(self):
890
        handler, branch = self.get_handler()
891
        old_path = 'a/a'
892
        new_path = 'a/b'
893
        handler.process(self.get_command_iter(old_path, new_path))
894
        revtree0, revtree1 = self.assertChanges(branch, 1,
895
            expected_added=[('a',), (new_path,)])
896
897
    def test_rename_new_symlink_in_subdir(self):
898
        handler, branch = self.get_handler()
899
        old_path = 'a/a'
900
        new_path = 'a/b'
901
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
0.99.6 by Ian Clatworthy
Handle rename of a just added file
902
        revtree0, revtree1 = self.assertChanges(branch, 1,
903
            expected_added=[('a',), (new_path,)])
904
905
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
906
class TestImportToPackRenameToDeleted(TestCaseForGenericProcessor):
907
    """Test rename to a destination path deleted in this commit."""
908
0.99.16 by Ian Clatworthy
add tests for symlink renaming
909
    def get_command_iter(self, old_path, new_path, kind='file'):
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
910
        # Revno 1: create two files
911
        # Revno 2: delete one, rename the other one to that path
912
        def command_list():
913
            author = ['', 'bugs@a.com', time.time(), time.timezone]
914
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
915
            def files_one():
0.99.16 by Ian Clatworthy
add tests for symlink renaming
916
                yield commands.FileModifyCommand(old_path, kind, False,
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
917
                        None, "aaa")
0.99.16 by Ian Clatworthy
add tests for symlink renaming
918
                yield commands.FileModifyCommand(new_path, kind, False,
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
919
                        None, "bbb")
920
            yield commands.CommitCommand('head', '1', author,
921
                committer, "commit 1", None, [], files_one)
922
            def files_two():
923
                yield commands.FileDeleteCommand(new_path)
924
                yield commands.FileRenameCommand(old_path, new_path)
925
            yield commands.CommitCommand('head', '2', author,
926
                committer, "commit 2", ":1", [], files_two)
927
        return command_list
928
0.99.16 by Ian Clatworthy
add tests for symlink renaming
929
    def test_rename_to_deleted_file_in_root(self):
930
        handler, branch = self.get_handler()
931
        old_path = 'a'
932
        new_path = 'b'
933
        handler.process(self.get_command_iter(old_path, new_path))
934
        revtree0, revtree1 = self.assertChanges(branch, 1,
935
            expected_added=[(old_path,), (new_path,)])
936
        revtree1, revtree2 = self.assertChanges(branch, 2,
937
            expected_removed=[(new_path,)],
938
            expected_renamed=[(old_path, new_path)])
939
        self.assertContent(branch, revtree1, old_path, "aaa")
940
        self.assertContent(branch, revtree1, new_path, "bbb")
941
        self.assertContent(branch, revtree2, new_path, "aaa")
942
        self.assertRevisionRoot(revtree1, old_path)
943
        self.assertRevisionRoot(revtree1, new_path)
944
945
    def test_rename_to_deleted_symlink_in_root(self):
946
        handler, branch = self.get_handler()
947
        old_path = 'a'
948
        new_path = 'b'
949
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
950
        revtree0, revtree1 = self.assertChanges(branch, 1,
951
            expected_added=[(old_path,), (new_path,)])
952
        revtree1, revtree2 = self.assertChanges(branch, 2,
953
            expected_removed=[(new_path,)],
954
            expected_renamed=[(old_path, new_path)])
955
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
956
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
957
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
958
        self.assertRevisionRoot(revtree1, old_path)
959
        self.assertRevisionRoot(revtree1, new_path)
960
961
    def test_rename_to_deleted_file_in_subdir(self):
962
        handler, branch = self.get_handler()
963
        old_path = 'd/a'
964
        new_path = 'd/b'
965
        handler.process(self.get_command_iter(old_path, new_path))
966
        revtree0, revtree1 = self.assertChanges(branch, 1,
967
            expected_added=[('d',), (old_path,), (new_path,)])
968
        revtree1, revtree2 = self.assertChanges(branch, 2,
969
            expected_removed=[(new_path,)],
970
            expected_renamed=[(old_path, new_path)])
971
        self.assertContent(branch, revtree1, old_path, "aaa")
972
        self.assertContent(branch, revtree1, new_path, "bbb")
973
        self.assertContent(branch, revtree2, new_path, "aaa")
974
975
    def test_rename_to_deleted_symlink_in_subdir(self):
976
        handler, branch = self.get_handler()
977
        old_path = 'd/a'
978
        new_path = 'd/b'
979
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
980
        revtree0, revtree1 = self.assertChanges(branch, 1,
981
            expected_added=[('d',), (old_path,), (new_path,)])
982
        revtree1, revtree2 = self.assertChanges(branch, 2,
983
            expected_removed=[(new_path,)],
984
            expected_renamed=[(old_path, new_path)])
985
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
986
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
987
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
988
989
    def test_rename_to_deleted_file_in_new_dir(self):
990
        handler, branch = self.get_handler()
991
        old_path = 'd1/a'
992
        new_path = 'd2/b'
993
        handler.process(self.get_command_iter(old_path, new_path))
994
        revtree0, revtree1 = self.assertChanges(branch, 1,
995
            expected_added=[('d1',), (old_path,), ('d2',), (new_path,)])
996
        revtree1, revtree2 = self.assertChanges(branch, 2,
997
            expected_removed=[('d1',), (new_path,)],
998
            expected_renamed=[(old_path, new_path)])
999
        self.assertContent(branch, revtree1, old_path, "aaa")
1000
        self.assertContent(branch, revtree1, new_path, "bbb")
1001
        self.assertContent(branch, revtree2, new_path, "aaa")
1002
1003
    def test_rename_to_deleted_symlink_in_new_dir(self):
1004
        handler, branch = self.get_handler()
1005
        old_path = 'd1/a'
1006
        new_path = 'd2/b'
1007
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1008
        revtree0, revtree1 = self.assertChanges(branch, 1,
1009
            expected_added=[('d1',), (old_path,), ('d2',), (new_path,)])
1010
        revtree1, revtree2 = self.assertChanges(branch, 2,
1011
            expected_removed=[('d1',), (new_path,)],
1012
            expected_renamed=[(old_path, new_path)])
1013
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1014
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
1015
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
1016
1017
0.99.17 by Ian Clatworthy
Handle rename of a file/symlink modified already in this commit
1018
class TestImportToPackRenameModified(TestCaseForGenericProcessor):
1019
    """Test rename of a path previously modified in this commit."""
1020
1021
    def get_command_iter(self, old_path, new_path, kind='file'):
1022
        # Revno 1: create a file or symlink
1023
        # Revno 2: modify then rename it
1024
        def command_list():
1025
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1026
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1027
            def files_one():
1028
                yield commands.FileModifyCommand(old_path, kind, False,
1029
                        None, "aaa")
1030
            yield commands.CommitCommand('head', '1', author,
1031
                committer, "commit 1", None, [], files_one)
1032
            def files_two():
1033
                yield commands.FileModifyCommand(old_path, kind, False,
1034
                        None, "bbb")
1035
                yield commands.FileRenameCommand(old_path, new_path)
1036
            yield commands.CommitCommand('head', '2', author,
1037
                committer, "commit 2", ":1", [], files_two)
1038
        return command_list
1039
1040
    def test_rename_of_modified_file_in_root(self):
1041
        handler, branch = self.get_handler()
1042
        old_path = 'a'
1043
        new_path = 'b'
1044
        handler.process(self.get_command_iter(old_path, new_path))
1045
        revtree0, revtree1 = self.assertChanges(branch, 1,
1046
            expected_added=[(old_path,)])
1047
        # Note: the delta doesn't show the modification?
1048
        # The actual new content is validated in the assertions following.
1049
        revtree1, revtree2 = self.assertChanges(branch, 2,
1050
            expected_renamed=[(old_path, new_path)])
1051
        self.assertContent(branch, revtree1, old_path, "aaa")
1052
        self.assertContent(branch, revtree2, new_path, "bbb")
1053
        self.assertRevisionRoot(revtree1, old_path)
1054
        self.assertRevisionRoot(revtree2, new_path)
1055
1056
    def test_rename_of_modified_symlink_in_root(self):
1057
        handler, branch = self.get_handler()
1058
        old_path = 'a'
1059
        new_path = 'b'
1060
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1061
        revtree0, revtree1 = self.assertChanges(branch, 1,
1062
            expected_added=[(old_path,)])
1063
        # Note: the delta doesn't show the modification?
1064
        # The actual new content is validated in the assertions following.
1065
        revtree1, revtree2 = self.assertChanges(branch, 2,
1066
            expected_renamed=[(old_path, new_path)])
1067
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1068
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1069
        self.assertRevisionRoot(revtree1, old_path)
1070
        self.assertRevisionRoot(revtree2, new_path)
1071
1072
    def test_rename_of_modified_file_in_subdir(self):
1073
        handler, branch = self.get_handler()
1074
        old_path = 'd/a'
1075
        new_path = 'd/b'
1076
        handler.process(self.get_command_iter(old_path, new_path))
1077
        revtree0, revtree1 = self.assertChanges(branch, 1,
1078
            expected_added=[('d',), (old_path,)])
1079
        # Note: the delta doesn't show the modification?
1080
        # The actual new content is validated in the assertions following.
1081
        revtree1, revtree2 = self.assertChanges(branch, 2,
1082
            expected_renamed=[(old_path, new_path)])
1083
        self.assertContent(branch, revtree1, old_path, "aaa")
1084
        self.assertContent(branch, revtree2, new_path, "bbb")
1085
1086
    def test_rename_of_modified_symlink_in_subdir(self):
1087
        handler, branch = self.get_handler()
1088
        old_path = 'd/a'
1089
        new_path = 'd/b'
1090
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1091
        revtree0, revtree1 = self.assertChanges(branch, 1,
1092
            expected_added=[('d',), (old_path,)])
1093
        # Note: the delta doesn't show the modification?
1094
        # The actual new content is validated in the assertions following.
1095
        revtree1, revtree2 = self.assertChanges(branch, 2,
1096
            expected_renamed=[(old_path, new_path)])
1097
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1098
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1099
1100
    def test_rename_of_modified_file_to_new_dir(self):
1101
        handler, branch = self.get_handler()
1102
        old_path = 'd1/a'
1103
        new_path = 'd2/b'
1104
        handler.process(self.get_command_iter(old_path, new_path))
1105
        revtree0, revtree1 = self.assertChanges(branch, 1,
1106
            expected_added=[('d1',), (old_path,)])
1107
        # Note: the delta doesn't show the modification?
1108
        # The actual new content is validated in the assertions following.
1109
        revtree1, revtree2 = self.assertChanges(branch, 2,
1110
            expected_renamed=[(old_path, new_path)],
1111
            expected_added=[('d2',)],
1112
            expected_removed=[('d1',)])
1113
        self.assertContent(branch, revtree1, old_path, "aaa")
1114
        self.assertContent(branch, revtree2, new_path, "bbb")
1115
1116
    def test_rename_of_modified_symlink_to_new_dir(self):
1117
        handler, branch = self.get_handler()
1118
        old_path = 'd1/a'
1119
        new_path = 'd2/b'
1120
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1121
        revtree0, revtree1 = self.assertChanges(branch, 1,
1122
            expected_added=[('d1',), (old_path,)])
1123
        # Note: the delta doesn't show the modification?
1124
        # The actual new content is validated in the assertions following.
1125
        revtree1, revtree2 = self.assertChanges(branch, 2,
1126
            expected_renamed=[(old_path, new_path)],
1127
            expected_added=[('d2',)],
1128
            expected_removed=[('d1',)])
1129
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1130
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1131
1132
0.99.19 by Ian Clatworthy
Handle rename then modification of the new path
1133
class TestImportToPackRenameThenModify(TestCaseForGenericProcessor):
1134
    """Test rename of a path then modfy the new-path in the same commit."""
1135
1136
    def get_command_iter(self, old_path, new_path, kind='file'):
1137
        # Revno 1: create a file or symlink
1138
        # Revno 2: rename it then modify the newly created path
1139
        def command_list():
1140
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1141
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1142
            def files_one():
1143
                yield commands.FileModifyCommand(old_path, kind, False,
1144
                        None, "aaa")
1145
            yield commands.CommitCommand('head', '1', author,
1146
                committer, "commit 1", None, [], files_one)
1147
            def files_two():
1148
                yield commands.FileRenameCommand(old_path, new_path)
1149
                yield commands.FileModifyCommand(new_path, kind, False,
1150
                        None, "bbb")
1151
            yield commands.CommitCommand('head', '2', author,
1152
                committer, "commit 2", ":1", [], files_two)
1153
        return command_list
1154
1155
    def test_rename_then_modify_file_in_root(self):
1156
        handler, branch = self.get_handler()
1157
        old_path = 'a'
1158
        new_path = 'b'
1159
        handler.process(self.get_command_iter(old_path, new_path))
1160
        revtree0, revtree1 = self.assertChanges(branch, 1,
1161
            expected_added=[(old_path,)])
1162
        # Note: the delta doesn't show the modification?
1163
        # The actual new content is validated in the assertions following.
1164
        revtree1, revtree2 = self.assertChanges(branch, 2,
1165
            expected_renamed=[(old_path, new_path)])
1166
        self.assertContent(branch, revtree1, old_path, "aaa")
1167
        self.assertContent(branch, revtree2, new_path, "bbb")
1168
        self.assertRevisionRoot(revtree1, old_path)
1169
        self.assertRevisionRoot(revtree2, new_path)
1170
1171
    def test_rename_then_modify_file_in_subdir(self):
1172
        handler, branch = self.get_handler()
1173
        old_path = 'd/a'
1174
        new_path = 'd/b'
1175
        handler.process(self.get_command_iter(old_path, new_path))
1176
        revtree0, revtree1 = self.assertChanges(branch, 1,
1177
            expected_added=[('d',), (old_path,)])
1178
        # Note: the delta doesn't show the modification?
1179
        # The actual new content is validated in the assertions following.
1180
        revtree1, revtree2 = self.assertChanges(branch, 2,
1181
            expected_renamed=[(old_path, new_path)])
1182
        self.assertContent(branch, revtree1, old_path, "aaa")
1183
        self.assertContent(branch, revtree2, new_path, "bbb")
1184
1185
    def test_rename_then_modify_file_in_new_dir(self):
1186
        handler, branch = self.get_handler()
1187
        old_path = 'd1/a'
1188
        new_path = 'd2/b'
1189
        handler.process(self.get_command_iter(old_path, new_path))
1190
        revtree0, revtree1 = self.assertChanges(branch, 1,
1191
            expected_added=[('d1',), (old_path,)])
1192
        # Note: the delta doesn't show the modification?
1193
        # The actual new content is validated in the assertions following.
1194
        revtree1, revtree2 = self.assertChanges(branch, 2,
1195
            expected_renamed=[(old_path, new_path)],
1196
            expected_added=[('d2',)],
1197
            expected_removed=[('d1',)])
1198
        self.assertContent(branch, revtree1, old_path, "aaa")
1199
        self.assertContent(branch, revtree2, new_path, "bbb")
1200
1201
    def test_rename_then_modify_symlink_in_root(self):
1202
        handler, branch = self.get_handler()
1203
        old_path = 'a'
1204
        new_path = 'b'
1205
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1206
        revtree0, revtree1 = self.assertChanges(branch, 1,
1207
            expected_added=[(old_path,)])
1208
        # Note: the delta doesn't show the modification?
1209
        # The actual new content is validated in the assertions following.
1210
        revtree1, revtree2 = self.assertChanges(branch, 2,
1211
            expected_renamed=[(old_path, new_path)])
1212
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1213
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1214
        self.assertRevisionRoot(revtree1, old_path)
1215
        self.assertRevisionRoot(revtree2, new_path)
1216
1217
    def test_rename_then_modify_symlink_in_subdir(self):
1218
        handler, branch = self.get_handler()
1219
        old_path = 'd/a'
1220
        new_path = 'd/b'
1221
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1222
        revtree0, revtree1 = self.assertChanges(branch, 1,
1223
            expected_added=[('d',), (old_path,)])
1224
        # Note: the delta doesn't show the modification?
1225
        # The actual new content is validated in the assertions following.
1226
        revtree1, revtree2 = self.assertChanges(branch, 2,
1227
            expected_renamed=[(old_path, new_path)])
1228
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1229
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1230
1231
    def test_rename_then_modify_symlink_in_new_dir(self):
1232
        handler, branch = self.get_handler()
1233
        old_path = 'd1/a'
1234
        new_path = 'd2/b'
1235
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1236
        revtree0, revtree1 = self.assertChanges(branch, 1,
1237
            expected_added=[('d1',), (old_path,)])
1238
        # Note: the delta doesn't show the modification?
1239
        # The actual new content is validated in the assertions following.
1240
        revtree1, revtree2 = self.assertChanges(branch, 2,
1241
            expected_renamed=[(old_path, new_path)],
1242
            expected_added=[('d2',)],
1243
            expected_removed=[('d1',)])
1244
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1245
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1246
1247
0.64.233 by Ian Clatworthy
Handle delete, rename then modify all in the one commit
1248
class TestImportToPackDeleteRenameThenModify(TestCaseForGenericProcessor):
1249
    """Test rename of to a deleted path then modfy the new-path in the same commit."""
1250
1251
    def get_command_iter(self, old_path, new_path, kind='file'):
1252
        # Revno 1: create two files or symlinks
1253
        # Revno 2: delete one, rename the other to it then modify the newly created path
1254
        def command_list():
1255
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1256
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1257
            def files_one():
1258
                yield commands.FileModifyCommand(old_path, kind, False,
1259
                        None, "aaa")
1260
                yield commands.FileModifyCommand(new_path, kind, False,
1261
                        None, "zzz")
1262
            yield commands.CommitCommand('head', '1', author,
1263
                committer, "commit 1", None, [], files_one)
1264
            def files_two():
1265
                yield commands.FileDeleteCommand(new_path)
1266
                yield commands.FileRenameCommand(old_path, new_path)
1267
                yield commands.FileModifyCommand(new_path, kind, False,
1268
                        None, "bbb")
1269
            yield commands.CommitCommand('head', '2', author,
1270
                committer, "commit 2", ":1", [], files_two)
1271
        return command_list
1272
1273
    def test_delete_rename_then_modify_file_in_root(self):
1274
        handler, branch = self.get_handler()
1275
        old_path = 'a'
1276
        new_path = 'b'
1277
        handler.process(self.get_command_iter(old_path, new_path))
1278
        revtree0, revtree1 = self.assertChanges(branch, 1,
1279
            expected_added=[(old_path,), (new_path,)])
1280
        # Note: the delta doesn't show the modification?
1281
        # The actual new content is validated in the assertions following.
1282
        revtree1, revtree2 = self.assertChanges(branch, 2,
1283
            expected_removed=[(new_path,)],
1284
            expected_renamed=[(old_path, new_path)])
1285
        self.assertContent(branch, revtree1, old_path, "aaa")
1286
        self.assertContent(branch, revtree1, new_path, "zzz")
1287
        self.assertContent(branch, revtree2, new_path, "bbb")
1288
        self.assertRevisionRoot(revtree1, old_path)
1289
        self.assertRevisionRoot(revtree1, new_path)
1290
        self.assertRevisionRoot(revtree2, new_path)
1291
1292
    def test_delete_rename_then_modify_file_in_subdir(self):
1293
        handler, branch = self.get_handler()
1294
        old_path = 'd/a'
1295
        new_path = 'd/b'
1296
        handler.process(self.get_command_iter(old_path, new_path))
1297
        revtree0, revtree1 = self.assertChanges(branch, 1,
1298
            expected_added=[('d',), (old_path,), (new_path,)])
1299
        # Note: the delta doesn't show the modification?
1300
        # The actual new content is validated in the assertions following.
1301
        revtree1, revtree2 = self.assertChanges(branch, 2,
1302
            expected_removed=[(new_path,)],
1303
            expected_renamed=[(old_path, new_path)])
1304
        self.assertContent(branch, revtree1, old_path, "aaa")
1305
        self.assertContent(branch, revtree1, new_path, "zzz")
1306
        self.assertContent(branch, revtree2, new_path, "bbb")
1307
1308
    def test_delete_rename_then_modify_file_in_new_dir(self):
1309
        handler, branch = self.get_handler()
1310
        old_path = 'd1/a'
1311
        new_path = 'd2/b'
1312
        handler.process(self.get_command_iter(old_path, new_path))
1313
        revtree0, revtree1 = self.assertChanges(branch, 1,
1314
            expected_added=[('d1',), ('d2',), (old_path,), (new_path,)])
1315
        # Note: the delta doesn't show the modification?
1316
        # The actual new content is validated in the assertions following.
1317
        revtree1, revtree2 = self.assertChanges(branch, 2,
1318
            expected_removed=[('d1',), (new_path,)],
1319
            expected_renamed=[(old_path, new_path)])
1320
        self.assertContent(branch, revtree1, old_path, "aaa")
1321
        self.assertContent(branch, revtree1, new_path, "zzz")
1322
        self.assertContent(branch, revtree2, new_path, "bbb")
1323
1324
    def test_delete_rename_then_modify_symlink_in_root(self):
1325
        handler, branch = self.get_handler()
1326
        old_path = 'a'
1327
        new_path = 'b'
1328
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1329
        revtree0, revtree1 = self.assertChanges(branch, 1,
1330
            expected_added=[(old_path,), (new_path,)])
1331
        # Note: the delta doesn't show the modification?
1332
        # The actual new content is validated in the assertions following.
1333
        revtree1, revtree2 = self.assertChanges(branch, 2,
1334
            expected_removed=[(new_path,)],
1335
            expected_renamed=[(old_path, new_path)])
1336
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1337
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1338
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1339
        self.assertRevisionRoot(revtree1, old_path)
1340
        self.assertRevisionRoot(revtree1, new_path)
1341
        self.assertRevisionRoot(revtree2, new_path)
1342
1343
    def test_delete_rename_then_modify_symlink_in_subdir(self):
1344
        handler, branch = self.get_handler()
1345
        old_path = 'd/a'
1346
        new_path = 'd/b'
1347
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1348
        revtree0, revtree1 = self.assertChanges(branch, 1,
1349
            expected_added=[('d',), (old_path,), (new_path,)])
1350
        # Note: the delta doesn't show the modification?
1351
        # The actual new content is validated in the assertions following.
1352
        revtree1, revtree2 = self.assertChanges(branch, 2,
1353
            expected_removed=[(new_path,)],
1354
            expected_renamed=[(old_path, new_path)])
1355
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1356
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1357
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1358
1359
    def test_delete_rename_then_modify_symlink_in_new_dir(self):
1360
        handler, branch = self.get_handler()
1361
        old_path = 'd1/a'
1362
        new_path = 'd2/b'
1363
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1364
        revtree0, revtree1 = self.assertChanges(branch, 1,
1365
            expected_added=[('d1',), ('d2',), (old_path,), (new_path,)])
1366
        # Note: the delta doesn't show the modification?
1367
        # The actual new content is validated in the assertions following.
1368
        revtree1, revtree2 = self.assertChanges(branch, 2,
1369
            expected_removed=[('d1',), (new_path,)],
1370
            expected_renamed=[(old_path, new_path)])
1371
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1372
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1373
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1374
1375
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1376
class TestImportToPackRenameTricky(TestCaseForGenericProcessor):
0.80.6 by Ian Clatworthy
file/symlink <-> directory rename tests
1377
1378
    def file_command_iter(self, path1, old_path2, new_path2, kind='file'):
1379
        # Revno 1: create two files or symlinks in a directory
1380
        # Revno 2: rename the second file so that it implicitly deletes the
1381
        # first one because either:
1382
        # * the new file is a in directory with the old file name
1383
        # * the new file has the same name as the directory of the first
1384
        def command_list():
1385
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1386
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1387
            def files_one():
1388
                yield commands.FileModifyCommand(path1, kind, False,
1389
                        None, "aaa")
1390
                yield commands.FileModifyCommand(old_path2, kind, False,
1391
                        None, "bbb")
1392
            yield commands.CommitCommand('head', '1', author,
1393
                committer, "commit 1", None, [], files_one)
1394
            def files_two():
1395
                yield commands.FileRenameCommand(old_path2, new_path2)
1396
            yield commands.CommitCommand('head', '2', author,
1397
                committer, "commit 2", ":1", [], files_two)
1398
        return command_list
1399
1400
    def test_rename_file_becomes_directory(self):
1401
        handler, branch = self.get_handler()
1402
        old_path2 = 'foo'
1403
        path1     = 'a/b'
1404
        new_path2 = 'a/b/c'
1405
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
1406
        revtree0, revtree1 = self.assertChanges(branch, 1,
1407
            expected_added=[('a',), (path1,), (old_path2,)])
1408
        revtree1, revtree2 = self.assertChanges(branch, 2,
1409
            expected_renamed=[(old_path2, new_path2)],
1410
            expected_kind_changed=[(path1, 'file', 'directory')])
1411
        self.assertContent(branch, revtree1, path1, "aaa")
1412
        self.assertContent(branch, revtree2, new_path2, "bbb")
1413
1414
    def test_rename_directory_becomes_file(self):
1415
        handler, branch = self.get_handler()
1416
        old_path2 = 'foo'
1417
        path1     = 'a/b/c'
1418
        new_path2 = 'a/b'
1419
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
1420
        revtree0, revtree1 = self.assertChanges(branch, 1,
1421
            expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
1422
        revtree1, revtree2 = self.assertChanges(branch, 2,
1423
            expected_renamed=[(old_path2, new_path2)],
1424
            expected_removed=[(path1,), (new_path2,)])
1425
        self.assertContent(branch, revtree1, path1, "aaa")
1426
        self.assertContent(branch, revtree2, new_path2, "bbb")
1427
1428
    def test_rename_symlink_becomes_directory(self):
1429
        handler, branch = self.get_handler()
1430
        old_path2 = 'foo'
1431
        path1     = 'a/b'
1432
        new_path2 = 'a/b/c'
1433
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
1434
            'symlink'))
1435
        revtree0, revtree1 = self.assertChanges(branch, 1,
1436
            expected_added=[('a',), (path1,), (old_path2,)])
1437
        revtree1, revtree2 = self.assertChanges(branch, 2,
1438
            expected_renamed=[(old_path2, new_path2)],
1439
            expected_kind_changed=[(path1, 'symlink', 'directory')])
1440
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
1441
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
1442
1443
    def test_rename_directory_becomes_symlink(self):
1444
        handler, branch = self.get_handler()
1445
        old_path2 = 'foo'
1446
        path1     = 'a/b/c'
1447
        new_path2 = 'a/b'
1448
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
1449
            'symlink'))
1450
        revtree0, revtree1 = self.assertChanges(branch, 1,
1451
            expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
1452
        revtree1, revtree2 = self.assertChanges(branch, 2,
1453
            expected_renamed=[(old_path2, new_path2)],
1454
            expected_removed=[(path1,), (new_path2,)])
1455
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
1456
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
1457
1458
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1459
class TestImportToPackCopy(TestCaseForGenericProcessor):
0.76.2 by Ian Clatworthy
code & tests for file copying
1460
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1461
    def file_command_iter(self, src_path, dest_path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
1462
        # Revno 1: create a file or symlink
1463
        # Revno 2: copy it
0.76.2 by Ian Clatworthy
code & tests for file copying
1464
        def command_list():
1465
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1466
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1467
            def files_one():
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1468
                yield commands.FileModifyCommand(src_path, kind, False,
0.76.2 by Ian Clatworthy
code & tests for file copying
1469
                        None, "aaa")
1470
            yield commands.CommitCommand('head', '1', author,
1471
                committer, "commit 1", None, [], files_one)
1472
            def files_two():
1473
                yield commands.FileCopyCommand(src_path, dest_path)
1474
            yield commands.CommitCommand('head', '2', author,
1475
                committer, "commit 2", ":1", [], files_two)
1476
        return command_list
1477
1478
    def test_copy_file_in_root(self):
1479
        handler, branch = self.get_handler()
1480
        src_path = 'a'
1481
        dest_path = 'b'
1482
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1483
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
1484
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1485
        self.assertContent(branch, revtree1, src_path, "aaa")
1486
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
1487
        self.assertContent(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1488
        self.assertRevisionRoot(revtree1, src_path)
1489
        self.assertRevisionRoot(revtree2, dest_path)
0.76.2 by Ian Clatworthy
code & tests for file copying
1490
1491
    def test_copy_file_in_subdir(self):
1492
        handler, branch = self.get_handler()
1493
        src_path = 'a/a'
1494
        dest_path = 'a/b'
1495
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1496
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
1497
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1498
        self.assertContent(branch, revtree1, src_path, "aaa")
1499
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
1500
        self.assertContent(branch, revtree2, dest_path, "aaa")
1501
1502
    def test_copy_file_to_new_dir(self):
1503
        handler, branch = self.get_handler()
1504
        src_path = 'a/a'
1505
        dest_path = 'b/a'
1506
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1507
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
1508
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1509
        self.assertContent(branch, revtree1, src_path, "aaa")
1510
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
1511
        self.assertContent(branch, revtree2, dest_path, "aaa")
1512
0.76.3 by Ian Clatworthy
symlink copying tests
1513
    def test_copy_symlink_in_root(self):
1514
        handler, branch = self.get_handler()
1515
        src_path = 'a'
1516
        dest_path = 'b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1517
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1518
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
1519
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1520
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1521
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
1522
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1523
        self.assertRevisionRoot(revtree1, src_path)
1524
        self.assertRevisionRoot(revtree2, dest_path)
0.76.3 by Ian Clatworthy
symlink copying tests
1525
1526
    def test_copy_symlink_in_subdir(self):
1527
        handler, branch = self.get_handler()
1528
        src_path = 'a/a'
1529
        dest_path = 'a/b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1530
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1531
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
1532
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1533
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1534
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
1535
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1536
1537
    def test_copy_symlink_to_new_dir(self):
1538
        handler, branch = self.get_handler()
1539
        src_path = 'a/a'
1540
        dest_path = 'b/a'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1541
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1542
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
1543
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1544
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1545
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
1546
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1547
0.76.2 by Ian Clatworthy
code & tests for file copying
1548
0.99.8 by Ian Clatworthy
handle copy of a newly added file
1549
class TestImportToPackCopyNew(TestCaseForGenericProcessor):
1550
    """Test copy of a newly added file."""
1551
1552
    def file_command_iter(self, src_path, dest_path, kind='file'):
1553
        # Revno 1: create a file or symlink and copy it
1554
        def command_list():
1555
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1556
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1557
            def files_one():
1558
                yield commands.FileModifyCommand(src_path, kind, False,
1559
                        None, "aaa")
1560
                yield commands.FileCopyCommand(src_path, dest_path)
1561
            yield commands.CommitCommand('head', '1', author,
1562
                committer, "commit 1", None, [], files_one)
1563
        return command_list
1564
1565
    def test_copy_new_file_in_root(self):
1566
        handler, branch = self.get_handler()
1567
        src_path = 'a'
1568
        dest_path = 'b'
1569
        handler.process(self.file_command_iter(src_path, dest_path))
1570
        revtree0, revtree1 = self.assertChanges(branch, 1,
1571
            expected_added=[(src_path,), (dest_path,)])
1572
        self.assertContent(branch, revtree1, src_path, "aaa")
1573
        self.assertContent(branch, revtree1, dest_path, "aaa")
1574
        self.assertRevisionRoot(revtree1, src_path)
1575
        self.assertRevisionRoot(revtree1, dest_path)
1576
1577
    def test_copy_new_file_in_subdir(self):
1578
        handler, branch = self.get_handler()
1579
        src_path = 'a/a'
1580
        dest_path = 'a/b'
1581
        handler.process(self.file_command_iter(src_path, dest_path))
1582
        revtree0, revtree1 = self.assertChanges(branch, 1,
1583
            expected_added=[('a',), (src_path,), (dest_path,)])
1584
        self.assertContent(branch, revtree1, src_path, "aaa")
1585
        self.assertContent(branch, revtree1, dest_path, "aaa")
1586
1587
    def test_copy_new_file_to_new_dir(self):
1588
        handler, branch = self.get_handler()
1589
        src_path = 'a/a'
1590
        dest_path = 'b/a'
1591
        handler.process(self.file_command_iter(src_path, dest_path))
1592
        revtree0, revtree1 = self.assertChanges(branch, 1,
1593
            expected_added=[('a',), (src_path,), ('b',), (dest_path,)])
1594
        self.assertContent(branch, revtree1, src_path, "aaa")
1595
        self.assertContent(branch, revtree1, dest_path, "aaa")
1596
1597
    def test_copy_new_symlink_in_root(self):
1598
        handler, branch = self.get_handler()
1599
        src_path = 'a'
1600
        dest_path = 'b'
1601
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1602
        revtree0, revtree1 = self.assertChanges(branch, 1,
1603
            expected_added=[(src_path,), (dest_path,)])
1604
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1605
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1606
        self.assertRevisionRoot(revtree1, src_path)
1607
        self.assertRevisionRoot(revtree1, dest_path)
1608
1609
    def test_copy_new_symlink_in_subdir(self):
1610
        handler, branch = self.get_handler()
1611
        src_path = 'a/a'
1612
        dest_path = 'a/b'
1613
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1614
        revtree0, revtree1 = self.assertChanges(branch, 1,
1615
            expected_added=[('a',), (src_path,), (dest_path,)])
1616
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1617
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1618
1619
    def test_copy_new_symlink_to_new_dir(self):
1620
        handler, branch = self.get_handler()
1621
        src_path = 'a/a'
1622
        dest_path = 'b/a'
1623
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1624
        revtree0, revtree1 = self.assertChanges(branch, 1,
1625
            expected_added=[('a',), (src_path,), ('b',), (dest_path,)])
1626
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1627
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1628
1629
0.99.15 by Ian Clatworthy
Add tests for copying to a path deleted in the same commit
1630
class TestImportToPackCopyToDeleted(TestCaseForGenericProcessor):
1631
1632
    def file_command_iter(self, src_path, dest_path, kind='file'):
1633
        # Revno 1: create two files or symlinks
1634
        # Revno 2: delete one and copy the other one to its path
1635
        def command_list():
1636
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1637
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1638
            def files_one():
1639
                yield commands.FileModifyCommand(src_path, kind, False,
1640
                        None, "aaa")
1641
                yield commands.FileModifyCommand(dest_path, kind, False,
1642
                        None, "bbb")
1643
            yield commands.CommitCommand('head', '1', author,
1644
                committer, "commit 1", None, [], files_one)
1645
            def files_two():
1646
                yield commands.FileDeleteCommand(dest_path)
1647
                yield commands.FileCopyCommand(src_path, dest_path)
1648
            yield commands.CommitCommand('head', '2', author,
1649
                committer, "commit 2", ":1", [], files_two)
1650
        return command_list
1651
1652
    def test_copy_to_deleted_file_in_root(self):
1653
        handler, branch = self.get_handler()
1654
        src_path = 'a'
1655
        dest_path = 'b'
1656
        handler.process(self.file_command_iter(src_path, dest_path))
1657
        revtree0, revtree1 = self.assertChanges(branch, 1,
1658
            expected_added=[(src_path,), (dest_path,)])
1659
        revtree1, revtree2 = self.assertChanges(branch, 2,
1660
            expected_removed=[(dest_path,)],
1661
            expected_added=[(dest_path,)])
1662
        self.assertContent(branch, revtree1, src_path, "aaa")
1663
        self.assertContent(branch, revtree1, dest_path, "bbb")
1664
        self.assertContent(branch, revtree2, src_path, "aaa")
1665
        self.assertContent(branch, revtree2, dest_path, "aaa")
1666
        self.assertRevisionRoot(revtree1, src_path)
1667
        self.assertRevisionRoot(revtree1, dest_path)
1668
1669
    def test_copy_to_deleted_symlink_in_root(self):
1670
        handler, branch = self.get_handler()
1671
        src_path = 'a'
1672
        dest_path = 'b'
1673
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1674
        revtree0, revtree1 = self.assertChanges(branch, 1,
1675
            expected_added=[(src_path,), (dest_path,)])
1676
        revtree1, revtree2 = self.assertChanges(branch, 2,
1677
            expected_removed=[(dest_path,)],
1678
            expected_added=[(dest_path,)])
1679
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1680
        self.assertSymlinkTarget(branch, revtree1, dest_path, "bbb")
1681
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1682
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1683
        self.assertRevisionRoot(revtree1, src_path)
1684
        self.assertRevisionRoot(revtree1, dest_path)
1685
1686
    def test_copy_to_deleted_file_in_subdir(self):
1687
        handler, branch = self.get_handler()
1688
        src_path = 'd/a'
1689
        dest_path = 'd/b'
1690
        handler.process(self.file_command_iter(src_path, dest_path))
1691
        revtree0, revtree1 = self.assertChanges(branch, 1,
1692
            expected_added=[('d',), (src_path,), (dest_path,)])
1693
        revtree1, revtree2 = self.assertChanges(branch, 2,
1694
            expected_removed=[(dest_path,)],
1695
            expected_added=[(dest_path,)])
1696
        self.assertContent(branch, revtree1, src_path, "aaa")
1697
        self.assertContent(branch, revtree1, dest_path, "bbb")
1698
        self.assertContent(branch, revtree2, src_path, "aaa")
1699
        self.assertContent(branch, revtree2, dest_path, "aaa")
1700
1701
    def test_copy_to_deleted_symlink_in_subdir(self):
1702
        handler, branch = self.get_handler()
1703
        src_path = 'd/a'
1704
        dest_path = 'd/b'
1705
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1706
        revtree0, revtree1 = self.assertChanges(branch, 1,
1707
            expected_added=[('d',), (src_path,), (dest_path,)])
1708
        revtree1, revtree2 = self.assertChanges(branch, 2,
1709
            expected_removed=[(dest_path,)],
1710
            expected_added=[(dest_path,)])
1711
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1712
        self.assertSymlinkTarget(branch, revtree1, dest_path, "bbb")
1713
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1714
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1715
1716
0.99.18 by Ian Clatworthy
Handle copy of a file/symlink already modified in this commit
1717
class TestImportToPackCopyModified(TestCaseForGenericProcessor):
1718
    """Test copy of file/symlink already modified in this commit."""
1719
1720
    def file_command_iter(self, src_path, dest_path, kind='file'):
1721
        # Revno 1: create a file or symlink
1722
        # Revno 2: modify and copy it
1723
        def command_list():
1724
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1725
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1726
            def files_one():
1727
                yield commands.FileModifyCommand(src_path, kind, False,
1728
                        None, "aaa")
1729
            yield commands.CommitCommand('head', '1', author,
1730
                committer, "commit 1", None, [], files_one)
1731
            def files_two():
1732
                yield commands.FileModifyCommand(src_path, kind, False,
1733
                        None, "bbb")
1734
                yield commands.FileCopyCommand(src_path, dest_path)
1735
            yield commands.CommitCommand('head', '2', author,
1736
                committer, "commit 2", ":1", [], files_two)
1737
        return command_list
1738
1739
    def test_copy_of_modified_file_in_root(self):
1740
        handler, branch = self.get_handler()
1741
        src_path = 'a'
1742
        dest_path = 'b'
1743
        handler.process(self.file_command_iter(src_path, dest_path))
1744
        revtree1, revtree2 = self.assertChanges(branch, 2,
1745
            expected_modified=[(src_path,)],
1746
            expected_added=[(dest_path,)])
1747
        self.assertContent(branch, revtree1, src_path, "aaa")
1748
        self.assertContent(branch, revtree2, src_path, "bbb")
1749
        self.assertContent(branch, revtree2, dest_path, "bbb")
1750
        self.assertRevisionRoot(revtree1, src_path)
1751
        self.assertRevisionRoot(revtree2, dest_path)
1752
1753
    def test_copy_of_modified_file_in_subdir(self):
1754
        handler, branch = self.get_handler()
1755
        src_path = 'd/a'
1756
        dest_path = 'd/b'
1757
        handler.process(self.file_command_iter(src_path, dest_path))
1758
        revtree1, revtree2 = self.assertChanges(branch, 2,
1759
            expected_modified=[(src_path,)],
1760
            expected_added=[(dest_path,)])
1761
        self.assertContent(branch, revtree1, src_path, "aaa")
1762
        self.assertContent(branch, revtree2, src_path, "bbb")
1763
        self.assertContent(branch, revtree2, dest_path, "bbb")
1764
1765
    def test_copy_of_modified_file_to_new_dir(self):
1766
        handler, branch = self.get_handler()
1767
        src_path = 'd1/a'
1768
        dest_path = 'd2/a'
1769
        handler.process(self.file_command_iter(src_path, dest_path))
1770
        revtree1, revtree2 = self.assertChanges(branch, 2,
1771
            expected_modified=[(src_path,)],
1772
            expected_added=[('d2',), (dest_path,)])
1773
        self.assertContent(branch, revtree1, src_path, "aaa")
1774
        self.assertContent(branch, revtree2, src_path, "bbb")
1775
        self.assertContent(branch, revtree2, dest_path, "bbb")
1776
1777
    def test_copy_of_modified_symlink_in_root(self):
1778
        handler, branch = self.get_handler()
1779
        src_path = 'a'
1780
        dest_path = 'b'
1781
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1782
        revtree1, revtree2 = self.assertChanges(branch, 2,
1783
            expected_modified=[(src_path,)],
1784
            expected_added=[(dest_path,)])
1785
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1786
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1787
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
1788
        self.assertRevisionRoot(revtree1, src_path)
1789
        self.assertRevisionRoot(revtree2, dest_path)
1790
1791
    def test_copy_of_modified_symlink_in_subdir(self):
1792
        handler, branch = self.get_handler()
1793
        src_path = 'd/a'
1794
        dest_path = 'd/b'
1795
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1796
        revtree1, revtree2 = self.assertChanges(branch, 2,
1797
            expected_modified=[(src_path,)],
1798
            expected_added=[(dest_path,)])
1799
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1800
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1801
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
1802
1803
    def test_copy_of_modified_symlink_to_new_dir(self):
1804
        handler, branch = self.get_handler()
1805
        src_path = 'd1/a'
1806
        dest_path = 'd2/a'
1807
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1808
        revtree1, revtree2 = self.assertChanges(branch, 2,
1809
            expected_modified=[(src_path,)],
1810
            expected_added=[('d2',), (dest_path,)])
1811
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1812
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1813
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
0.99.10 by Ian Clatworthy
commented out draft of CopyModified tests
1814
1815
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1816
class TestImportToPackFileKinds(TestCaseForGenericProcessor):
0.64.74 by Ian Clatworthy
fix symlink importing
1817
1818
    def get_command_iter(self, path, kind, content):
1819
        def command_list():
1820
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1821
            def files_one():
1822
                yield commands.FileModifyCommand(path, kind, False,
1823
                        None, content)
1824
            yield commands.CommitCommand('head', '1', None,
1825
                committer, "commit 1", None, [], files_one)
1826
        return command_list
1827
1828
    def test_import_plainfile(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
1829
        handler, branch = self.get_handler()
1830
        handler.process(self.get_command_iter('foo', 'file', 'aaa'))
0.64.74 by Ian Clatworthy
fix symlink importing
1831
1832
    def test_import_symlink(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
1833
        handler, branch = self.get_handler()
1834
        handler.process(self.get_command_iter('foo', 'symlink', 'bar'))