From 3ad772bb1f89e4effbcb49acbed5d305d5bed446 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Mon, 4 Apr 2016 00:58:34 +0200 Subject: [PATCH] patchutils.py: Add tests for multiple patches in a single file. --- staging/patchutils.py | 49 ++++++++++++++++++++++++++ staging/tests/multi.patch | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 staging/tests/multi.patch diff --git a/staging/patchutils.py b/staging/patchutils.py index fd14680a..1b32ce40 100644 --- a/staging/patchutils.py +++ b/staging/patchutils.py @@ -814,6 +814,55 @@ if __name__ == "__main__": self.assertEqual(patches[0].is_binary, False) self.assertEqual(patches[0].modified_file, "test.txt") + def test_multi(self): + with open("tests/multi.patch") as fp: + source = fp.read().split("\n") + + patchfile = tempfile.NamedTemporaryFile(mode='w+') + patchfile.write("\n".join(source)) + patchfile.flush() + + patches = list(read_patch(patchfile.name)) + self.assertEqual(len(patches), 3) + + self.assertEqual(patches[0].patch_author, "Author Name") + self.assertEqual(patches[0].patch_email, "author@email.com") + self.assertEqual(patches[0].patch_subject, "component: Replace arg1 with arg2.") + self.assertEqual(patches[0].patch_revision, 3) + self.assertEqual(patches[0].signed_off_by, [("Author Name", "author@email.com"), + ("Other Developer", "other@email.com")]) + self.assertEqual(patches[0].filename, patchfile.name) + self.assertEqual(patches[0].is_binary, False) + self.assertEqual(patches[0].modified_file, "other_test.txt") + + lines = patches[0].read().rstrip("\n").split("\n") + self.assertEqual(lines, source[11:24]) + + self.assertEqual(patches[1].patch_author, "Author Name") + self.assertEqual(patches[1].patch_email, "author@email.com") + self.assertEqual(patches[1].patch_subject, "component: Replace arg1 with arg2.") + self.assertEqual(patches[1].patch_revision, 3) + self.assertEqual(patches[1].signed_off_by, [("Author Name", "author@email.com"), + ("Other Developer", "other@email.com")]) + self.assertEqual(patches[1].filename, patchfile.name) + self.assertEqual(patches[1].is_binary, False) + self.assertEqual(patches[1].modified_file, "test.txt") + + lines = patches[1].read().rstrip("\n").split("\n") + self.assertEqual(lines, source[24:46]) + + self.assertEqual(patches[2].patch_author, "Other Developer") + self.assertEqual(patches[2].patch_email, "other@email.com") + self.assertEqual(patches[2].patch_subject, "component: Replace arg2 with arg3.") + self.assertEqual(patches[2].patch_revision, 4) + self.assertEqual(patches[2].signed_off_by, [("Other Developer", "other@email.com")]) + self.assertEqual(patches[2].filename, patchfile.name) + self.assertEqual(patches[2].is_binary, False) + self.assertEqual(patches[2].modified_file, "test.txt") + + lines = patches[2].read().rstrip("\n").split("\n") + self.assertEqual(lines, source[58:71]) + # Basic tests for apply_patch() class PatchApplyTests(unittest.TestCase): def test_apply(self): diff --git a/staging/tests/multi.patch b/staging/tests/multi.patch new file mode 100644 index 00000000..2ab78136 --- /dev/null +++ b/staging/tests/multi.patch @@ -0,0 +1,73 @@ +From be07df750862699f2515c0ac0ceb7a6c25e9458a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Author=20Name?= +Subject: [PATCH v3] component: Replace arg1 with arg2. + +Signed-off-by: =?UTF-8?q?Author=20Name?= +Signed-off-by: Other Developer +--- + other_test.txt | 2 +- + test.txt | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/other_test.txt b/other_test.txt +index a26e3f5..187ea7d 100644 +--- a/other_test.txt ++++ b/other_test.txt +@@ -1,7 +1,7 @@ + other_line1(); + other_line2(); + other_line3(); +-function(arg1); ++function(arg2); + other_line4(); + other_line5(); + other_line6(); +diff --git a/test.txt b/test.txt +index c9947e7..5d7eff8 100644 +--- a/test.txt ++++ b/test.txt +@@ -1,7 +1,7 @@ + line1(); + line2(); + line3(); +-function(arg1); ++function(arg2); + line5(); + line6(); + line7(); +@@ -9,7 +9,7 @@ line8(); + line9(); + line10(); + line11(); +-function(arg1); ++function(arg2); + line12(); + line13(); + line14(); +-- +2.7.1 + +From 801d4e778daf4f66dbe373e0a62cf0eb2fc0a7a3 Mon Sep 17 00:00:00 2001 +From: Other Developer +Subject: component: Replace arg2 with arg3. (v4) + +Signed-off-by: Other Developer +--- + test.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/test.txt b/test.txt +index 5d7eff8..73811d5 100644 +--- a/test.txt ++++ b/test.txt +@@ -1,7 +1,7 @@ + line1(); + line2(); + line3(); +-function(arg2); ++function(arg3); + line5(); + line6(); + line7(); +-- +2.7.1