~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: Aaron Bentley
  • Date: 2009-10-15 15:25:20 UTC
  • mto: (4634.97.2 2.0)
  • mto: This revision was merged to the branch mainline in revision 4770.
  • Revision ID: aaron@aaronbentley.com-20091015152520-dudll0her1ktejc5
Clean up tests, test iter_patched.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
                            MalformedHunkHeader,
26
26
                            MalformedPatchHeader,
27
27
                            BinaryPatch,
 
28
                            BinaryFiles,
28
29
                            Patch,
29
30
                            ContextLine,
30
31
                            InsertLine,
47
48
                                 "test_patches_data", filename)
48
49
        return file(data_path, "rb")
49
50
 
 
51
    def data_lines(self, filename):
 
52
        datafile = self.datafile(filename)
 
53
        try:
 
54
            return datafile.readlines()
 
55
        finally:
 
56
            datafile.close()
 
57
 
50
58
    def testValidPatchHeader(self):
51
59
        """Parse a valid patch header"""
52
60
        lines = "--- orig/commands.py\n+++ mod/dommands.py\n".split('\n')
140
148
 
141
149
    def test_parse_binary(self):
142
150
        """Test parsing a whole patch"""
143
 
        patches = parse_patches(self.datafile("binary.patch"))
 
151
        patches = parse_patches(self.data_lines("binary.patch"))
144
152
        self.assertIs(BinaryPatch, patches[0].__class__)
145
153
        self.assertIs(Patch, patches[1].__class__)
146
154
        self.assertContainsRe(patches[0].oldname, '^bar\t')
149
157
                                  'Binary files bar\t.* and qux\t.* differ\n')
150
158
 
151
159
    def test_roundtrip_binary(self):
152
 
        patchtext = self.datafile("binary.patch").read()
 
160
        patchtext = ''.join(self.data_lines("binary.patch"))
153
161
        patches = parse_patches(patchtext.splitlines(True))
154
162
        self.assertEqual(patchtext, ''.join(str(p) for p in patches))
155
163
 
211
219
                count += 1
212
220
            self.assertEqual(count, len(mod_lines))
213
221
 
 
222
    def test_iter_patched_binary(self):
 
223
        binary_lines = self.data_lines('binary.patch')
 
224
        e = self.assertRaises(BinaryFiles, iter_patched, [], binary_lines)
 
225
 
 
226
 
214
227
    def test_iter_patched_from_hunks(self):
215
228
        """Test a few patch files, and make sure they work."""
216
229
        files = [