14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48
45
"test_patches_data", filename)
49
46
return file(data_path, "rb")
51
def data_lines(self, filename):
52
datafile = self.datafile(filename)
54
return datafile.readlines()
58
48
def testValidPatchHeader(self):
59
49
"""Parse a valid patch header"""
60
50
lines = "--- orig/commands.py\n+++ mod/dommands.py\n".split('\n')
146
136
patchtext = self.datafile("patchtext.patch").read()
147
137
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))
173
139
def testInit(self):
174
140
"""Handle patches missing half the position, range tuple"""
229
195
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)
236
197
def test_iter_patched_from_hunks(self):
237
198
"""Test a few patch files, and make sure they work."""