/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.65.4 by James Westby
Make the rename handling more robust.
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
import time
18
19
from bzrlib import (
20
    branch,
21
    tests,
22
    )
23
24
from bzrlib.plugins.fastimport import (
25
    commands,
26
    errors,
27
    )
28
29
from bzrlib.plugins.fastimport.processors import (
30
    generic_processor,
31
    )
32
33
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
34
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
0.65.4 by James Westby
Make the rename handling more robust.
35
36
    def get_handler(self):
37
        branch = self.make_branch('.')
38
        handler = generic_processor.GenericProcessor(branch.bzrdir)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
39
        return handler, branch
0.65.4 by James Westby
Make the rename handling more robust.
40
41
    # FIXME: [] as a default is bad, as it is mutable, but I want
42
    # to use None to mean "don't check this".
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
43
    def assertChanges(self, branch, revno, expected_added=[],
44
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
45
            expected_renamed=[], expected_kind_changed=[]):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
46
        """Check the changes introduced in a revision of a branch.
47
48
        This method checks that a revision introduces expected changes.
49
        The required changes are passed in as a list, where
50
        each entry contains the needed information about the change.
51
52
        If you do not wish to assert anything about a particular
53
        category then pass None instead.
54
55
        branch: The branch.
56
        revno: revision number of revision to check.
57
        expected_added: a list of (filename,) tuples that must have
58
            been added in the delta.
59
        expected_removed: a list of (filename,) tuples that must have
60
            been removed in the delta.
61
        expected_modified: a list of (filename,) tuples that must have
62
            been modified in the delta.
63
        expected_renamed: a list of (old_path, new_path) tuples that
64
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
65
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
66
            that must have been changed in the delta.
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
67
        :return: revtree1, revtree2
68
        """
69
        repo = branch.repository
0.80.1 by Ian Clatworthy
basic units tests for filemodify
70
        revtree1 = repo.revision_tree(branch.get_rev_id(revno - 1))
71
        revtree2 = repo.revision_tree(branch.get_rev_id(revno))
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
72
        changes = revtree2.changes_from(revtree1)
0.80.3 by Ian Clatworthy
file <-> symlink change tests
73
        self._check_changes(changes, expected_added, expected_removed,
74
            expected_modified, expected_renamed, expected_kind_changed)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
75
        return revtree1, revtree2
76
0.80.3 by Ian Clatworthy
file <-> symlink change tests
77
    def _check_changes(self, changes, expected_added=[],
0.65.4 by James Westby
Make the rename handling more robust.
78
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
79
            expected_renamed=[], expected_kind_changed=[]):
0.65.4 by James Westby
Make the rename handling more robust.
80
        """Check the changes in a TreeDelta
81
82
        This method checks that the TreeDelta contains the expected
83
        modifications between the two trees that were used to generate
84
        it. The required changes are passed in as a list, where
85
        each entry contains the needed information about the change.
86
87
        If you do not wish to assert anything about a particular
88
        category then pass None instead.
89
90
        changes: The TreeDelta to check.
91
        expected_added: a list of (filename,) tuples that must have
92
            been added in the delta.
93
        expected_removed: a list of (filename,) tuples that must have
94
            been removed in the delta.
95
        expected_modified: a list of (filename,) tuples that must have
96
            been modified in the delta.
97
        expected_renamed: a list of (old_path, new_path) tuples that
98
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
99
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
100
            that must have been changed in the delta.
0.65.4 by James Westby
Make the rename handling more robust.
101
        """
102
        renamed = changes.renamed
103
        added = changes.added
104
        removed = changes.removed
105
        modified = changes.modified
0.80.3 by Ian Clatworthy
file <-> symlink change tests
106
        kind_changed = changes.kind_changed
0.65.4 by James Westby
Make the rename handling more robust.
107
        if expected_renamed is not None:
108
            self.assertEquals(len(renamed), len(expected_renamed),
0.74.1 by John Arbash Meinel
Change the rename code to create a new text entry.
109
                "%s is renamed, expected %s" % (renamed, expected_renamed))
0.65.4 by James Westby
Make the rename handling more robust.
110
            renamed_files = [(item[0], item[1]) for item in renamed]
111
            for expected_renamed_entry in expected_renamed:
112
                self.assertTrue(expected_renamed_entry in renamed_files,
113
                    "%s is not renamed, %s are" % (str(expected_renamed_entry),
114
                        renamed_files))
115
        if expected_added is not None:
