@@ -325,29 +325,25 @@ def test__main__handle_exceptions(
325
325
mock_stderr_write .assert_called_with ("Test message\n " )
326
326
327
327
@patch (
328
- "argparse.ArgumentParser.parse_args " ,
328
+ "commitlint.cli.get_args " ,
329
329
return_value = MagicMock (
330
330
commit_message = "Invalid commit message" ,
331
331
file = None ,
332
332
hash = None ,
333
333
from_hash = None ,
334
+ skip_detail = False ,
334
335
quiet = True ,
335
336
),
336
337
)
337
- @patch (
338
- "commitlint.cli.lint_commit_message" ,
339
- )
338
+ @patch ("sys.stdout.write" )
340
339
@patch ("sys.stderr.write" )
341
340
@patch ("sys.exit" )
342
- def test__main__handle_quiet_option (
343
- self , mock_sys_exit , mock_stderr_write , mock_lint_commit_message , * _
341
+ def test__main__quiet_option_with_invalid_commit_message (
342
+ self , mock_sys_exit , mock_stderr_write , mock_stdout_write , * _
344
343
):
345
- mock_lint_commit_message .side_effect = CommitlintException (
346
- "Invalid commit message"
347
- )
348
344
main ()
349
- mock_sys_exit . assert_called_with ( 1 )
350
- mock_stderr_write . assert_called_with ( "Invalid commit message \n " )
345
+ mock_stderr_write . assert_not_called ( )
346
+ mock_stdout_write . assert_not_called ( )
351
347
352
348
@patch (
353
349
"commitlint.cli.get_args" ,
@@ -370,3 +366,51 @@ def test__main__quiet_option_with_valid_commit_message(
370
366
mock_stderr_write .assert_not_called ()
371
367
mock_stdout_write .assert_not_called ()
372
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
+ def test__invalid_commit_message_with_hash_range_in_quiet (
408
+ self , mock_stdout_write , mock_sys_exit , mock_get_commit_messages , * _
409
+ ):
410
+ mock_get_commit_messages .return_value = [
411
+ "Invalid commit message 1" ,
412
+ "Invalid commit message 2" ,
413
+ ]
414
+ main ()
415
+ mock_sys_exit .assert_called_once_with (1 )
416
+ mock_stdout_write .assert_not_called ()
0 commit comments