Skip to content

Commit 683da80

Browse files
committed
patchtest2: use black to reformat
Signed-off-by: Trevor Gamblin <[email protected]>
1 parent 3c65df1 commit 683da80

File tree

3 files changed

+53
-36
lines changed

3 files changed

+53
-36
lines changed

src/patchtest2/mbox.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from dataclasses import dataclass
1919

20+
2021
# From: https://stackoverflow.com/questions/59681461/read-a-big-mbox-file-with-python
2122
class MboxReader:
2223
def __init__(self, filepath):
@@ -56,17 +57,20 @@ def __init__(self, data):
5657
self.diff = self.split_body[1]
5758
# get the shortlog, but make sure to exclude bracketed prefixes
5859
# before the colon, and remove extra whitespace/newlines
59-
self.shortlog = self.subject[self.subject.find(']', 0,
60-
self.subject.find(':')) + 1:].replace('\n', '').strip()
60+
self.shortlog = (
61+
self.subject[self.subject.find("]", 0, self.subject.find(":")) + 1 :]
62+
.replace("\n", "")
63+
.strip()
64+
)
65+
6166

6267
class PatchSeries:
6368
def __init__(self, filepath):
6469
with MboxReader(filepath) as mbox:
6570
# Keep raw copies of messages in a list
6671
self.messages = [message for message in mbox]
6772
# Get a copy of each message's core patch contents
68-
self.patchdata = [Patch(message) for message in
69-
self.messages]
73+
self.patchdata = [Patch(message) for message in self.messages]
7074

7175
assert self.patchdata
7276
self.patch_count = len(self.patchdata)
@@ -121,6 +125,7 @@ def valid_branch(branch):
121125

122126
return not invalid
123127

128+
124129
class TargetRepo:
125130
def __init__(self, repodir):
126131
self.repodir = repodir
@@ -147,13 +152,12 @@ def can_be_merged(self, patchfile):
147152
except git.exc.GitCommandError as ce:
148153
result = ce
149154
self.abort_merge()
150-
155+
151156
return result
152157

153158
def merge_patch(self, patchfile):
154159
self.repo.git.execute(
155-
["git", "am", "--keep-cr", os.path.abspath(patchfile)],
156-
with_exceptions=True
160+
["git", "am", "--keep-cr", os.path.abspath(patchfile)], with_exceptions=True
157161
)
158162

159163
def abort_merge(self):

src/patchtest2/tests/core.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,60 @@
11
import patchtest2.patterns as patterns
22
import pyparsing
33

4+
45
class PatchtestResult:
56
def __init__(self, patch, testname, result, reason):
67
self.patch = patch
78
self.testname = testname
89
self.result = result
910
self.reason = reason
1011
self.pass_string = f"{self.result}: {self.testname} on {self.patch}"
11-
self.skip_or_fail_string = f"{self.result}: {self.testname} on {self.patch} ({self.reason})"
12+
self.skip_or_fail_string = (
13+
f"{self.result}: {self.testname} on {self.patch} ({self.reason})"
14+
)
1215

1316
def __str__(self):
1417
if self.result == "PASS":
1518
return self.pass_string
1619
else:
1720
return self.skip_or_fail_string
1821

22+
1923
class PatchtestResults:
2024
def __init__(self, target_repo, series):
2125
self.target_repo = target_repo
2226
self.series = series
2327
self.mbox_results = dict(
24-
[
25-
('signed_off_by', [test_mbox_signed_off_by_presence(patch) for
26-
patch in self.series.patchdata]),
27-
('shortlog_format', [test_mbox_shortlog_format(patch) for patch
28-
in self.series.patchdata]),
29-
('commit_message_presence',
30-
[test_mbox_commit_message_presence(patch) for patch in
31-
self.series.patchdata]),
32-
]
33-
)
28+
[
29+
(
30+
"signed_off_by",
31+
[
32+
test_mbox_signed_off_by_presence(patch)
33+
for patch in self.series.patchdata
34+
],
35+
),
36+
(
37+
"shortlog_format",
38+
[
39+
test_mbox_shortlog_format(patch)
40+
for patch in self.series.patchdata
41+
],
42+
),
43+
(
44+
"commit_message_presence",
45+
[
46+
test_mbox_commit_message_presence(patch)
47+
for patch in self.series.patchdata
48+
],
49+
),
50+
]
51+
)
3452

3553
def print_mbox_results(self, tag):
3654
for testresult in self.mbox_results[tag]:
3755
print(testresult)
3856

57+
3958
# test_for_pattern()
4059
# @pattern: a pyparsing regex object
4160
# @string: a string (patch subject, commit message, author, etc. to
@@ -46,15 +65,13 @@ def test_for_pattern(pattern, string):
4665
else:
4766
return "FAIL"
4867

68+
4969
def test_mbox_signed_off_by_presence(target):
5070
test_name = "test_mbox_signed_off_by_presence"
51-
result = test_for_pattern(patterns.signed_off_by,
52-
target.commit_message)
71+
result = test_for_pattern(patterns.signed_off_by, target.commit_message)
5372
reason = "mbox was missing a signed-off-by tag"
54-
return PatchtestResult(target.subject,
55-
test_name,
56-
result,
57-
reason)
73+
return PatchtestResult(target.subject, test_name, result, reason)
74+
5875

5976
def test_mbox_shortlog_format(target):
6077
test_name = "test_mbox_shortlog_format"
@@ -74,10 +91,8 @@ def test_mbox_shortlog_format(target):
7491
result = "FAIL"
7592
reason = 'Commit shortlog (first line of commit message) should follow the format "<target>: <summary>"'
7693

77-
return PatchtestResult(target.subject,
78-
test_name,
79-
result,
80-
reason)
94+
return PatchtestResult(target.subject, test_name, result, reason)
95+
8196

8297
def test_mbox_commit_message_presence(target):
8398
test_name = "test_mbox_commit_message_presence"
@@ -86,10 +101,7 @@ def test_mbox_commit_message_presence(target):
86101

87102
# Check to see if there is content before the signoff
88103
match = patterns.endcommit_messages_regex.search(target.commit_message)
89-
if not target.commit_message[:match.start()]:
104+
if not target.commit_message[: match.start()]:
90105
result = "FAIL"
91106

92-
return PatchtestResult(target.subject,
93-
test_name,
94-
result,
95-
reason)
107+
return PatchtestResult(target.subject, test_name, result, reason)

src/patchtest2/tests/patchtest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from patchtest2.mbox import PatchSeries, TargetRepo
33
from patchtest2.tests.core import PatchtestResults
44

5+
56
def run():
67
parser = PatchtestParser.get_parser()
78
args = parser.parse_args()
89
target_repo = TargetRepo(args.repodir)
910
series = PatchSeries(args.patch_path)
1011
results = PatchtestResults(target_repo, series)
1112

12-
results.print_mbox_results('signed_off_by')
13-
results.print_mbox_results('shortlog_format')
14-
results.print_mbox_results('commit_message_presence')
13+
results.print_mbox_results("signed_off_by")
14+
results.print_mbox_results("shortlog_format")
15+
results.print_mbox_results("commit_message_presence")

0 commit comments

Comments
 (0)