summaryrefslogtreecommitdiffstats
path: root/meta/lib/patchtest/tests/test_patch.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/patchtest/tests/test_patch.py')
-rw-r--r--meta/lib/patchtest/tests/test_patch.py31
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
8import base 8import base
9import os 9import os
10import parse_signed_off_by 10import patterns
11import parse_upstream_status
12import pyparsing 11import pyparsing
13 12
14class TestPatch(base.Base): 13class 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: