]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/tests/test_patchparser.py
parser: Fix parsing of patches with a trailing no-newline marker
[patchwork] / apps / patchwork / tests / test_patchparser.py
index 0496a69f231e21f5e0dda86c8b247560c5a7a8ea..119936acab1e44519f0e32afa970ebb3cbb0361a 100644 (file)
@@ -422,6 +422,32 @@ class CVSFormatPatchTest(MBoxPatchTest):
         self.assertTrue(comment is not None)
         self.assertTrue(patch.content.startswith('Index'))
 
+class CharsetFallbackPatchTest(MBoxPatchTest):
+    """ Test mail with and invalid charset name, and check that we can parse
+        with one of the fallback encodings"""
+
+    mail_file = '0010-invalid-charset.mbox'
+
+    def testPatch(self):
+        (patch, comment) = find_content(self.project, self.mail)
+        self.assertTrue(patch is not None)
+        self.assertTrue(comment is not None)
+
+class NoNewlineAtEndOfFilePatchTest(MBoxPatchTest):
+    mail_file = '0011-no-newline-at-end-of-file.mbox'
+
+    def testPatch(self):
+        (patch, comment) = find_content(self.project, self.mail)
+        self.assertTrue(patch is not None)
+        self.assertTrue(comment is not None)
+        self.assertTrue(patch.content.startswith('diff --git a/tools/testing/selftests/powerpc/Makefile'))
+        # Confirm the trailing no newline marker doesn't end up in the comment
+        self.assertFalse(comment.content.rstrip().endswith('\ No newline at end of file'))
+        # Confirm it's instead at the bottom of the patch
+        self.assertTrue(patch.content.rstrip().endswith('\ No newline at end of file'))
+        # Confirm we got both markers
+        self.assertEqual(2, patch.content.count('\ No newline at end of file'))
+
 class DelegateRequestTest(TestCase):
     patch_filename = '0001-add-line.patch'
     msgid = '<1@example.com>'