Skip to content

Commit 8d8615e

Browse files
committed
fix: format list comprehensions for better readability in get_pr_commit_messages() and related tests
1 parent 85f23c7 commit 8d8615e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def get_pr_commit_messages() -> list[str]:
5454
check=False,
5555
)
5656
if result.returncode == 0 and result.stdout:
57-
return [m.rstrip("\n") for m in result.stdout.split("\x00") if m.rstrip("\n")]
57+
return [
58+
m.rstrip("\n") for m in result.stdout.split("\x00") if m.rstrip("\n")
59+
]
5860
except Exception:
5961
pass
6062
return []

main_test.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Unit tests for main.py"""
2+
23
import io
34
import json
45
import os
@@ -16,7 +17,9 @@
1617
class TestBuildCheckArgs(unittest.TestCase):
1718
def test_all_true(self):
1819
result = main.build_check_args("true", "true", "true", "true")
19-
self.assertEqual(result, ["--message", "--branch", "--author-name", "--author-email"])
20+
self.assertEqual(
21+
result, ["--message", "--branch", "--author-name", "--author-email"]
22+
)
2023

2124
def test_all_false(self):
2225
result = main.build_check_args("false", "false", "false", "false")
@@ -62,7 +65,11 @@ def test_single_message_fail(self):
6265
self.assertEqual(rc, 1)
6366

6467
def test_multiple_messages_partial_failure(self):
65-
results = [MagicMock(returncode=0), MagicMock(returncode=1), MagicMock(returncode=0)]
68+
results = [
69+
MagicMock(returncode=0),
70+
MagicMock(returncode=1),
71+
MagicMock(returncode=0),
72+
]
6673
with patch("main.subprocess.run", side_effect=results):
6774
rc = main.run_pr_message_checks(["ok", "bad", "ok"], self._make_file())
6875
self.assertEqual(rc, 1)
@@ -125,7 +132,9 @@ def test_rc_one(self):
125132
def test_command_contains_all_args(self):
126133
mock_result = MagicMock(returncode=0)
127134
with patch("main.subprocess.run", return_value=mock_result) as mock_run:
128-
main.run_default_checks(["--message", "--branch", "--author-name"], io.StringIO())
135+
main.run_default_checks(
136+
["--message", "--branch", "--author-name"], io.StringIO()
137+
)
129138
called_cmd = mock_run.call_args[0][0]
130139
self.assertEqual(
131140
called_cmd,
@@ -152,6 +161,7 @@ def setUp(self):
152161
# Ensure result.txt is written to a temp location
153162
self._orig_dir = os.getcwd()
154163
import tempfile
164+
155165
self._tmpdir = tempfile.mkdtemp()
156166
os.chdir(self._tmpdir)
157167

@@ -300,6 +310,7 @@ def test_exception_returns_empty(self):
300310
class TestReadResultFile(unittest.TestCase):
301311
def setUp(self):
302312
import tempfile
313+
303314
self._orig_dir = os.getcwd()
304315
self._tmpdir = tempfile.mkdtemp()
305316
os.chdir(self._tmpdir)
@@ -335,6 +346,7 @@ def test_trailing_whitespace_stripped(self):
335346
class TestAddJobSummary(unittest.TestCase):
336347
def setUp(self):
337348
import tempfile
349+
338350
self._orig_dir = os.getcwd()
339351
self._tmpdir = tempfile.mkdtemp()
340352
os.chdir(self._tmpdir)
@@ -387,6 +399,7 @@ def test_no_event_path(self):
387399

388400
def test_same_repo_not_fork(self):
389401
import tempfile
402+
390403
event = {
391404
"pull_request": {
392405
"head": {"repo": {"full_name": "owner/repo"}},
@@ -403,6 +416,7 @@ def test_same_repo_not_fork(self):
403416

404417
def test_different_repo_is_fork(self):
405418
import tempfile
419+
406420
event = {
407421
"pull_request": {
408422
"head": {"repo": {"full_name": "fork-owner/repo"}},
@@ -419,6 +433,7 @@ def test_different_repo_is_fork(self):
419433

420434
def test_json_parse_failure_returns_false(self):
421435
import tempfile
436+
422437
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
423438
f.write("not valid json{{{")
424439
event_path = f.name
@@ -470,6 +485,7 @@ def test_empty_string_result_text_no_print(self):
470485
class TestMain(unittest.TestCase):
471486
def setUp(self):
472487
import tempfile
488+
473489
self._orig_dir = os.getcwd()
474490
self._tmpdir = tempfile.mkdtemp()
475491
os.chdir(self._tmpdir)

0 commit comments

Comments
 (0)