116
            self.assertEquals(len(added), len(expected_added),
117
                "%s is added" % str(added))
118
            added_files = [(item[0],) for item in added]
119
            for expected_added_entry in expected_added:
120
                self.assertTrue(expected_added_entry in added_files,
121
                    "%s is not added, %s are" % (str(expected_added_entry),
122
                        added_files))
123
        if expected_removed is not None:
124
            self.assertEquals(len(removed), len(expected_removed),
125
                "%s is removed" % str(removed))
126
            removed_files = [(item[0],) for item in removed]
127
            for expected_removed_entry in expected_removed:
128
                self.assertTrue(expected_removed_entry in removed_files,
129
                    "%s is not removed, %s are" % (str(expected_removed_entry),
130
                        removed_files))
131
        if expected_modified is not None:
132
            self.assertEquals(len(modified), len(expected_modified),
133
                "%s is modified" % str(modified))
134
            modified_files = [(item[0],) for item in modified]
135
            for expected_modified_entry in expected_modified:
136
                self.assertTrue(expected_modified_entry in modified_files,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
137
                    "%s is not modified, %s are" % (
138
                    str(expected_modified_entry), modified_files))
139
        if expected_kind_changed is not None:
140
            self.assertEquals(len(kind_changed), len(expected_kind_changed),
141
                "%s is kind-changed, expected %s" % (kind_changed,
142
                    expected_kind_changed))
143
            kind_changed_files = [(item[0], item[2], item[3])
144
                for item in kind_changed]
145
            for expected_kind_changed_entry in expected_kind_changed:
146
                self.assertTrue(expected_kind_changed_entry in
147
                    kind_changed_files, "%s is not kind-changed, %s are" % (
148
                    str(expected_kind_changed_entry), kind_changed_files))
0.65.4 by James Westby
Make the rename handling more robust.
149
0.80.1 by Ian Clatworthy
basic units tests for filemodify
150
    def assertContent(self, branch, tree, path, content):
151
        file_id = tree.inventory.path2id(path)
152
        branch.lock_read()
153
        self.addCleanup(branch.unlock)
154
        self.assertEqual(tree.get_file_text(file_id), content)
155
156
    def assertSymlinkTarget(self, branch, tree, path, target):
157
        file_id = tree.inventory.path2id(path)
158
        branch.lock_read()
159
        self.addCleanup(branch.unlock)
160
        self.assertEqual(tree.get_symlink_target(file_id), target)
161
0.80.4 by Ian Clatworthy
file executable off <-> on tests
162
    def assertExecutable(self, branch, tree, path, executable):
163
        file_id = tree.inventory.path2id(path)
164
        branch.lock_read()
165
        self.addCleanup(branch.unlock)
166
        self.assertEqual(tree.is_executable(file_id), executable)
167
0.80.1 by Ian Clatworthy
basic units tests for filemodify
168
    def assertRevisionRoot(self, revtree, path):
169
        self.assertEqual(revtree.get_revision_id(),
170
                         revtree.inventory.root.children[path].revision)
