@@ -541,6 +541,11 @@ def test_commit_from_pre_commit_msg_hook(config, mocker, capsys):
541
541
"footer" : "" ,
542
542
}
543
543
544
+ is_blank_commit_file_mock = mocker .patch (
545
+ "commitizen.commands.commit.Commit.is_blank_commit_file"
546
+ )
547
+ is_blank_commit_file_mock .return_value = True
548
+
544
549
commit_mock = mocker .patch ("commitizen.git.commit" )
545
550
commit_mock .return_value = cmd .Command ("success" , "" , "" , "" , 0 )
546
551
@@ -554,3 +559,52 @@ def test_commit_from_pre_commit_msg_hook(config, mocker, capsys):
554
559
out , _ = capsys .readouterr ()
555
560
assert "Commit message is successful!" in out
556
561
commit_mock .assert_not_called ()
562
+
563
+
564
+ def test_commit_with_msg_from_pre_commit_msg_hook (config , mocker , capsys ):
565
+ testargs = ["cz" , "commit" , "--commit-msg-file" , "some_file" ]
566
+ mocker .patch .object (sys , "argv" , testargs )
567
+
568
+ prompt_mock = mocker .patch ("questionary.prompt" )
569
+ prompt_mock .return_value = {
570
+ "prefix" : "feat" ,
571
+ "subject" : "user created" ,
572
+ "scope" : "" ,
573
+ "is_breaking_change" : False ,
574
+ "body" : "" ,
575
+ "footer" : "" ,
576
+ }
577
+
578
+ is_blank_commit_file_mock = mocker .patch (
579
+ "commitizen.commands.commit.Commit.is_blank_commit_file"
580
+ )
581
+ is_blank_commit_file_mock .return_value = False
582
+
583
+ commit_mock = mocker .patch ("commitizen.git.commit" )
584
+ commit_mock .return_value = cmd .Command ("success" , "" , "" , "" , 0 )
585
+
586
+ cli .main ()
587
+
588
+ prompt_mock .assert_not_called ()
589
+ commit_mock .assert_not_called ()
590
+
591
+
592
+ @pytest .mark .parametrize (
593
+ "isexist, commitmsg, returnvalue" ,
594
+ [
595
+ [False , "" , True ],
596
+ [True , "\n #test" , True ],
597
+ [True , "test: test\n #test" , False ],
598
+ [True , "#test: test\n #test" , True ],
599
+ ],
600
+ )
601
+ def test_is_blank_commit_file (config , mocker , isexist , commitmsg , returnvalue ):
602
+ exists_mock = mocker .patch ("commitizen.commands.commit.exists" )
603
+ exists_mock .return_value = isexist
604
+
605
+ reader_mock = mocker .mock_open (read_data = commitmsg )
606
+ mocker .patch ("builtins.open" , reader_mock )
607
+
608
+ commit_cmd = commands .Commit (config , {})
609
+ ret = commit_cmd .is_blank_commit_file ("test" )
610
+ assert ret == returnvalue
0 commit comments