/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-17 21:27:40 UTC
  • mto: (0.64.114 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090217212740-qeqgp189adajb51q
clean-up tests for GenericProcessor

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    )
32
32
 
33
33
 
34
 
class TestRename(tests.TestCaseWithTransport):
 
34
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
35
35
 
36
36
    def get_handler(self):
37
37
        branch = self.make_branch('.')
38
38
        handler = generic_processor.GenericProcessor(branch.bzrdir)
39
 
        return (handler, branch)
40
 
 
41
 
    def get_command_iter(self, old_path, new_path):
42
 
        def command_list():
43
 
            author = ['', 'bugs@a.com', time.time(), time.timezone]
44
 
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
45
 
            def files_one():
46
 
                yield commands.FileModifyCommand(old_path, 'file', False,
47
 
                        None, "aaa")
48
 
            yield commands.CommitCommand('head', '1', author,
49
 
                committer, "commit 1", None, [], files_one)
50
 
            def files_two():
51
 
                yield commands.FileRenameCommand(old_path, new_path)
52
 
            yield commands.CommitCommand('head', '2', author,
53
 
                committer, "commit 2", ":1", [], files_two)
54
 
        return command_list
 
39
        return handler, branch
55
40
 
56
41
    # FIXME: [] as a default is bad, as it is mutable, but I want
57
42
    # to use None to mean "don't check this".
 
43
    def assertChanges(self, branch, revno, expected_added=[],
 
44
            expected_removed=[], expected_modified=[],
 
45
            expected_renamed=[]):
 
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.
 
65
        :return: revtree1, revtree2
 
66
        """
 
67
        repo = branch.repository
 
68
        revtree1 = repo.revision_tree(branch.revision_history()[revno - 1])
 
69
        revtree2 = repo.revision_tree(branch.revision_history()[revno])
 
70
        changes = revtree2.changes_from(revtree1)
 
71
        self.check_changes(changes, expected_added, expected_removed,
 
72
            expected_modified, expected_renamed)
 
73
        return revtree1, revtree2
 
74
 
58
75
    def check_changes(self, changes, expected_added=[],
59
76
            expected_removed=[], expected_modified=[],
60
77
            expected_renamed=[]):
115
132
                    "%s is not modified, %s are" % (str(expected_modified_entry),
116
133
                        modified_files))
117
134
 
 
135
 
 
136
class TestRename(TestCaseForGenericProcessor):
 
137
 
 
138
    def get_command_iter(self, old_path, new_path):
 
139
        def command_list():
 
140
            author = ['', 'bugs@a.com', time.time(), time.timezone]
 
141
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
 
142
            def files_one():
 
143
                yield commands.FileModifyCommand(old_path, 'file', False,
 
144
                        None, "aaa")
 
145
            yield commands.CommitCommand('head', '1', author,
 
146
                committer, "commit 1", None, [], files_one)
 
147
            def files_two():
 
148
                yield commands.FileRenameCommand(old_path, new_path)
 
149
            yield commands.CommitCommand('head', '2', author,
 
150
                committer, "commit 2", ":1", [], files_two)
 
151
        return command_list
 
152
 
118
153
    def test_rename_in_root(self):
119
 
        (handler, branch) = self.get_handler()
 
154
        handler, branch = self.get_handler()
120
155
        old_path = 'a'
121
156
        new_path = 'b'
122
 
        command_list = self.get_command_iter(old_path, new_path)
123
 
        handler.process(command_list)
124
 
        repo = branch.repository
125
 
        revtree1 = repo.revision_tree(branch.revision_history()[0])
126
 
        revtree2 = repo.revision_tree(branch.revision_history()[1])
127
 
        changes = revtree2.changes_from(revtree1)
 
157
        handler.process(self.get_command_iter(old_path, new_path))
 
158
        revtree1, revtree2 = self.assertChanges(branch, 1,
 
159
            expected_renamed=[(old_path, new_path)])
128
160
        self.assertEqual(revtree1.get_revision_id(),
129
161
                         revtree1.inventory.root.children['a'].revision)
130
162
        self.assertEqual(revtree2.get_revision_id(),
131
163
                         revtree2.inventory.root.children['b'].revision)
132
 
        self.check_changes(changes, expected_renamed=[(old_path, new_path)])
133
164
 
134
165
    def test_rename_in_subdir(self):
135
 
        (handler, branch) = self.get_handler()
 
166
        handler, branch = self.get_handler()
136
167
        old_path = 'a/a'
137
168
        new_path = 'a/b'
138
 
        command_list = self.get_command_iter(old_path, new_path)
139
 
        handler.process(command_list)
140
 
        repo = branch.repository
141
 
        revtree1 = repo.revision_tree(branch.revision_history()[0])
142
 
        revtree2 = repo.revision_tree(branch.revision_history()[1])
143
 
        changes = revtree2.changes_from(revtree1)
144
 
        self.check_changes(changes, expected_renamed=[(old_path, new_path)])
 
169
        handler.process(self.get_command_iter(old_path, new_path))
 
170
        self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)])
145
171
 
146
172
    def test_move_to_new_dir(self):
147
 
        (handler, branch) = self.get_handler()
 
173
        handler, branch = self.get_handler()
148
174
        old_path = 'a/a'
149
175
        new_path = 'b/a'
150
 
        command_list = self.get_command_iter(old_path, new_path)
151
 
        handler.process(command_list)
152
 
        repo = branch.repository
153
 
        revtree1 = repo.revision_tree(branch.revision_history()[0])
154
 
        revtree2 = repo.revision_tree(branch.revision_history()[1])
155
 
        changes = revtree2.changes_from(revtree1)
156
 
        self.check_changes(changes, expected_renamed=[(old_path, new_path)],
 
176
        handler.process(self.get_command_iter(old_path, new_path))
 
177
        self.assertChanges(branch, 1, expected_renamed=[(old_path, new_path)],
157
178
            expected_added=[('b',)])
158
179
 
159
180
 
160
 
class TestFileKinds(tests.TestCaseWithTransport):
161
 
 
162
 
    def get_handler(self):
163
 
        branch = self.make_branch('.')
164
 
        handler = generic_processor.GenericProcessor(branch.bzrdir)
165
 
        return (handler, branch)
 
181
class TestFileKinds(TestCaseForGenericProcessor):
166
182
 
167
183
    def get_command_iter(self, path, kind, content):
168
184
        def command_list():
175
191
        return command_list
176
192
 
177
193
    def test_import_plainfile(self):
178
 
        (handler, branch) = self.get_handler()
179
 
        command_list = self.get_command_iter('foo', 'file', 'aaa')
 
194
        handler, branch = self.get_handler()
 
195
        handler.process(self.get_command_iter('foo', 'file', 'aaa'))
180
196
 
181
197
    def test_import_symlink(self):
182
 
        (handler, branch) = self.get_handler()
183
 
        command_list = self.get_command_iter('foo', 'symlink', 'bar')
184
 
        handler.process(command_list)
 
198
        handler, branch = self.get_handler()
 
199
        handler.process(self.get_command_iter('foo', 'symlink', 'bar'))