diff options
author | Trevor Gamblin <tgamblin@baylibre.com> | 2024-09-24 07:54:58 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-09-30 17:00:50 +0100 |
commit | bb0f1625d7655d04c6df3c144e488f676ff2f762 (patch) | |
tree | 3e3a07f71c4e1950f5e7cc47dbdd1605888d0d16 /meta/lib/patchtest/tests/test_patch.py | |
parent | dd3a73961b49b508771a8cd579ebf1004f786f12 (diff) | |
download | poky-bb0f1625d7655d04c6df3c144e488f676ff2f762.tar.gz |
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 <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/patchtest/tests/test_patch.py')
-rw-r--r-- | meta/lib/patchtest/tests/test_patch.py | 31 |
1 files changed, 13 insertions, 18 deletions
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 @@ | |||
7 | 7 | ||
8 | import base | 8 | import base |
9 | import os | 9 | import os |
10 | import parse_signed_off_by | 10 | import patterns |
11 | import parse_upstream_status | ||
12 | import pyparsing | 11 | import pyparsing |
13 | 12 | ||
14 | class TestPatch(base.Base): | 13 | class TestPatch(base.Base): |
15 | 14 | ||
16 | re_cve_pattern = pyparsing.Regex("CVE\-\d{4}\-\d+") | ||
17 | re_cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+") | ||
18 | upstream_status_regex = pyparsing.AtLineStart("+" + "Upstream-Status") | ||
19 | |||
20 | @classmethod | 15 | @classmethod |
21 | def setUpClassLocal(cls): | 16 | def setUpClassLocal(cls): |
22 | cls.newpatches = [] | 17 | cls.newpatches = [] |
@@ -25,16 +20,16 @@ class TestPatch(base.Base): | |||
25 | if patch.path.endswith('.patch') and patch.is_added_file: | 20 | if patch.path.endswith('.patch') and patch.is_added_file: |
26 | cls.newpatches.append(patch) | 21 | cls.newpatches.append(patch) |
27 | 22 | ||
28 | cls.mark = str(parse_signed_off_by.signed_off_by_mark).strip('"') | 23 | cls.mark = str(patterns.signed_off_by_prefix).strip('"') |
29 | 24 | ||
30 | # match PatchSignedOffBy.mark with '+' preceding it | 25 | # match PatchSignedOffBy.mark with '+' preceding it |
31 | cls.prog = parse_signed_off_by.patch_signed_off_by | 26 | cls.prog = patterns.patch_signed_off_by |
32 | 27 | ||
33 | def setUp(self): | 28 | def setUp(self): |
34 | if self.unidiff_parse_error: | 29 | if self.unidiff_parse_error: |
35 | self.skip('Parse error %s' % self.unidiff_parse_error) | 30 | self.skip('Parse error %s' % self.unidiff_parse_error) |
36 | 31 | ||
37 | self.valid_status = ', '.join(parse_upstream_status.upstream_status_nonliteral_valid_status) | 32 | self.valid_status = ', '.join(patterns.upstream_status_nonliteral_valid_status) |
38 | self.standard_format = 'Upstream-Status: <Valid status>' | 33 | self.standard_format = 'Upstream-Status: <Valid status>' |
39 | 34 | ||
40 | # we are just interested in series that introduce CVE patches, thus discard other | 35 | # we are just interested in series that introduce CVE patches, thus discard other |
@@ -50,28 +45,28 @@ class TestPatch(base.Base): | |||
50 | 45 | ||
51 | for newpatch in TestPatch.newpatches: | 46 | for newpatch in TestPatch.newpatches: |
52 | payload = newpatch.__str__() | 47 | payload = newpatch.__str__() |
53 | if not self.upstream_status_regex.search_string(payload): | 48 | if not patterns.upstream_status_regex.search_string(payload): |
54 | self.fail('Added patch file is missing Upstream-Status: <Valid status> in the commit message', | 49 | self.fail('Added patch file is missing Upstream-Status: <Valid status> in the commit message', |
55 | data=[('Standard format', self.standard_format), ('Valid status', self.valid_status)]) | 50 | data=[('Standard format', self.standard_format), ('Valid status', self.valid_status)]) |
56 | for line in payload.splitlines(): | 51 | for line in payload.splitlines(): |
57 | if self.patchmetadata_regex.match(line): | 52 | if self.patchmetadata_regex.match(line): |
58 | continue | 53 | continue |
59 | if self.upstream_status_regex.search_string(line): | 54 | if patterns.upstream_status_regex.search_string(line): |
60 | if parse_upstream_status.inappropriate_status_mark.searchString(line): | 55 | if patterns.inappropriate.searchString(line): |
61 | try: | 56 | try: |
62 | parse_upstream_status.upstream_status_inappropriate_info.parseString(line.lstrip('+')) | 57 | patterns.upstream_status_inappropriate_info.parseString(line.lstrip('+')) |
63 | except pyparsing.ParseException as pe: | 58 | except pyparsing.ParseException as pe: |
64 | self.fail('Upstream-Status is Inappropriate, but no reason was provided', | 59 | self.fail('Upstream-Status is Inappropriate, but no reason was provided', |
65 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')]) | 60 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Inappropriate [reason]')]) |
66 | elif parse_upstream_status.submitted_status_mark.searchString(line): | 61 | elif patterns.submitted.searchString(line): |
67 | try: | 62 | try: |
68 | parse_upstream_status.upstream_status_submitted_info.parseString(line.lstrip('+')) | 63 | patterns.upstream_status_submitted_info.parseString(line.lstrip('+')) |
69 | except pyparsing.ParseException as pe: | 64 | except pyparsing.ParseException as pe: |
70 | self.fail('Upstream-Status is Submitted, but it is not mentioned where', | 65 | self.fail('Upstream-Status is Submitted, but it is not mentioned where', |
71 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')]) | 66 | data=[('Current', pe.pstr), ('Standard format', 'Upstream-Status: Submitted [where]')]) |
72 | else: | 67 | else: |
73 | try: | 68 | try: |
74 | parse_upstream_status.upstream_status.parseString(line.lstrip('+')) | 69 | patterns.upstream_status.parseString(line.lstrip('+')) |
75 | except pyparsing.ParseException as pe: | 70 | except pyparsing.ParseException as pe: |
76 | self.fail('Upstream-Status is in incorrect format', | 71 | self.fail('Upstream-Status is in incorrect format', |
77 | data=[('Current', pe.pstr), ('Standard format', self.standard_format), ('Valid status', self.valid_status)]) | 72 | data=[('Current', pe.pstr), ('Standard format', self.standard_format), ('Valid status', self.valid_status)]) |
@@ -92,10 +87,10 @@ class TestPatch(base.Base): | |||
92 | 87 | ||
93 | def test_cve_tag_format(self): | 88 | def test_cve_tag_format(self): |
94 | for commit in TestPatch.commits: | 89 | for commit in TestPatch.commits: |
95 | if self.re_cve_pattern.search_string(commit.shortlog) or self.re_cve_pattern.search_string(commit.commit_message): | 90 | if patterns.cve.search_string(commit.shortlog) or patterns.cve.search_string(commit.commit_message): |
96 | tag_found = False | 91 | tag_found = False |
97 | for line in commit.payload.splitlines(): | 92 | for line in commit.payload.splitlines(): |
98 | if self.re_cve_payload_tag.search_string(line): | 93 | if patterns.cve_payload_tag.search_string(line): |
99 | tag_found = True | 94 | tag_found = True |
100 | break | 95 | break |
101 | if not tag_found: | 96 | if not tag_found: |