Skip to contentSkip to conversation

test_mbox_signed_off_by: fix test

PATCH New Trevor Gamblin 1 participant 1 message Jun 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test_mbox_signed_off_by: fix test

This fixes a consistent issue with false failures being reported when testing for authors' signed-off-bys in mboxes. Instead of manually compiling a regex pattern, use pyparsing's AtLineStart to check for the signature's presence at the beginning of the line.

---
 tests/pyparsing/parse_signed_off_by.py | 4 ++--
 tests/test_mbox_signed_off_by.py       | 5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)
tests/pyparsing/parse_signed_off_by.py +2 -2
index fc39a6c..9338c49 100644
@@ -30,5 +30,5 @@ email = pyparsing.Regex(r"(?P<user>[A-Za-z0-9._%+-]+)@(?P<hostname>[A-Za-z0-9.-]
 
 email_enclosed = common.lessthan + email + common.greaterthan
 
-signed_off_by_mark = pyparsing.Literal("Signed-off-by")
-signed_off_by = common.start + signed_off_by_mark + common.colon + name + email_enclosed + common.end
+signed_off_by_mark = pyparsing.Literal("Signed-off-by:")
+signed_off_by = pyparsing.AtLineStart(signed_off_by_mark + name + email_enclosed)
tests/test_mbox_signed_off_by.py +2 -3
index e50bb8e..eae2816 100644
@@ -28,15 +28,14 @@ class SignedOffBy(base.Base):
     @classmethod
     def setUpClassLocal(cls):
         # match self.mark with no '+' preceding it
-        cls.mark = str(parse_signed_off_by.signed_off_by_mark).strip('"')
-        cls.prog = re.compile("(?<!\+)%s" % cls.mark)
+        cls.prog = parse_signed_off_by.signed_off_by
 
     def test_signed_off_by_presence(self):
         for commit in SignedOffBy.commits:
             # skip those patches that revert older commits, these do not required the tag presence
             if self.revert_shortlog_regex.match(commit.shortlog):
                 continue
-            if not SignedOffBy.prog.search(commit.payload):
+            if not SignedOffBy.prog.search_string(commit.payload):
                 self.fail('Patch is missing Signed-off-by',
                           'Sign off the patch (either manually or with "git commit --amend -s")',
                           commit)
Signature · 1 line
2.40.1