@@ -18,7 +18,11 @@ class TestCLIGetArgs:
1818 @patch (
1919 "argparse.ArgumentParser.parse_args" ,
2020 return_value = MagicMock (
21- commit_message = "commit message" , file = None , hash = None , from_hash = None
21+ commit_message = "commit message" ,
22+ file = None ,
23+ hash = None ,
24+ from_hash = None ,
25+ quiet = None ,
2226 ),
2327 )
2428 def test__get_args__with_commit_message (self , * _ ):
@@ -27,6 +31,7 @@ def test__get_args__with_commit_message(self, *_):
2731 assert args .file is None
2832 assert args .hash is None
2933 assert args .from_hash is None
34+ assert args .quiet is None
3035
3136 @patch (
3237 "argparse.ArgumentParser.parse_args" ,
@@ -88,6 +93,7 @@ class TestCLIMain:
8893 hash = None ,
8994 from_hash = None ,
9095 skip_detail = False ,
96+ quiet = False ,
9197 ),
9298 )
9399 @patch ("sys.stdout.write" )
@@ -107,6 +113,7 @@ def test__main__valid_commit_message(
107113 hash = None ,
108114 from_hash = None ,
109115 skip_detail = True ,
116+ quiet = False ,
110117 ),
111118 )
112119 @patch ("sys.stdout.write" )
@@ -126,6 +133,7 @@ def test__main__valid_commit_message_using_skip_detail(
126133 hash = None ,
127134 from_hash = None ,
128135 skip_detail = False ,
136+ quiet = False ,
129137 ),
130138 )
131139 @patch ("sys.stderr.write" )
@@ -154,6 +162,7 @@ def test__main__invalid_commit_message(
154162 hash = None ,
155163 from_hash = None ,
156164 skip_detail = True ,
165+ quiet = False ,
157166 ),
158167 )
159168 @patch ("sys.stderr.write" )
@@ -177,7 +186,7 @@ def test__main__invalid_commit_message_using_skip_detail(
177186
178187 @patch (
179188 "commitlint.cli.get_args" ,
180- return_value = MagicMock (file = "path/to/file.txt" , skip_detail = False ),
189+ return_value = MagicMock (file = "path/to/file.txt" , skip_detail = False , quiet = False ),
181190 )
182191 @patch ("sys.stdout.write" )
183192 @patch ("builtins.open" , mock_open (read_data = "feat: valid commit message" ))
@@ -187,7 +196,7 @@ def test__main__valid_commit_message_with_file(self, mock_stdout_write, *_):
187196
188197 @patch (
189198 "commitlint.cli.get_args" ,
190- return_value = MagicMock (file = "path/to/file.txt" , skip_detail = False ),
199+ return_value = MagicMock (file = "path/to/file.txt" , skip_detail = False , quiet = False ),
191200 )
192201 @patch ("sys.stderr.write" )
193202 @patch ("sys.exit" )
@@ -209,7 +218,9 @@ def test__main__invalid_commit_message_with_file(
209218
210219 @patch (
211220 "commitlint.cli.get_args" ,
212- return_value = MagicMock (file = None , hash = "commit_hash" , skip_detail = False ),
221+ return_value = MagicMock (
222+ file = None , hash = "commit_hash" , skip_detail = False , quiet = False
223+ ),
213224 )
214225 @patch ("commitlint.cli.get_commit_message_of_hash" )
215226 @patch ("sys.stdout.write" )
@@ -222,7 +233,9 @@ def test__main__valid_commit_message_with_hash(
222233
223234 @patch (
224235 "commitlint.cli.get_args" ,
225- return_value = MagicMock (file = None , hash = "commit_hash" , skip_detail = False ),
236+ return_value = MagicMock (
237+ file = None , hash = "commit_hash" , skip_detail = False , quiet = False
238+ ),
226239 )
227240 @patch ("commitlint.cli.get_commit_message_of_hash" )
228241 @patch ("sys.stderr.write" )
@@ -251,6 +264,7 @@ def test__main__invalid_commit_message_with_hash(
251264 from_hash = "start_commit_hash" ,
252265 to_hash = "end_commit_hash" ,
253266 skip_detail = False ,
267+ quiet = False ,
254268 ),
255269 )
256270 @patch ("commitlint.cli.get_commit_messages_of_hash_range" )
@@ -273,6 +287,7 @@ def test__main__valid_commit_message_with_hash_range(
273287 from_hash = "invalid_start_hash" ,
274288 to_hash = "end_commit_hash" ,
275289 skip_detail = False ,
290+ quiet = False ,
276291 ),
277292 )
278293 @patch ("sys.stderr.write" )
@@ -308,3 +323,101 @@ def test__main__handle_exceptions(
308323 main ()
309324 mock_sys_exit .assert_called_with (1 )
310325 mock_stderr_write .assert_called_with ("Test message\n " )
326+
327+ @patch (
328+ "commitlint.cli.get_args" ,
329+ return_value = MagicMock (
330+ commit_message = "Invalid commit message" ,
331+ file = None ,
332+ hash = None ,
333+ from_hash = None ,
334+ skip_detail = False ,
335+ quiet = True ,
336+ ),
337+ )
338+ @patch ("sys.stdout.write" )
339+ @patch ("sys.stderr.write" )
340+ @patch ("sys.exit" )
341+ def test__main__quiet_option_with_invalid_commit_message (
342+ self , mock_sys_exit , mock_stderr_write , mock_stdout_write , * _
343+ ):
344+ main ()
345+ mock_stderr_write .assert_not_called ()
346+ mock_stdout_write .assert_not_called ()
347+
348+ @patch (
349+ "commitlint.cli.get_args" ,
350+ return_value = MagicMock (
351+ commit_message = "feat: valid commit message" ,
352+ file = None ,
353+ hash = None ,
354+ from_hash = None ,
355+ skip_detail = False ,
356+ quiet = True ,
357+ ),
358+ )
359+ @patch ("sys.stdout.write" )
360+ @patch ("sys.stderr.write" )
361+ @patch ("sys.exit" )
362+ def test__main__quiet_option_with_valid_commit_message (
363+ self , mock_sys_exit , mock_stderr_write , mock_stdout_write , * _
364+ ):
365+ main ()
366+ mock_stderr_write .assert_not_called ()
367+ mock_stdout_write .assert_not_called ()
368+ mock_sys_exit .assert_not_called ()
369+
370+ @patch (
371+ "commitlint.cli.get_args" ,
372+ return_value = MagicMock (
373+ file = None ,
374+ hash = None ,
375+ from_hash = "start_commit_hash" ,
376+ to_hash = "end_commit_hash" ,
377+ skip_detail = False ,
378+ quiet = True ,
379+ ),
380+ )
381+ @patch ("commitlint.cli.get_commit_messages_of_hash_range" )
382+ @patch ("sys.stdout.write" )
383+ def test__valid_commit_message_with_hash_range_in_quiet (
384+ self , mock_stdout_write , mock_get_commit_messages , * _
385+ ):
386+ mock_get_commit_messages .return_value = [
387+ "feat: commit message 1" ,
388+ "fix: commit message 2" ,
389+ ]
390+ main ()
391+ mock_stdout_write .assert_not_called ()
392+
393+ @patch (
394+ "commitlint.cli.get_args" ,
395+ return_value = MagicMock (
396+ file = None ,
397+ hash = None ,
398+ from_hash = "start_commit_hash" ,
399+ to_hash = "end_commit_hash" ,
400+ skip_detail = False ,
401+ quiet = True ,
402+ ),
403+ )
404+ @patch ("commitlint.cli.get_commit_messages_of_hash_range" )
405+ @patch ("sys.exit" )
406+ @patch ("sys.stdout.write" )
407+ @patch ("sys.stderr.write" )
408+ def test__invalid_commit_message_with_hash_range_in_quiet (
409+ self ,
410+ mock_stderr_write ,
411+ mock_stdout_write ,
412+ mock_sys_exit ,
413+ mock_get_commit_messages ,
414+ * _ ,
415+ ):
416+ mock_get_commit_messages .return_value = [
417+ "Invalid commit message 1" ,
418+ "Invalid commit message 2" ,
419+ ]
420+ main ()
421+ mock_stderr_write .assert_not_called ()
422+ mock_sys_exit .assert_called_once_with (1 )
423+ mock_stdout_write .assert_not_called ()
0 commit comments