def testKeywordDiff(self): """Testing parsing SVN diff with keywords""" # 'svn cat' will expand special variables in svn:keywords, # but 'svn diff' doesn't expand anything. This causes the # patch to fail if those variables appear in the patch context. diff = ( "Index: Makefile\n" "===========================================================" "========\n" "--- Makefile (revision 4)\n" "+++ Makefile (working copy)\n" "@@ -1,6 +1,7 @@\n" " # $Id$\n" " # $Rev$\n" " # $Revision:: $\n" "+# foo\n" " include ../tools/Makefile.base-vars\n" " NAME = misc-docs\n" " OUTNAME = svn-misc-docs\n" ) filename = "trunk/doc/misc-docs/Makefile" rev = Revision("4") file = self.tool.get_file(filename, rev) patch(diff, file, filename)
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))
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)
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)
def test_unterminated_keyword_diff(self): """Testing SVN (<backend>) parsing diff with unterminated keywords""" diff = (b'Index: Makefile\n' b'===========================================================' b'========\n' b'--- Makefile (revision 4)\n' b'+++ Makefile (working copy)\n' b'@@ -1,6 +1,7 @@\n' b' # $Id$\n' b' # $Id:\n' b' # $Rev$\n' b' # $Revision:: $\n' b'+# foo\n' b' include ../tools/Makefile.base-vars\n' b' NAME = misc-docs\n' b' OUTNAME = svn-misc-docs\n') filename = 'trunk/doc/misc-docs/Makefile' rev = Revision('5') file = self.tool.get_file(filename, rev) patch(diff, file, filename)
def testUnterminatedKeywordDiff(self): """Testing parsing SVN diff with unterminated keywords""" diff = "Index: Makefile\n" \ "===========================================================" \ "========\n" \ "--- Makefile (revision 4)\n" \ "+++ Makefile (working copy)\n" \ "@@ -1,6 +1,7 @@\n" \ " # $Id$\n" \ " # $Id:\n" \ " # $Rev$\n" \ " # $Revision:: $\n" \ "+# foo\n" \ " include ../tools/Makefile.base-vars\n" \ " NAME = misc-docs\n" \ " OUTNAME = svn-misc-docs\n" filename = 'trunk/doc/misc-docs/Makefile' rev = Revision('5') file = self.tool.get_file(filename, rev) patch(diff, file, filename)
def test_keyword_diff(self): """Testing SVN (<backend>) parsing diff with keywords""" # 'svn cat' will expand special variables in svn:keywords, # but 'svn diff' doesn't expand anything. This causes the # patch to fail if those variables appear in the patch context. diff = (b'Index: Makefile\n' b'===========================================================' b'========\n' b'--- Makefile (revision 4)\n' b'+++ Makefile (working copy)\n' b'@@ -1,6 +1,7 @@\n' b' # $Id$\n' b' # $Rev$\n' b' # $Revision:: $\n' b'+# foo\n' b' include ../tools/Makefile.base-vars\n' b' NAME = misc-docs\n' b' OUTNAME = svn-misc-docs\n') filename = 'trunk/doc/misc-docs/Makefile' rev = Revision('4') file = self.tool.get_file(filename, rev) patch(diff, file, filename)
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)