~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-16 20:43:21 UTC
  • mfrom: (3363.18.4 direct-patching)
  • Revision ID: pqm@pqm.ubuntu.com-20081016204321-ayg99pvl7sr7y6qu
Add iter_patched_from_hunks to reduce API friction (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
                            get_patch_names,
32
32
                            hunk_from_header, 
33
33
                            iter_patched, 
 
34
                            iter_patched_from_hunks,
34
35
                            parse_line,
35
36
                            parse_patch,
36
37
                            parse_patches)
187
188
                count += 1
188
189
            self.assertEqual(count, len(mod_lines))
189
190
 
 
191
    def test_iter_patched_from_hunks(self):
 
192
        """Test a few patch files, and make sure they work."""
 
193
        files = [
 
194
            ('diff-2', 'orig-2', 'mod-2'),
 
195
            ('diff-3', 'orig-3', 'mod-3'),
 
196
            ('diff-4', 'orig-4', 'mod-4'),
 
197
            ('diff-5', 'orig-5', 'mod-5'),
 
198
            ('diff-6', 'orig-6', 'mod-6'),
 
199
        ]
 
200
        for diff, orig, mod in files:
 
201
            parsed = parse_patch(self.datafile(diff))
 
202
            orig_lines = list(self.datafile(orig))
 
203
            mod_lines = list(self.datafile(mod))
 
204
            iter_patched = iter_patched_from_hunks(orig_lines, parsed.hunks)
 
205
            patched_file = IterableFile(iter_patched)
 
206
            lines = []
 
207
            count = 0
 
208
            for patch_line in patched_file:
 
209
                self.assertEqual(patch_line, mod_lines[count])
 
210
                count += 1
 
211
            self.assertEqual(count, len(mod_lines))
 
212
 
190
213
    def testFirstLineRenumber(self):
191
214
        """Make sure we handle lines at the beginning of the hunk"""
192
215
        patch = parse_patch(self.datafile("insert_top.patch"))