171
172
173
class TestModify(TestCaseForGenericProcessor):
174
0.80.3 by Ian Clatworthy
file <-> symlink change tests
175
    def file_command_iter(self, path, kind='file', content='aaa',
0.80.4 by Ian Clatworthy
file executable off <-> on tests
176
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
177
        # Revno 1: create a file or symlink
178
        # Revno 2: modify it
0.80.3 by Ian Clatworthy
file <-> symlink change tests
179
        if to_kind is None:
180
            to_kind = kind
0.80.4 by Ian Clatworthy
file executable off <-> on tests
181
        if to_executable is None:
182
            to_executable = executable
0.80.1 by Ian Clatworthy
basic units tests for filemodify
183
        def command_list():
184
            author = ['', 'bugs@a.com', time.time(), time.timezone]
185
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
186
            def files_one():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
187
                yield commands.FileModifyCommand(path, kind, executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
188
                        None, content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
189
            yield commands.CommitCommand('head', '1', author,
190
                committer, "commit 1", None, [], files_one)
191
            def files_two():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
192
                yield commands.FileModifyCommand(path, to_kind, to_executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
193
                        None, to_content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
194
            yield commands.CommitCommand('head', '2', author,
195
                committer, "commit 2", ":1", [], files_two)
196
        return command_list
197
198
    def test_modify_file_in_root(self):
199
        handler, branch = self.get_handler()
200
        path = 'a'
201
        handler.process(self.file_command_iter(path))
202
        revtree0, revtree1 = self.assertChanges(branch, 1,
203
            expected_added=[(path,)])
204
        revtree1, revtree2 = self.assertChanges(branch, 2,
205
            expected_modified=[(path,)])
206
        self.assertContent(branch, revtree1, path, "aaa")
207
        self.assertContent(branch, revtree2, path, "bbb")
208
        self.assertRevisionRoot(revtree1, path)
209
        self.assertRevisionRoot(revtree2, path)
210
211
    def test_modify_file_in_subdir(self):
212
        handler, branch = self.get_handler()
213
        path = 'a/a'
214
        handler.process(self.file_command_iter(path))
215
        revtree0, revtree1 = self.assertChanges(branch, 1,
216
            expected_added=[('a',), (path,)])
217
        revtree1, revtree2 = self.assertChanges(branch, 2,
218
            expected_modified=[(path,)])
219
        self.assertContent(branch, revtree1, path, "aaa")
220
        self.assertContent(branch, revtree2, path, "bbb")
221
222
    def test_modify_symlink_in_root(self):
223
        handler, branch = self.get_handler()
224
        path = 'a'
225
        handler.process(self.file_command_iter(path, kind='symlink'))
226
        revtree1, revtree2 = self.assertChanges(branch, 2,
227
            expected_modified=[(path,)])
228
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
229
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
230
        self.assertRevisionRoot(revtree1, path)
231
        self.assertRevisionRoot(revtree2, path)
232
233
    def test_modify_symlink_in_subdir(self):
234
        handler, branch = self.get_handler()
235
        path = 'a/a'
236
        handler.process(self.file_command_iter(path, kind='symlink'))
237
        revtree0, revtree1 = self.assertChanges(branch, 1,
238
            expected_added=[('a',), (path,)])
239
        revtree1, revtree2 = self.assertChanges(branch, 2,
240
            expected_modified=[(path,)])
241
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
242
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
243
0.80.3 by Ian Clatworthy
file <-> symlink change tests
244
    def test_modify_file_becomes_symlink(self):
245
        handler, branch = self.get_handler()
246
        path = 'a/a'
247
        handler.process(self.file_command_iter(path,
248
            kind='file', to_kind='symlink'))
249
        revtree0, revtree1 = self.assertChanges(branch, 1,
250
            expected_added=[('a',), (path,)])
251
        revtree1, revtree2 = self.assertChanges(branch, 2,
252
            expected_kind_changed=[(path, 'file', 'symlink')])
253
        self.assertContent(branch, revtree1, path, "aaa")
254
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
255
256
    def test_modify_symlink_becomes_file(self):
257
        handler, branch = self.get_handler()
258
        path = 'a/a'
259
        handler.process(self.file_command_iter(path,
260
            kind='symlink', to_kind='file'))
261
        revtree0, revtree1 = self.assertChanges(branch, 1,
262
            expected_added=[('a',), (path,)])
263
        revtree1, revtree2 = self.assertChanges(branch, 2,
264
            expected_kind_changed=[(path, 'symlink', 'file')])
265
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
266
        self.assertContent(branch, revtree2, path, "bbb")
267
0.80.4 by Ian Clatworthy
file executable off <-> on tests
268
    def test_modify_file_now_executable(self):
269
        handler, branch = self.get_handler()
270
        path = 'a/a'
271
        handler.process(self.file_command_iter(path,
272
            executable=False, to_executable=True, to_content='aaa'))
273
        revtree0, revtree1 = self.assertChanges(branch, 1,
274
            expected_added=[('a',), (path,)])
275
        revtree1, revtree2 = self.assertChanges(branch, 2,
276
            expected_modified=[(path,)])
277
        self.assertExecutable(branch, revtree1, path, False)
278
        self.assertExecutable(branch, revtree2, path, True)
279
280
    def test_modify_file_no_longer_executable(self):
281
        handler, branch = self.get_handler()
282
        path = 'a/a'
283
        handler.process(self.file_command_iter(path,
284
            executable=True, to_executable=False, to_content='aaa'))
285
        revtree0, revtree1 = self.assertChanges(branch, 1,
286
            expected_added=[('a',), (path,)])
287
        revtree1, revtree2 = self.assertChanges(branch, 2,
288
            expected_modified=[(path,)])
289
        self.assertExecutable(branch, revtree1, path, True)
290
        self.assertExecutable(branch, revtree2, path, False)
291
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
292
0.80.2 by Ian Clatworthy
basic delete tests
293
class TestDelete(TestCaseForGenericProcessor):
294
295
    def file_command_iter(self, path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
296
        # Revno 1: create a file or symlink
297
        # Revno 2: delete it
0.80.2 by Ian Clatworthy
basic delete tests
298
        def command_list():
299
            author = ['', 'bugs@a.com', time.time(), time.timezone]
300
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
301
            def files_one():
302
                yield commands.FileModifyCommand(path, kind, False,
303
                        None, "aaa")
304
            yield commands.CommitCommand('head', '1', author,
305
                committer, "commit 1", None, [], files_one)
306
            def files_two():
307
                yield commands.FileDeleteCommand(path)
308
            yield commands.CommitCommand('head', '2', author,
309
                committer, "commit 2", ":1", [], files_two)
310
        return command_list
311
312
    def test_delete_file_in_root(self):
313
        handler, branch = self.get_handler()
314
        path = 'a'
315
        handler.process(self.file_command_iter(path))
316
        revtree0, revtree1 = self.assertChanges(branch, 1,
317
            expected_added=[(path,)])
318
        revtree1, revtree2 = self.assertChanges(branch, 2,
319
            expected_removed=[(path,)])
320
        self.assertContent(branch, revtree1, path, "aaa")
321
        self.assertRevisionRoot(revtree1, path)
322
323
    def test_delete_file_in_subdir(self):
324
        handler, branch = self.get_handler()
325
        path = 'a/a'
326
        handler.process(self.file_command_iter(path))
327
        revtree0, revtree1 = self.assertChanges(branch, 1,
328
            expected_added=[('a',), (path,)])
329
        revtree1, revtree2 = self.assertChanges(branch, 2,
330
            expected_removed=[(path,)])
331
        self.assertContent(branch, revtree1, path, "aaa")
332
333
    def test_delete_symlink_in_root(self):
334
        handler, branch = self.get_handler()
335
        path = 'a'
336
        handler.process(self.file_command_iter(path, kind='symlink'))
337
        revtree1, revtree2 = self.assertChanges(branch, 2,
338
            expected_removed=[(path,)])
339
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
340
        self.assertRevisionRoot(revtree1, path)
341
342
    def test_delete_symlink_in_subdir(self):
343
        handler, branch = self.get_handler()
344
        path = 'a/a'
345
        handler.process(self.file_command_iter(path, kind='symlink'))
346
        revtree0, revtree1 = self.assertChanges(branch, 1,
347
            expected_added=[('a',), (path,)])
348
        revtree1, revtree2 = self.assertChanges(branch, 2,
349
            expected_removed=[(path,)])
350
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
351
352
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
353
class TestRename(TestCaseForGenericProcessor):
354
355
    def get_command_iter(self, old_path, new_path):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
356
        # Revno 1: create a file or symlink
357
        # Revno 2: rename it
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
358
        def command_list():
359
            author = ['', 'bugs@a.com', time.time(), time.timezone]
360
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
361
            def files_one():
362
                yield commands.FileModifyCommand(old_path, 'file', False,
363
                        None, "aaa")
364
            yield commands.CommitCommand('head', '1', author,
365
                committer, "commit 1", None, [], files_one)
366
            def files_two():
367
                yield commands.FileRenameCommand(old_path, new_path)
368
            yield commands.CommitCommand('head', '2', author,
369
                committer, "commit 2", ":1", [], files_two)
370
        return command_list
371
0.65.4 by James Westby
Make the rename handling more robust.
372
    def test_rename_in_root(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
373
        handler, branch = self.get_handler()
0.65.4 by James Westby
Make the rename handling more robust.
374
        old_path = 'a'
375
        new_path = 'b'
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
376
        handler.process(self.get_command_iter(old_path, new_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
377
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
378
            expected_renamed=[(old_path, new_path)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
379
        self.assertRevisionRoot(revtree1, old_path)
380
        self.assertRevisionRoot(revtree2, new_path)
0.65.4 by James Westby
Make the rename handling more robust.
381
382
    def test_rename_in_subdir(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
383
        handler, branch = self.get_handler()
0.65.4 by James Westby
Make the rename handling more robust.
384
        old_path = 'a/a'
385
        new_path = 'a/b'
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
386
        handler.process(self.get_command_iter(old_path, new_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
387
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
0.65.4 by James Westby
Make the rename handling more robust.
388
389
    def test_move_to_new_dir(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
390
        handler, branch = self.get_handler()
0.65.4 by James Westby
Make the rename handling more robust.
391
        old_path = 'a/a'
392
        new_path = 'b/a'
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
393
        handler.process(self.get_command_iter(old_path, new_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
394
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)],
0.65.4 by James Westby
Make the rename handling more robust.
395
            expected_added=[('b',)])
0.64.74 by Ian Clatworthy
fix symlink importing
396
397
0.76.2 by Ian Clatworthy
code & tests for file copying
398
class TestCopy(TestCaseForGenericProcessor):
399
0.80.1 by Ian Clatworthy
basic units tests for filemodify
400
    def file_command_iter(self, src_path, dest_path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
401
        # Revno 1: create a file or symlink
402
        # Revno 2: copy it
0.76.2 by Ian Clatworthy
code & tests for file copying
403
        def command_list():
404
            author = ['', 'bugs@a.com', time.time(), time.timezone]
405
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
406
            def files_one():
0.80.1 by Ian Clatworthy
basic units tests for filemodify
407
                yield commands.FileModifyCommand(src_path, kind, False,
0.76.2 by Ian Clatworthy
code & tests for file copying
408
                        None, "aaa")
409
            yield commands.CommitCommand('head', '1', author,
410
                committer, "commit 1", None, [], files_one)
411
            def files_two():
412
                yield commands.FileCopyCommand(src_path, dest_path)
413
            yield commands.CommitCommand('head', '2', author,
414
                committer, "commit 2", ":1", [], files_two)
415
        return command_list
416
417
    def test_copy_file_in_root(self):
418
        handler, branch = self.get_handler()
419
        src_path = 'a'
420
        dest_path = 'b'
421
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
422
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
423
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
424
        self.assertContent(branch, revtree1, src_path, "aaa")
425
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
426
        self.assertContent(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
427
        self.assertRevisionRoot(revtree1, src_path)
428
        self.assertRevisionRoot(revtree2, dest_path)
0.76.2 by Ian Clatworthy
code & tests for file copying
429
430
    def test_copy_file_in_subdir(self):
431
        handler, branch = self.get_handler()
432
        src_path = 'a/a'
433
        dest_path = 'a/b'
434
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
435
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
436
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
437
        self.assertContent(branch, revtree1, src_path, "aaa")
438
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
439
        self.assertContent(branch, revtree2, dest_path, "aaa")
440
441
    def test_copy_file_to_new_dir(self):
442
        handler, branch = self.get_handler()
443
        src_path = 'a/a'
444
        dest_path = 'b/a'
445
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
446
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
447
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
448
        self.assertContent(branch, revtree1, src_path, "aaa")
449
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
450
        self.assertContent(branch, revtree2, dest_path, "aaa")
451
0.76.3 by Ian Clatworthy
symlink copying tests
452
    def test_copy_symlink_in_root(self):
453
        handler, branch = self.get_handler()
454
        src_path = 'a'
455
        dest_path = 'b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
456
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
457
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
458
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
459
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
460
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
461
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
462
        self.assertRevisionRoot(revtree1, src_path)
463
        self.assertRevisionRoot(revtree2, dest_path)
0.76.3 by Ian Clatworthy
symlink copying tests
464
465
    def test_copy_symlink_in_subdir(self):
466
        handler, branch = self.get_handler()
467
        src_path = 'a/a'
468
        dest_path = 'a/b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
469
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
470
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
471
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
472
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
473
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
474
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
475
476
    def test_copy_symlink_to_new_dir(self):
477
        handler, branch = self.get_handler()
478
        src_path = 'a/a'
479
        dest_path = 'b/a'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
480
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
481
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
482
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
483
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
484
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
485
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
486
0.76.2 by Ian Clatworthy
code & tests for file copying
487
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
488
class TestFileKinds(TestCaseForGenericProcessor):
0.64.74 by Ian Clatworthy
fix symlink importing
489
490
    def get_command_iter(self, path, kind, content):
491
        def command_list():
492
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
493
            def files_one():
494
                yield commands.FileModifyCommand(path, kind, False,
495
                        None, content)
496
            yield commands.CommitCommand('head', '1', None,
497
                committer, "commit 1", None, [], files_one)
498
        return command_list
499
500
    def test_import_plainfile(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
501
        handler, branch = self.get_handler()
502
        handler.process(self.get_command_iter('foo', 'file', 'aaa'))
0.64.74 by Ian Clatworthy
fix symlink importing
503
504
    def test_import_symlink(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
505
        handler, branch = self.get_handler()
506
        handler.process(self.get_command_iter('foo', 'symlink', 'bar'))