Example #1
0
    def testPatch(self):
        """Testing patching"""

        file = 'foo.c'

        old = self._get_file('orig_src', file)
        new = self._get_file('new_src', file)
        diff = self._get_file('diffs', 'unified', 'foo.c.diff')

        patched = diffutils.patch(diff, old, file)
        self.assertEqual(patched, new)

        diff = self._get_file('diffs', 'unified', 'README.diff')
        self.assertRaises(Exception, lambda: diffutils.patch(diff, old, file))
Example #2
0
 def testPatchCRLFFileCRDiff(self):
     """Testing patching a CRLF file with a CR diff"""
     old = self._get_file('orig_src', 'README.crlf')
     new = self._get_file('new_src', 'README')
     diff = self._get_file('diffs', 'unified', 'README.diff')
     patched = diffutils.patch(diff, old, new)
     self.assertEqual(patched, new)
Example #3
0
 def testPatchFileWithFakeNoNewline(self):
     """Testing patching a file indicating no newline with a trailing \\r"""
     old = self._get_file('orig_src', 'README.nonewline')
     new = self._get_file('new_src', 'README.nonewline')
     diff = self._get_file('diffs', 'unified', 'README.nonewline.diff')
     files = diffparser.DiffParser(diff).parse()
     patched = diffutils.patch(files[0].data, old, new)
     self.assertEqual(diff, files[0].data)
     self.assertEqual(patched, new)
Example #4
0
 def testEmptyPatch(self):
     """Testing patching with an empty diff"""
     old = 'This is a test'
     diff = ''
     patched = diffutils.patch(diff, old, 'test.c')
     self.assertEqual(patched, old)