@@ -554,3 +554,62 @@ def test_commit_when_nothing_added_to_commit(config, mocker: MockFixture, out):
554
554
555
555
commit_mock .assert_called_once ()
556
556
error_mock .assert_called_once_with (out )
557
+
558
+
559
+ @pytest .mark .usefixtures ("staging_is_clean" )
560
+ def test_commit_command_with_config_message_length_limit (config , mocker : MockFixture ):
561
+ prompt_mock = mocker .patch ("questionary.prompt" )
562
+ prefix = "feat"
563
+ subject = "random subject"
564
+ message_length = len (prefix ) + len (": " ) + len (subject )
565
+ prompt_mock .return_value = {
566
+ "prefix" : prefix ,
567
+ "subject" : subject ,
568
+ "scope" : "" ,
569
+ "is_breaking_change" : False ,
570
+ "body" : "random body" ,
571
+ "footer" : "random footer" ,
572
+ }
573
+
574
+ commit_mock = mocker .patch ("commitizen.git.commit" )
575
+ commit_mock .return_value = cmd .Command ("success" , "" , b"" , b"" , 0 )
576
+ success_mock = mocker .patch ("commitizen.out.success" )
577
+
578
+ config .settings ["message_length_limit" ] = message_length
579
+ commands .Commit (config , {})()
580
+ success_mock .assert_called_once ()
581
+
582
+ config .settings ["message_length_limit" ] = message_length - 1
583
+ with pytest .raises (CommitMessageLengthExceededError ):
584
+ commands .Commit (config , {})()
585
+
586
+
587
+ @pytest .mark .usefixtures ("staging_is_clean" )
588
+ def test_commit_command_cli_overrides_config_message_length_limit (
589
+ config , mocker : MockFixture
590
+ ):
591
+ prompt_mock = mocker .patch ("questionary.prompt" )
592
+ prefix = "feat"
593
+ subject = "random subject"
594
+ message_length = len (prefix ) + len (": " ) + len (subject )
595
+ prompt_mock .return_value = {
596
+ "prefix" : prefix ,
597
+ "subject" : subject ,
598
+ "scope" : "" ,
599
+ "is_breaking_change" : False ,
600
+ "body" : "random body" ,
601
+ "footer" : "random footer" ,
602
+ }
603
+
604
+ commit_mock = mocker .patch ("commitizen.git.commit" )
605
+ commit_mock .return_value = cmd .Command ("success" , "" , b"" , b"" , 0 )
606
+ success_mock = mocker .patch ("commitizen.out.success" )
607
+
608
+ config .settings ["message_length_limit" ] = message_length - 1
609
+
610
+ commands .Commit (config , {"message_length_limit" : message_length })()
611
+ success_mock .assert_called_once ()
612
+
613
+ success_mock .reset_mock ()
614
+ commands .Commit (config , {"message_length_limit" : 0 })()
615
+ success_mock .assert_called_once ()
0 commit comments