~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from bzrlib.patches import (MalformedLine,
25
25
                            MalformedHunkHeader,
26
26
                            MalformedPatchHeader,
 
27
                            BinaryPatch,
 
28
                            BinaryFiles,
 
29
                            Patch,
27
30
                            ContextLine,
28
31
                            InsertLine,
29
32
                            RemoveLine,
45
48
                                 "test_patches_data", filename)
46
49
        return file(data_path, "rb")
47
50
 
 
51
    def data_lines(self, filename):
 
52
        datafile = self.datafile(filename)
 
53
        try:
 
54
            return datafile.readlines()
 
55
        finally:
 
56
            datafile.close()
 
57
 
48
58
    def testValidPatchHeader(self):
49
59
        """Parse a valid patch header"""
50
60
        lines = "--- orig/commands.py\n+++ mod/dommands.py\n".split('\n')
136
146
        patchtext = self.datafile("patchtext.patch").read()
137
147
        self.compare_parsed(patchtext)
138
148
 
 
149
    def test_parse_binary(self):
 
150
        """Test parsing a whole patch"""
 
151
        patches = parse_patches(self.data_lines("binary.patch"))
 
152
        self.assertIs(BinaryPatch, patches[0].__class__)
 
153
        self.assertIs(Patch, patches[1].__class__)
 
154
        self.assertContainsRe(patches[0].oldname, '^bar\t')
 
155
        self.assertContainsRe(patches[0].newname, '^qux\t')
 
156
        self.assertContainsRe(str(patches[0]),
 
157
                                  'Binary files bar\t.* and qux\t.* differ\n')
 
158
 
 
159
    def test_roundtrip_binary(self):
 
160
        patchtext = ''.join(self.data_lines("binary.patch"))
 
161
        patches = parse_patches(patchtext.splitlines(True))
 
162
        self.assertEqual(patchtext, ''.join(str(p) for p in patches))
 
163
 
139
164
    def testInit(self):
140
165
        """Handle patches missing half the position, range tuple"""
141
166
        patchtext = \
194
219
                count += 1
195
220
            self.assertEqual(count, len(mod_lines))
196
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
 
197
227
    def test_iter_patched_from_hunks(self):
198
228
        """Test a few patch files, and make sure they work."""
199
229
        files = [