Skip to content

Commit

Permalink
patchtest2/tests: add test_mbox_shortlog_length, run black
Browse files Browse the repository at this point in the history
Signed-off-by: Trevor Gamblin <[email protected]>
  • Loading branch information
threexc committed Feb 7, 2025
1 parent 6fa7974 commit e933d82
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/patchtest2/tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def __init__(self, target_repo, series):
"shortlog_format",
self._results(test_mbox_shortlog_format),
),
(
"shortlog_length",
self._results(test_mbox_shortlog_length),
),
(
"has_commit_message",
self._results(test_mbox_has_commit_message),
Expand Down Expand Up @@ -111,6 +115,24 @@ def test_mbox_shortlog_format(target):
return PatchtestResult(target.subject, test_name, result, reason)


def test_mbox_shortlog_length(target):
shortlog = re.sub("^(\[.*?\])+ ", "", target.shortlog)
shortlog_len = len(shortlog)
test_name = "test_mbox_shortlog_length"
result = "PASS"
reason = f"Edit shortlog so that it is {patterns.mbox_shortlog_maxlength} characters or less (currently {shortlog_len} characters)"

print(target.shortlog)
if shortlog.startswith('Revert "'):
result = "SKIP"
reason = "No need to test revert patches"
else:
if shortlog_len > patterns.mbox_shortlog_maxlength:
result = "FAIL"

return PatchtestResult(target.subject, test_name, result, reason)


def test_mbox_has_commit_message(target):
test_name = "test_mbox_has_commit_message"
result = "PASS"
Expand All @@ -129,10 +151,11 @@ def test_mbox_has_commit_message(target):

return PatchtestResult(target.subject, test_name, result, reason)


def test_mbox_unidiff_parse_error(target):
test_name = "test_mbox_unidiff_parse_error"
result = "PASS"
reason = f"Patch \"{target.shortlog}\" contains malformed diff lines."
reason = f'Patch "{target.shortlog}" contains malformed diff lines.'

try:
diff = unidiff.PatchSet.from_string(target.data.as_string())
Expand Down

0 comments on commit e933d82

Please sign in to comment.