45
48
"test_patches_data", filename)
46
49
return file(data_path, "rb")
51
def data_lines(self, filename):
52
datafile = self.datafile(filename)
54
return datafile.readlines()
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)
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')
159
def test_parse_binary_after_normal(self):
160
patches = parse_patches(self.data_lines("binary-after-normal.patch"))
161
self.assertIs(BinaryPatch, patches[1].__class__)
162
self.assertIs(Patch, patches[0].__class__)
163
self.assertContainsRe(patches[1].oldname, '^bar\t')
164
self.assertContainsRe(patches[1].newname, '^qux\t')
165
self.assertContainsRe(str(patches[1]),
166
'Binary files bar\t.* and qux\t.* differ\n')
168
def test_roundtrip_binary(self):
169
patchtext = ''.join(self.data_lines("binary.patch"))
170
patches = parse_patches(patchtext.splitlines(True))
171
self.assertEqual(patchtext, ''.join(str(p) for p in patches))
139
173
def testInit(self):
140
174
"""Handle patches missing half the position, range tuple"""
195
229
self.assertEqual(count, len(mod_lines))
231
def test_iter_patched_binary(self):
232
binary_lines = self.data_lines('binary.patch')
233
e = self.assertRaises(BinaryFiles, iter_patched, [], binary_lines)
197
236
def test_iter_patched_from_hunks(self):
198
237
"""Test a few patch files, and make sure they work."""