From 63d5313664c96cdfcee345f5c880f9973a3ee1da Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Wed, 31 Aug 2022 15:09:47 -0400 Subject: Refactor how we handle trailers With the addition of b4 trailers it became pretty obvious that the way we originally implemented trailers didn't age well. This refactor does the following: - introduces LoreTrailer class to replace passing trailers as tuples - reimplements trailer-order with strict adherence to chain-of-custody rules - adds tests to most common trailer follow-up/ordering cases Signed-off-by: Konstantin Ryabitsev --- .../trailers-followup-custody-ref-ordered.txt | 41 ++++++++ .../trailers-followup-custody-ref-unordered.txt | 41 ++++++++ tests/samples/trailers-followup-custody.mbox | 65 ++++++++++++ .../trailers-followup-single-ref-addlink.txt | 37 +++++++ .../trailers-followup-single-ref-addmysob.txt | 36 +++++++ .../trailers-followup-single-ref-copyccs.txt | 39 +++++++ .../trailers-followup-single-ref-defaults.txt | 35 +++++++ .../samples/trailers-followup-single-ref-noadd.txt | 33 ++++++ .../trailers-followup-single-ref-ordered.txt | 39 +++++++ .../trailers-followup-single-ref-sloppy.txt | 37 +++++++ tests/samples/trailers-followup-single.mbox | 78 ++++++++++++++ ...ilers-followup-with-cover-ref-covertrailers.txt | 75 ++++++++++++++ .../trailers-followup-with-cover-ref-defaults.txt | 73 +++++++++++++ tests/samples/trailers-followup-with-cover.mbox | 113 +++++++++++++++++++++ tests/samples/trailers-test-extinfo.txt | 29 ++++++ tests/samples/trailers-test-simple.txt | 24 +++++ tests/test___init__.py | 66 +++++++++++- 17 files changed, 859 insertions(+), 2 deletions(-) create mode 100644 tests/samples/trailers-followup-custody-ref-ordered.txt create mode 100644 tests/samples/trailers-followup-custody-ref-unordered.txt create mode 100644 tests/samples/trailers-followup-custody.mbox create mode 100644 tests/samples/trailers-followup-single-ref-addlink.txt create mode 100644 tests/samples/trailers-followup-single-ref-addmysob.txt create mode 100644 tests/samples/trailers-followup-single-ref-copyccs.txt create mode 100644 tests/samples/trailers-followup-single-ref-defaults.txt create mode 100644 tests/samples/trailers-followup-single-ref-noadd.txt create mode 100644 tests/samples/trailers-followup-single-ref-ordered.txt create mode 100644 tests/samples/trailers-followup-single-ref-sloppy.txt create mode 100644 tests/samples/trailers-followup-single.mbox create mode 100644 tests/samples/trailers-followup-with-cover-ref-covertrailers.txt create mode 100644 tests/samples/trailers-followup-with-cover-ref-defaults.txt create mode 100644 tests/samples/trailers-followup-with-cover.mbox create mode 100644 tests/samples/trailers-test-extinfo.txt create mode 100644 tests/samples/trailers-test-simple.txt (limited to 'tests') diff --git a/tests/samples/trailers-followup-custody-ref-ordered.txt b/tests/samples/trailers-followup-custody-ref-ordered.txt new file mode 100644 index 0000000..383befb --- /dev/null +++ b/tests/samples/trailers-followup-custody-ref-ordered.txt @@ -0,0 +1,41 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Link: https://msgid.link/some@msgid.here +Reviewed-by: Original Reviewer +Signed-off-by: Original Submitter +Cc: Dev Eloper1 +Cc: Dev Eloper2 +Cc: Some List +Fixes: abcdef01234567890 +Link: https://lore.kernel.org/some@msgid.here # bug discussion +Suggested-by: Friendly Suggester +Reviewed-by: Followup Reviewer1 +Tested-by: Followup Reviewer2 +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-custody-ref-unordered.txt b/tests/samples/trailers-followup-custody-ref-unordered.txt new file mode 100644 index 0000000..4b238da --- /dev/null +++ b/tests/samples/trailers-followup-custody-ref-unordered.txt @@ -0,0 +1,41 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Link: https://msgid.link/some@msgid.here +Reviewed-by: Original Reviewer +Signed-off-by: Original Submitter +Suggested-by: Friendly Suggester +Fixes: abcdef01234567890 +Link: https://lore.kernel.org/some@msgid.here # bug discussion +Reviewed-by: Followup Reviewer1 +Tested-by: Followup Reviewer2 +Cc: Dev Eloper1 +Cc: Dev Eloper2 +Cc: Some List +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-custody.mbox b/tests/samples/trailers-followup-custody.mbox new file mode 100644 index 0000000..0c4e4b8 --- /dev/null +++ b/tests/samples/trailers-followup-custody.mbox @@ -0,0 +1,65 @@ +From foo@z Thu Jan 1 00:00:00 1970 +From: Test Test +Subject: [PATCH] Simple test +To: Some List +Cc: Dev Eloper1 , + Dev Eloper2 +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: + +Follow-up trailer collating test. + +Link: https://msgid.link/some@msgid.here +Reviewed-by: Original Reviewer +Signed-off-by: Original Submitter +Suggested-by: Friendly Suggester +Fixes: abcdef01234567890 +Link: https://lore.kernel.org/some@msgid.here # bug discussion +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + +From foo@z Thu Jan 1 00:00:00 1970 +From: Followup Reviewer1 +Subject: Re: [PATCH] Simple test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +> This is a simple trailer parsing test. + +Reviewed-by: Followup Reviewer1 + +-- +My sig + +From foo@z Thu Jan 1 00:00:00 1970 +From: Followup Reviewer2 +Subject: Re: [PATCH] Simple test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +>> This is a simple trailer parsing test. +> +> Reviewed-by: Followup Reviewer1 + +Tested-by: Followup Reviewer2 + +-- +My sig diff --git a/tests/samples/trailers-followup-single-ref-addlink.txt b/tests/samples/trailers-followup-single-ref-addlink.txt new file mode 100644 index 0000000..024c842 --- /dev/null +++ b/tests/samples/trailers-followup-single-ref-addlink.txt @@ -0,0 +1,37 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Followup Reviewer1 +Tested-by: Followup Reviewer2 +Link: https://lore.kernel.org/r/orig-message@example.com +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-single-ref-addmysob.txt b/tests/samples/trailers-followup-single-ref-addmysob.txt new file mode 100644 index 0000000..9da6c0b --- /dev/null +++ b/tests/samples/trailers-followup-single-ref-addmysob.txt @@ -0,0 +1,36 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Followup Reviewer1 +Tested-by: Followup Reviewer2 +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-single-ref-copyccs.txt b/tests/samples/trailers-followup-single-ref-copyccs.txt new file mode 100644 index 0000000..3623462 --- /dev/null +++ b/tests/samples/trailers-followup-single-ref-copyccs.txt @@ -0,0 +1,39 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Followup Reviewer1 +Tested-by: Followup Reviewer2 +Cc: Dev Eloper1 +Cc: Dev Eloper2 +Cc: Some List +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-single-ref-defaults.txt b/tests/samples/trailers-followup-single-ref-defaults.txt new file mode 100644 index 0000000..3750c06 --- /dev/null +++ b/tests/samples/trailers-followup-single-ref-defaults.txt @@ -0,0 +1,35 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Followup Reviewer1 +Tested-by: Followup Reviewer2 +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-single-ref-noadd.txt b/tests/samples/trailers-followup-single-ref-noadd.txt new file mode 100644 index 0000000..80a1011 --- /dev/null +++ b/tests/samples/trailers-followup-single-ref-noadd.txt @@ -0,0 +1,33 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-single-ref-ordered.txt b/tests/samples/trailers-followup-single-ref-ordered.txt new file mode 100644 index 0000000..2084c36 --- /dev/null +++ b/tests/samples/trailers-followup-single-ref-ordered.txt @@ -0,0 +1,39 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Cc: Dev Eloper1 +Cc: Dev Eloper2 +Cc: Some List +Tested-by: Followup Reviewer2 +Reviewed-by: Followup Reviewer1 +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-single-ref-sloppy.txt b/tests/samples/trailers-followup-single-ref-sloppy.txt new file mode 100644 index 0000000..9b6a49d --- /dev/null +++ b/tests/samples/trailers-followup-single-ref-sloppy.txt @@ -0,0 +1,37 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH] Simple test +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Followup Reviewer1 +Tested-by: Followup Reviewer2 +Reviewed-by: Mismatched Reviewer1 +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-single.mbox b/tests/samples/trailers-followup-single.mbox new file mode 100644 index 0000000..b12f6ba --- /dev/null +++ b/tests/samples/trailers-followup-single.mbox @@ -0,0 +1,78 @@ +From foo@z Thu Jan 1 00:00:00 1970 +From: Test Test +Subject: [PATCH] Simple test +To: Some List +Cc: Dev Eloper1 , + Dev Eloper2 +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: + +Follow-up trailer collating test. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + +From foo@z Thu Jan 1 00:00:00 1970 +From: Followup Reviewer1 +Subject: Re: [PATCH] Simple test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +> This is a simple trailer parsing test. + +Reviewed-by: Followup Reviewer1 + +-- +My sig + +From foo@z Thu Jan 1 00:00:00 1970 +From: Followup Reviewer2 +Subject: Re: [PATCH] Simple test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +>> This is a simple trailer parsing test. +> +> Reviewed-by: Followup Reviewer1 + +Tested-by: Followup Reviewer2 + +-- +My sig + +From foo@z Thu Jan 1 00:00:00 1970 +From: Mismatched Reviewer +Subject: Re: [PATCH] Simple test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +> This is a simple trailer parsing test. + +Reviewed-by: Mismatched Reviewer1 + +-- +My sig + diff --git a/tests/samples/trailers-followup-with-cover-ref-covertrailers.txt b/tests/samples/trailers-followup-with-cover-ref-covertrailers.txt new file mode 100644 index 0000000..8a503ea --- /dev/null +++ b/tests/samples/trailers-followup-with-cover-ref-covertrailers.txt @@ -0,0 +1,75 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH v2 1/2] Simple test 1 +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +In-Reply-To: +References: +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test patch 1. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Coverletter Reviewer1 +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH v2 2/2] Simple test 2 +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +In-Reply-To: +References: +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test patch 2. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Followup Reviewer1 +Reviewed-by: Coverletter Reviewer1 +Signed-off-by: Test Override +--- + +diff --git a/b4/bupkes.py b/b4/bupkes.py +index 12345678..23456789 100644 +--- a/b4/bupkes.py +--- b/b4/bupkes.py +@@@ -1,1 +1,1 @@ def bupkes(): + + +-bupkes1 ++bupkes2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-with-cover-ref-defaults.txt b/tests/samples/trailers-followup-with-cover-ref-defaults.txt new file mode 100644 index 0000000..cbd1eb8 --- /dev/null +++ b/tests/samples/trailers-followup-with-cover-ref-defaults.txt @@ -0,0 +1,73 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH v2 1/2] Simple test 1 +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +In-Reply-To: +References: +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test patch 1. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Signed-off-by: Test Override +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH v2 2/2] Simple test 2 +From: Test Test +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +To: Some List +Cc: Dev Eloper1 , Dev Eloper2 +In-Reply-To: +References: +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +Follow-up trailer collating test patch 2. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +Reviewed-by: Followup Reviewer1 +Signed-off-by: Test Override +--- + +diff --git a/b4/bupkes.py b/b4/bupkes.py +index 12345678..23456789 100644 +--- a/b4/bupkes.py +--- b/b4/bupkes.py +@@@ -1,1 +1,1 @@ def bupkes(): + + +-bupkes1 ++bupkes2 + + +-- +2.wong.fu + diff --git a/tests/samples/trailers-followup-with-cover.mbox b/tests/samples/trailers-followup-with-cover.mbox new file mode 100644 index 0000000..52c14c4 --- /dev/null +++ b/tests/samples/trailers-followup-with-cover.mbox @@ -0,0 +1,113 @@ +From foo@z Thu Jan 1 00:00:00 1970 +From: Test Test +Subject: [PATCH v2 0/2] Simple cover +To: Some List +Cc: Dev Eloper1 , + Dev Eloper2 +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: + +This is a cover letter. It has a diffstat. + +--- +b4/junk.py | 1 - +b4/bupkes.py | 1 - +2 files changed, 2 insertions(+), 2 deletions(-) + + +From foo@z Thu Jan 1 00:00:00 1970 +From: Test Test +Subject: [PATCH v2 1/2] Simple test 1 +To: Some List +Cc: Dev Eloper1 , + Dev Eloper2 +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +Follow-up trailer collating test patch 1. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu + +From foo@z Thu Jan 1 00:00:00 1970 +From: Test Test +Subject: [PATCH v2 2/2] Simple test 2 +To: Some List +Cc: Dev Eloper1 , + Dev Eloper2 +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +Follow-up trailer collating test patch 2. + +Fixes: abcdef01234567890 +Reviewed-by: Original Reviewer +Link: https://msgid.link/some@msgid.here +Signed-off-by: Original Submitter +--- + +diff --git a/b4/bupkes.py b/b4/bupkes.py +index 12345678..23456789 100644 +--- a/b4/bupkes.py +--- b/b4/bupkes.py +@@@ -1,1 +1,1 @@ def bupkes(): + + +-bupkes1 ++bupkes2 + + +-- +2.wong.fu + +From foo@z Thu Jan 1 00:00:00 1970 +From: Followup Reviewer1 +Subject: Re: [PATCH v2 2/2] Simple test 2 +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +> This is a simple trailer parsing test. + +Reviewed-by: Followup Reviewer1 + +-- +My sig + +From foo@z Thu Jan 1 00:00:00 1970 +From: Followup Reviewer1 +Subject: Re: [PATCH v2 0/2] Simple cover +Date: Tue, 30 Aug 2022 11:19:07 -0400 +Message-Id: +In-Reply-To: +References: + +> This is a simple trailer parsing test. + +Reviewed-by: Coverletter Reviewer1 + +-- +My sig + diff --git a/tests/samples/trailers-test-extinfo.txt b/tests/samples/trailers-test-extinfo.txt new file mode 100644 index 0000000..d36abbb --- /dev/null +++ b/tests/samples/trailers-test-extinfo.txt @@ -0,0 +1,29 @@ +From: Test Test +Subject: [PATCH] Simple test +Date: Tue, 30 Aug 2022 11:19:07 -0400 + +This is a simple trailer parsing test. + +Reviewed-by: Bogus Bupkes +[for the parts that are bogus] +Fixes: abcdef01234567890 +Tested-by: Some Person + [this person visually indented theirs] +Link: https://msgid.link/some@msgid.here # initial submission +Signed-off-by: Wrapped Persontrailer + +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu diff --git a/tests/samples/trailers-test-simple.txt b/tests/samples/trailers-test-simple.txt new file mode 100644 index 0000000..693d781 --- /dev/null +++ b/tests/samples/trailers-test-simple.txt @@ -0,0 +1,24 @@ +From: Test Test +Subject: [PATCH] Simple test +Date: Tue, 30 Aug 2022 11:19:07 -0400 + +This is a simple trailer parsing test. + +Reviewed-by: Bogus Bupkes +Fixes: abcdef01234567890 +Link: https://msgid.link/some@msgid.here +--- + +diff --git a/b4/junk.py b/b4/junk.py +index 12345678..23456789 100644 +--- a/b4/junk.py +--- b/b4/junk.py +@@@ -1,1 +1,1 @@ def junk(): + + +-junk1 ++junk2 + + +-- +2.wong.fu diff --git a/tests/test___init__.py b/tests/test___init__.py index d78667e..f97e166 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -1,7 +1,9 @@ import pytest # noqa import b4 -import re import os +import email +import mailbox +import io @pytest.mark.parametrize('source,expected', [ @@ -25,7 +27,6 @@ def test_save_git_am_mbox(tmpdir, source, regex, flags, ismbox): import re if source is not None: if ismbox: - import mailbox mbx = mailbox.mbox(f'tests/samples/{source}.txt') msgs = list(mbx) else: @@ -48,3 +49,64 @@ def test_save_git_am_mbox(tmpdir, source, regex, flags, ismbox): with open(dest, 'r') as fh: res = fh.read() assert re.search(regex, res, flags=flags) + + +@pytest.mark.parametrize('source,expected', [ + ('trailers-test-simple', + [('person', 'Reviewed-By', 'Bogus Bupkes ', None), + ('utility', 'Fixes', 'abcdef01234567890', None), + ('utility', 'Link', 'https://msgid.link/some@msgid.here', None), + ]), + ('trailers-test-extinfo', + [('person', 'Reviewed-by', 'Bogus Bupkes ', '[for the parts that are bogus]'), + ('utility', 'Fixes', 'abcdef01234567890', None), + ('person', 'Tested-by', 'Some Person ', ' [this person visually indented theirs]'), + ('utility', 'Link', 'https://msgid.link/some@msgid.here', ' # initial submission'), + ('person', 'Signed-off-by', 'Wrapped Persontrailer ', None), + ]), +]) +def test_parse_trailers(source, expected): + with open(f'tests/samples/{source}.txt', 'r') as fh: + msg = email.message_from_file(fh) + lmsg = b4.LoreMessage(msg) + gh, m, trs, bas, sig = b4.LoreMessage.get_body_parts(lmsg.body) + assert len(expected) == len(trs) + for tr in trs: + mytype, myname, myvalue, myextinfo = expected.pop(0) + mytr = b4.LoreTrailer(name=myname, value=myvalue, extinfo=myextinfo) + assert tr == mytr + assert tr.type == mytype + + +@pytest.mark.parametrize('source,serargs,amargs,reference,b4cfg', [ + ('single', {}, {}, 'defaults', {}), + ('single', {}, {'noaddtrailers': True}, 'noadd', {}), + ('single', {}, {'addmysob': True}, 'addmysob', {}), + ('single', {}, {'addmysob': True, 'copyccs': True}, 'copyccs', {}), + ('single', {}, {'addmysob': True, 'addlink': True}, 'addlink', {}), + ('single', {}, {'addmysob': True, 'copyccs': True}, 'ordered', + {'trailer-order': 'Cc,Tested*,Reviewed*,*'}), + ('single', {'sloppytrailers': True}, {'addmysob': True}, 'sloppy', {}), + ('with-cover', {}, {'addmysob': True}, 'defaults', {}), + ('with-cover', {}, {'covertrailers': True, 'addmysob': True}, 'covertrailers', {}), + ('custody', {}, {'addmysob': True, 'copyccs': True}, 'unordered', {}), + ('custody', {}, {'addmysob': True, 'copyccs': True}, 'ordered', + {'trailer-order': 'Cc,Fixes*,Link*,Suggested*,Reviewed*,Tested*,*'}), +]) +def test_followup_trailers(source, serargs, amargs, reference, b4cfg): + b4.USER_CONFIG = { + 'name': 'Test Override', + 'email': 'test-override@example.com', + } + b4.MAIN_CONFIG = dict(b4.DEFAULT_CONFIG) + b4.MAIN_CONFIG.update(b4cfg) + lmbx = b4.LoreMailbox() + for msg in mailbox.mbox(f'tests/samples/trailers-followup-{source}.mbox'): + lmbx.add_message(msg) + lser = lmbx.get_series(**serargs) + assert lser is not None + amsgs = lser.get_am_ready(**amargs) + ifh = io.StringIO() + b4.save_git_am_mbox(amsgs, ifh) + with open(f'tests/samples/trailers-followup-{source}-ref-{reference}.txt', 'r') as fh: + assert ifh.getvalue() == fh.read() -- cgit v1.2.3