@@ -40,116 +40,107 @@ class TestPatch(base.Base):
self.skip('No new CVE patches introduced')
def test_upstream_status_presence_format(self):
- if not TestPatch.newpatches:
- self.skip("There are no new software patches, no reason to test Upstream-Status presence/format")
+ if not TestPatch.newpatches:
+ self.skip("There are no new software patches, no reason to test Upstream-Status presence/format")
- for newpatch in TestPatch.newpatches:
- payload = newpatch.__str__()
- lines = payload.splitlines()
+ for newpatch in TestPatch.newpatches:
+ payload = newpatch.__str__()
+ lines = payload.splitlines()
- scissors_index = None
- for idx, line in enumerate(lines):
- if line.lstrip("+") == "---":
- scissors_index = idx
- break
+ scissors_index = None
+ for idx, line in enumerate(lines):
+ if line.lstrip("+") == "---":
+ scissors_index = idx
+ break
- header_has_upstream = False
- body_has_upstream = False
+ header_has_upstream = False
+ body_has_upstream = False
- for idx, line in enumerate(lines):
- if not patchtest_patterns.upstream_status_regex.search_string(line):
- continue
+ for idx, line in enumerate(lines):
+ if not patchtest_patterns.upstream_status_regex.search_string(line):
+ continue
- if scissors_index is not None and idx > scissors_index:
- body_has_upstream = True
- else:
- header_has_upstream = True
-
- if not header_has_upstream:
- if body_has_upstream:
- self.skip(
- 'Upstream-Status is present only after the patch scissors. '
- 'It may be ignored by git and lost during patch refresh. '
- 'Consider placing it before the scissors line.',
- data=[
- ("Standard format", self.standard_format),
- ("Valid status", self.valid_status),
- ],
- )
- else:
+ if scissors_index is not None and idx > scissors_index:
+ body_has_upstream = True
+ else:
+ header_has_upstream = True
+
+ if not header_has_upstream:
+ if body_has_upstream:
+ print(
+ 'WARNING: Upstream-Status is present only after the patch scissors. '
+ 'It may be ignored by git and lost during patch refresh. '
+ 'Consider placing it before the scissors line.'
+ )
+ else:
+ self.fail(
+ "Added patch file is missing Upstream-Status: <Valid status> in the commit message",
+ data=[
+ ("Standard format", self.standard_format),
+ ("Valid status", self.valid_status),
+ ],
+ )
+
+ for idx, line in enumerate(lines):
+ if patchtest_patterns.patchmetadata_regex.match(line):
+ continue
+
+ if not patchtest_patterns.upstream_status_regex.search_string(line):
+ continue
+
+ if scissors_index is not None and idx > scissors_index:
+ print(
+ 'WARNING: Upstream-Status found after patch scissors. '
+ 'It may be ignored by git and lost during patch refresh. '
+ 'Consider placing it before the scissors line.'
+ )
+ continue
+
+ if patchtest_patterns.inappropriate.searchString(line):
+ try:
+ patchtest_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 patchtest_patterns.submitted.searchString(line):
+ try:
+ patchtest_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:
+ patchtest_patterns.upstream_status.parseString(line.lstrip("+"))
+ except pyparsing.ParseException as pe:
self.fail(
- "Added patch file is missing Upstream-Status: <Valid status> in the commit message",
+ "Upstream-Status is in incorrect format",
data=[
+ ("Current", pe.pstr),
("Standard format", self.standard_format),
("Valid status", self.valid_status),
],
)
- for idx, line in enumerate(lines):
- if patchtest_patterns.patchmetadata_regex.match(line):
- continue
-
- if not patchtest_patterns.upstream_status_regex.search_string(line):
- continue
-
- if scissors_index is not None and idx > scissors_index:
- self.skip(
- 'Upstream-Status found after patch scissors. '
- 'It may be ignored by git and lost during patch refresh. '
- 'Consider placing it before the scissors line.',
- data=[
- ("Current", line.lstrip("+")),
- ("Standard format", self.standard_format),
- ("Valid status", self.valid_status),
- ],
- )
-
-
- if patchtest_patterns.inappropriate.searchString(line):
- try:
- patchtest_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 patchtest_patterns.submitted.searchString(line):
- try:
- patchtest_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:
- patchtest_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),
- ],
- )
-
def test_signed_off_by_presence(self):
if not TestPatch.newpatches:
self.skip("There are no new software patches, no reason to test %s presence" % PatchSignedOffBy.mark)
Detect cases where Upstream-Status is placed after the patch scissors ("---") and emit a warning instead of failing. Such placement may be intentional in some workflows to avoid including the tag in upstream commits. Signed-off-by: Aditya GS <adityags2004@gmail.com> --- meta/lib/patchtest/tests/test_patch.py | 187 ++++++++++++------------- 1 file changed, 89 insertions(+), 98 deletions(-)