/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_generic_processor.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-20 01:29:28 UTC
  • mto: (0.64.124 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090220012928-qit87bi9cokj82iz
file <-> symlink change tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    # to use None to mean "don't check this".
43
43
    def assertChanges(self, branch, revno, expected_added=[],
44
44
            expected_removed=[], expected_modified=[],
45
 
            expected_renamed=[]):
 
45
            expected_renamed=[], expected_kind_changed=[]):
46
46
        """Check the changes introduced in a revision of a branch.
47
47
 
48
48
        This method checks that a revision introduces expected changes.
62
62
            been modified in the delta.
63
63
        expected_renamed: a list of (old_path, new_path) tuples that
64
64
            must have been renamed in the delta.
 
65
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
 
66
            that must have been changed in the delta.
65
67
        :return: revtree1, revtree2
66
68
        """
67
69
        repo = branch.repository
68
70
        revtree1 = repo.revision_tree(branch.get_rev_id(revno - 1))
69
71
        revtree2 = repo.revision_tree(branch.get_rev_id(revno))
70
72
        changes = revtree2.changes_from(revtree1)
71
 
        self.check_changes(changes, expected_added, expected_removed,
72
 
            expected_modified, expected_renamed)
 
73
        self._check_changes(changes, expected_added, expected_removed,
 
74
            expected_modified, expected_renamed, expected_kind_changed)
73
75
        return revtree1, revtree2
74
76
 
75
 
    def check_changes(self, changes, expected_added=[],
 
77
    def _check_changes(self, changes, expected_added=[],
76
78
            expected_removed=[], expected_modified=[],
77
 
            expected_renamed=[]):
 
79
            expected_renamed=[], expected_kind_changed=[]):
78
80
        """Check the changes in a TreeDelta
79
81
 
80
82
        This method checks that the TreeDelta contains the expected
94
96
            been modified in the delta.
95
97
        expected_renamed: a list of (old_path, new_path) tuples that
96
98
            must have been renamed in the delta.
 
99
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
 
100
            that must have been changed in the delta.
97
101
        """
98
102
        renamed = changes.renamed
99
103
        added = changes.added
100
104
        removed = changes.removed
101
105
        modified = changes.modified
 
106
        kind_changed = changes.kind_changed
102
107
        if expected_renamed is not None:
103
108
            self.assertEquals(len(renamed), len(expected_renamed),
104
109
                "%s is renamed, expected %s" % (renamed, expected_renamed))
129
134
            modified_files = [(item[0],) for item in modified]
130
135
            for expected_modified_entry in expected_modified:
131
136
                self.assertTrue(expected_modified_entry in modified_files,
132
 
                    "%s is not modified, %s are" % (str(expected_modified_entry),
133
 
                        modified_files))
 
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))
134
149
 
135
150
    def assertContent(self, branch, tree, path, content):
136
151
        file_id = tree.inventory.path2id(path)
151
166
 
152
167
class TestModify(TestCaseForGenericProcessor):
153
168
 
154
 
    def file_command_iter(self, path, kind='file'):
 
169
    def file_command_iter(self, path, kind='file', content='aaa',
 
170
        to_kind=None, to_content='bbb'):
 
171
        if to_kind is None:
 
172
            to_kind = kind
155
173
        def command_list():
156
174
            author = ['', 'bugs@a.com', time.time(), time.timezone]
157
175
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
158
176
            def files_one():
159
177
                yield commands.FileModifyCommand(path, kind, False,
160
 
                        None, "aaa")
 
178
                        None, content)
161
179
            yield commands.CommitCommand('head', '1', author,
162
180
                committer, "commit 1", None, [], files_one)
163
181
            def files_two():
164
 
                yield commands.FileModifyCommand(path, kind, False,
165
 
                        None, "bbb")
 
182
                yield commands.FileModifyCommand(path, to_kind, False,
 
183
                        None, to_content)
166
184
            yield commands.CommitCommand('head', '2', author,
167
185
                committer, "commit 2", ":1", [], files_two)
168
186
        return command_list
213
231
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
214
232
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
215
233
 
 
234
    def test_modify_file_becomes_symlink(self):
 
235
        handler, branch = self.get_handler()
 
236
        path = 'a/a'
 
237
        handler.process(self.file_command_iter(path,
 
238
            kind='file', to_kind='symlink'))
 
239
        revtree0, revtree1 = self.assertChanges(branch, 1,
 
240
            expected_added=[('a',), (path,)])
 
241
        revtree1, revtree2 = self.assertChanges(branch, 2,
 
242
            expected_kind_changed=[(path, 'file', 'symlink')])
 
243
        self.assertContent(branch, revtree1, path, "aaa")
 
244
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
 
245
 
 
246
    def test_modify_symlink_becomes_file(self):
 
247
        handler, branch = self.get_handler()
 
248
        path = 'a/a'
 
249
        handler.process(self.file_command_iter(path,
 
250
            kind='symlink', to_kind='file'))
 
251
        revtree0, revtree1 = self.assertChanges(branch, 1,
 
252
            expected_added=[('a',), (path,)])
 
253
        revtree1, revtree2 = self.assertChanges(branch, 2,
 
254
            expected_kind_changed=[(path, 'symlink', 'file')])
 
255
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
 
256
        self.assertContent(branch, revtree2, path, "bbb")
 
257
 
216
258
 
217
259
class TestDelete(TestCaseForGenericProcessor):
218
260