1414
1515os .environ .setdefault ("GITHUB_STEP_SUMMARY" , "/tmp/step_summary.txt" )
1616
17- import main # noqa: E402
17+ import main
1818
1919#: The report footer names the installed commit-check version, which differs
2020#: between a contributor's machine and CI. Golden tests pin it so they assert on
@@ -313,7 +313,7 @@ def test_invalid_json_returns_none(self):
313313class TestRunCheckJson (unittest .TestCase ):
314314 def test_parses_json_output (self ):
315315 mock_result = MagicMock (returncode = 0 , stdout = json_output (make_check ("branch" )))
316- with patch ("main.subprocess.run" , return_value = mock_result ) as mock_run :
316+ with patch ("main.subprocess.run" , return_value = mock_result ):
317317 rc , data , raw = main .run_check_json (["--branch" ])
318318 self .assertEqual (rc , 0 )
319319 self .assertEqual (data ["status" ], "pass" )
@@ -757,7 +757,7 @@ def test_pr_title_check_runs_when_enabled(self):
757757 ) as mock_scope ,
758758 patch ("main.run_other_checks" , return_value = []),
759759 ):
760- rc , results = main .run_commit_check ()
760+ rc , _results = main .run_commit_check ()
761761 self .assertEqual (rc , 0 )
762762 mock_scope .assert_called_once_with (
763763 "PR title" , ["--message" ], input_text = "feat: a feature"
@@ -775,7 +775,7 @@ def test_pr_title_failure_propagates(self):
775775 patch ("main.check_scope" , return_value = fail_scope ("PR title" )),
776776 patch ("main.run_other_checks" , return_value = []),
777777 ):
778- rc , results = main .run_commit_check ()
778+ rc , _results = main .run_commit_check ()
779779 self .assertEqual (rc , 1 )
780780
781781 def test_pr_title_skipped_outside_pr_context (self ):
@@ -789,7 +789,7 @@ def test_pr_title_skipped_outside_pr_context(self):
789789 patch ("main.get_pr_title" ) as mock_title ,
790790 patch ("main.run_other_checks" , return_value = []),
791791 ):
792- rc , results = main .run_commit_check ()
792+ rc , _results = main .run_commit_check ()
793793 self .assertEqual (rc , 0 )
794794 mock_title .assert_not_called ()
795795
@@ -825,7 +825,7 @@ def test_non_pr_message_check_uses_commit_message_scope(self):
825825 ) as mock_scope ,
826826 patch ("main.run_other_checks" , return_value = []),
827827 ):
828- rc , results = main .run_commit_check ()
828+ rc , _results = main .run_commit_check ()
829829 self .assertEqual (rc , 0 )
830830 mock_pr .assert_not_called ()
831831 # HEAD is the commit that was checked, so the scope names it too.
@@ -882,7 +882,7 @@ def test_pr_without_enumerable_commits_warns_and_checks_head(self):
882882 ) as mock_scope ,
883883 patch ("main.run_other_checks" , return_value = []),
884884 ):
885- rc , results , output = self ._run_capturing_stdout ()
885+ rc , _results , output = self ._run_capturing_stdout ()
886886 self .assertEqual (rc , 0 )
887887 self .assertIn (self .SHALLOW_PR_WARNING , output )
888888 mock_scope .assert_called_once_with ("Commit message" , ["--message" ], sha = "" )
@@ -1162,9 +1162,7 @@ def _run(self, total, api_commits, head="b2"):
11621162 for sha , msg in api_commits
11631163 ]
11641164 github_module = MagicMock ()
1165- github_module .Github .return_value .get_repo .return_value .get_pull .return_value = (
1166- pull
1167- )
1165+ github_module .Github .return_value .get_repo .return_value .get_pull .return_value = pull
11681166 env = {
11691167 "GITHUB_TOKEN" : "token" ,
11701168 "GITHUB_REPOSITORY" : "owner/repo" ,
@@ -1554,7 +1552,7 @@ def test_annotation_payload_is_escaped(self):
15541552 ],
15551553 )
15561554 output = self ._run ([scope ])
1557- annotation = [ ln for ln in output .splitlines () if ln .startswith ("::error" )][ 0 ]
1555+ annotation = next ( ln for ln in output .splitlines () if ln .startswith ("::error" ))
15581556 self .assertNotIn ("\n " , annotation .removeprefix ("::error " ))
15591557 self .assertIn ("first line" , annotation )
15601558
@@ -3391,17 +3389,19 @@ def test_the_two_streams_are_read_separately(self):
33913389 mock_result = MagicMock (returncode = 0 , stdout = "{}" , stderr = "" )
33923390 with patch ("main.subprocess.run" , return_value = mock_result ) as mock_run :
33933391 main .run_check_json (["--branch" ])
3394- self .assertIs (mock_run .call_args [1 ]["stderr " ], main . subprocess . PIPE )
3392+ self .assertIs (mock_run .call_args [1 ]["capture_output " ], True )
33953393
33963394 def test_a_notice_does_not_break_the_json (self ):
33973395 mock_result = MagicMock (
33983396 returncode = 0 ,
33993397 stdout = json_output (make_check ("branch" )),
34003398 stderr = self .NOTICE ,
34013399 )
3402- with patch ("main.subprocess.run" , return_value = mock_result ):
3403- with patch .object (sys , "stderr" , io .StringIO ()):
3404- rc , data , raw = main .run_check_json (["--branch" ])
3400+ with (
3401+ patch ("main.subprocess.run" , return_value = mock_result ),
3402+ patch .object (sys , "stderr" , io .StringIO ()),
3403+ ):
3404+ rc , data , _raw = main .run_check_json (["--branch" ])
34053405 self .assertEqual (rc , 0 )
34063406 self .assertIsNotNone (data )
34073407 self .assertEqual (data ["status" ], "pass" )
@@ -3410,9 +3410,11 @@ def test_a_notice_does_not_break_the_json(self):
34103410
34113411 def test_a_notice_alone_does_not_fail_the_scope (self ):
34123412 mock_result = MagicMock (returncode = 0 , stdout = json_output (), stderr = self .NOTICE )
3413- with patch ("main.subprocess.run" , return_value = mock_result ):
3414- with patch .object (sys , "stderr" , io .StringIO ()):
3415- scope = main .check_scope ("Branch" , ["--branch" ])
3413+ with (
3414+ patch ("main.subprocess.run" , return_value = mock_result ),
3415+ patch .object (sys , "stderr" , io .StringIO ()),
3416+ ):
3417+ scope = main .check_scope ("Branch" , ["--branch" ])
34163418 self .assertEqual (scope .status , "pass" )
34173419 self .assertEqual (scope .raw_text , "" )
34183420
@@ -3421,10 +3423,12 @@ def test_notices_reach_the_job_log_once(self):
34213423 returncode = 0 , stdout = json_output (make_check ("branch" )), stderr = self .NOTICE
34223424 )
34233425 fake_err = io .StringIO ()
3424- with patch ("main.subprocess.run" , return_value = mock_result ):
3425- with patch .object (sys , "stderr" , fake_err ):
3426- for _ in range (3 ):
3427- main .run_check_json (["--branch" ])
3426+ with (
3427+ patch ("main.subprocess.run" , return_value = mock_result ),
3428+ patch .object (sys , "stderr" , fake_err ),
3429+ ):
3430+ for _ in range (3 ):
3431+ main .run_check_json (["--branch" ])
34283432 printed = fake_err .getvalue ()
34293433 self .assertIn ("--branch requested but no branch rules are configured" , printed )
34303434 # Once, not once per scope and per commit in the pull request.
@@ -3434,9 +3438,11 @@ def test_unparsable_output_keeps_both_streams(self):
34343438 mock_result = MagicMock (
34353439 returncode = 2 , stdout = "" , stderr = "Error: cchk.toml: Expected ']'\n "
34363440 )
3437- with patch ("main.subprocess.run" , return_value = mock_result ):
3438- with patch .object (sys , "stderr" , io .StringIO ()):
3439- scope = main .check_scope ("Branch" , ["--branch" ])
3441+ with (
3442+ patch ("main.subprocess.run" , return_value = mock_result ),
3443+ patch .object (sys , "stderr" , io .StringIO ()),
3444+ ):
3445+ scope = main .check_scope ("Branch" , ["--branch" ])
34403446 self .assertEqual (scope .status , "fail" )
34413447 self .assertIn ("Expected ']'" , scope .raw_text )
34423448
0 commit comments