@@ -196,6 +196,11 @@ def test_commit_from_pre_commit_msg_hook(config, mocker, capsys):
196
196
"footer" : "" ,
197
197
}
198
198
199
+ is_blank_commit_file_mock = mocker .patch (
200
+ "commitizen.commands.commit.Commit.is_blank_commit_file"
201
+ )
202
+ is_blank_commit_file_mock .return_value = True
203
+
199
204
commit_mock = mocker .patch ("commitizen.git.commit" )
200
205
commit_mock .return_value = cmd .Command ("success" , "" , "" , "" , 0 )
201
206
@@ -209,3 +214,52 @@ def test_commit_from_pre_commit_msg_hook(config, mocker, capsys):
209
214
out , _ = capsys .readouterr ()
210
215
assert "Commit message is successful!" in out
211
216
commit_mock .assert_not_called ()
217
+
218
+
219
+ def test_commit_with_msg_from_pre_commit_msg_hook (config , mocker , capsys ):
220
+ testargs = ["cz" , "commit" , "--commit-msg-file" , "some_file" ]
221
+ mocker .patch .object (sys , "argv" , testargs )
222
+
223
+ prompt_mock = mocker .patch ("questionary.prompt" )
224
+ prompt_mock .return_value = {
225
+ "prefix" : "feat" ,
226
+ "subject" : "user created" ,
227
+ "scope" : "" ,
228
+ "is_breaking_change" : False ,
229
+ "body" : "" ,
230
+ "footer" : "" ,
231
+ }
232
+
233
+ is_blank_commit_file_mock = mocker .patch (
234
+ "commitizen.commands.commit.Commit.is_blank_commit_file"
235
+ )
236
+ is_blank_commit_file_mock .return_value = False
237
+
238
+ commit_mock = mocker .patch ("commitizen.git.commit" )
239
+ commit_mock .return_value = cmd .Command ("success" , "" , "" , "" , 0 )
240
+
241
+ cli .main ()
242
+
243
+ prompt_mock .assert_not_called ()
244
+ commit_mock .assert_not_called ()
245
+
246
+
247
+ @pytest .mark .parametrize (
248
+ "isexist, commitmsg, returnvalue" ,
249
+ [
250
+ [False , "" , True ],
251
+ [True , "\n #test" , True ],
252
+ [True , "test: test\n #test" , False ],
253
+ [True , "#test: test\n #test" , True ],
254
+ ],
255
+ )
256
+ def test_is_blank_commit_file (config , mocker , isexist , commitmsg , returnvalue ):
257
+ exists_mock = mocker .patch ("commitizen.commands.commit.exists" )
258
+ exists_mock .return_value = isexist
259
+
260
+ reader_mock = mocker .mock_open (read_data = commitmsg )
261
+ mocker .patch ("builtins.open" , reader_mock )
262
+
263
+ commit_cmd = commands .Commit (config , {})
264
+ ret = commit_cmd .is_blank_commit_file ("test" )
265
+ assert ret == returnvalue
0 commit comments