From bb0f1625d7655d04c6df3c144e488f676ff2f762 Mon Sep 17 00:00:00 2001 From: Trevor Gamblin Date: Tue, 24 Sep 2024 07:54:58 -0400 Subject: patchtest: patterns: add module, refactor Currently, patchtest has a lot of spread-out definitions for patterns used in various setup and test functions. Organize these by putting them all into a new patterns.py module. This allows the tests/pyparsing directory to be removed, as it is now redundant. Also remove some definitions where they were duplicated or unused, and perform some renames to improve readability and avoid collisions. Many of these variables are composed from others, so the file is only partially sorted. (From OE-Core rev: 1ab55d495957918be532a36224b5598c9955a44d) Signed-off-by: Trevor Gamblin Signed-off-by: Richard Purdie --- meta/lib/patchtest/tests/test_patch.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'meta/lib/patchtest/tests/test_patch.py') diff --git a/meta/lib/patchtest/tests/test_patch.py b/meta/lib/patchtest/tests/test_patch.py index d7187a0cb1..d856b216f0 100644 --- a/meta/lib/patchtest/tests/test_patch.py +++ b/meta/lib/patchtest/tests/test_patch.py @@ -7,16 +7,11 @@ import base import os -import parse_signed_off_by -import parse_upstream_status +import patterns import pyparsing class TestPatch(base.Base): - re_cve_pattern = pyparsing.Regex("CVE\-\d{4}\-\d+") - re_cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+") - upstream_status_regex = pyparsing.AtLineStart("+" + "Upstream-Status") - @classmethod def setUpClassLocal(cls): cls.newpatches = [] @@ -25,16 +20,16 @@ class TestPatch(base.Base): if patch.path.endswith('.patch') and patch.is_added_file: cls.newpatches.append(patch) - cls.mark = str(parse_signed_off_by.signed_off_by_mark).strip('"') + cls.mark = str(patterns.signed_off_by_prefix).strip('"') # match PatchSignedOffBy.mark with '+' preceding it - cls.prog = parse_signed_off_by.patch_signed_off_by + cls.prog = patterns.patch_signed_off_by def setUp(self): if self.unidiff_parse_error: self.skip('Parse error %s' % self.unidiff_parse_error) - self.valid_status = ', '.join(parse_upstream_status.upstream_status_nonliteral_valid_status) + self.valid_status = ', '.join(patterns.upstream_status_nonliteral_valid_status) self.standard_format = 'Upstream-Status: ' # we are just interested in series that introduce CVE patches, thus discard other @@ -50,28 +45,28 @@ class TestPatch(base.Base): for newpatch in TestPatch.newpatches: payload = newpatch.__str__() - if not self.upstream_status_regex.search_string(payload): + if not patterns.upstream_status_regex.search_string(payload): self.fail('Added patch file is missing Upstream-Status: in the commit message', data=[('Standard format', self.standard_format), ('Valid status', self.valid_status)]) for line in payload.splitlines(): if self.patchmetadata_regex.match(line): continue - if self.upstream_status_regex.search_string(line): - if parse_upstream_status.inappropriate_status_mark.searchString(line): + if patterns.upstream_status_regex.search_string(line): + if patterns.inappropriate.searchString(line): try: - parse_upstream_status.upstream_status_inappropriate_info.parseString(line.lstrip('+')) + patterns.upstream_status_inappropriate_info.parseString(line.lstrip('+')) except pyparsing.ParseException as pe: self.fail('Upstream-Status is Inappropriate, but no reason was provided', data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')]) - elif parse_upstream_status.submitted_status_mark.searchString(line): + elif patterns.submitted.searchString(line): try: - parse_upstream_status.upstream_status_submitted_info.parseString(line.lstrip('+')) + patterns.upstream_status_submitted_info.parseString(line.lstrip('+')) except pyparsing.ParseException as pe: self.fail('Upstream-Status is Submitted, but it is not mentioned where', data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')]) else: try: - parse_upstream_status.upstream_status.parseString(line.lstrip('+')) + patterns.upstream_status.parseString(line.lstrip('+')) except pyparsing.ParseException as pe: self.fail('Upstream-Status is in incorrect format', data=[('Current', pe.pstr), ('Standard format', self.standard_format), ('Valid status', self.valid_status)]) @@ -92,10 +87,10 @@ class TestPatch(base.Base): def test_cve_tag_format(self): for commit in TestPatch.commits: - if self.re_cve_pattern.search_string(commit.shortlog) or self.re_cve_pattern.search_string(commit.commit_message): + if patterns.cve.search_string(commit.shortlog) or patterns.cve.search_string(commit.commit_message): tag_found = False for line in commit.payload.splitlines(): - if self.re_cve_payload_tag.search_string(line): + if patterns.cve_payload_tag.search_string(line): tag_found = True break if not tag_found: -- cgit v1.2.3-54-g00ecf