@@ -126,38 +126,52 @@ def test_empty_list(self):
126126 self .assertEqual (rc , 0 )
127127 mock_run .assert_not_called ()
128128
129- def test_second_and_later_messages_use_no_banner (self ):
129+ def test_first_failure_keeps_banner_and_later_failures_use_no_banner (self ):
130130 results = [
131+ MagicMock (returncode = 0 , stdout = "" ),
131132 MagicMock (returncode = 1 , stdout = "Commit rejected.\n " ),
132133 MagicMock (returncode = 1 , stdout = "Type subject_imperative check failed\n " ),
133134 ]
134135 with patch ("main.subprocess.run" , side_effect = results ) as mock_run :
135- main .run_pr_message_checks (["bad first" , "bad second" ], io .StringIO ())
136+ main .run_pr_message_checks (["ok first" , "bad second" , "bad third " ], io .StringIO ())
136137
137138 self .assertEqual (
138139 mock_run .call_args_list [0 ][0 ][0 ], ["commit-check" , "--message" ]
139140 )
140141 self .assertEqual (
141142 mock_run .call_args_list [1 ][0 ][0 ],
143+ ["commit-check" , "--message" ],
144+ )
145+ self .assertEqual (
146+ mock_run .call_args_list [2 ][0 ][0 ],
142147 ["commit-check" , "--message" , "--no-banner" ],
143148 )
144149
145- def test_second_message_prefix_uses_separator (self ):
150+ def test_later_failure_prefix_uses_short_separator_without_extra_blank_lines (self ):
146151 results = [
152+ MagicMock (returncode = 0 , stdout = "" ),
147153 MagicMock (returncode = 1 , stdout = "Commit rejected.\n " ),
148- MagicMock (returncode = 1 , stdout = "Type subject_imperative check failed\n " ),
154+ MagicMock (
155+ returncode = 1 ,
156+ stdout = (
157+ "Type subject_imperative check failed ==> bad third\n "
158+ "Commit message should use imperative mood\n "
159+ "Suggest: Use imperative mood\n \n "
160+ ),
161+ ),
149162 ]
150163 result_file = io .StringIO ()
151164 with patch ("main.subprocess.run" , side_effect = results ):
152- main .run_pr_message_checks (["bad first" , "bad second" ], result_file )
165+ main .run_pr_message_checks (["ok first" , "bad second" , "bad third " ], result_file )
153166
154167 output = result_file .getvalue ()
155- self .assertIn ("\n --- Commit 1/2 : bad first \n Commit rejected.\n " , output )
168+ self .assertIn ("--- Commit 2/3 : bad second \n Commit rejected.\n " , output )
156169 self .assertIn (
157- f"{ main .COMMIT_SECTION_SEPARATOR } --- Commit 2/2 : bad second \n " ,
170+ f"{ main .COMMIT_SECTION_SEPARATOR } --- Commit 3/3 : bad third \n " ,
158171 output ,
159172 )
160- self .assertIn ("Type subject_imperative check failed\n " , output )
173+ self .assertNotIn ("------------------------------------------------------------------------" , output )
174+ self .assertNotIn ("\n \n \n " , output )
161175
162176
163177class TestRunOtherChecks (unittest .TestCase ):
0 commit comments