@@ -18,7 +18,11 @@ class TestCLIGetArgs:
18
18
@patch (
19
19
"argparse.ArgumentParser.parse_args" ,
20
20
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 ,
22
26
),
23
27
)
24
28
def test__get_args__with_commit_message (self , * _ ):
@@ -27,6 +31,7 @@ def test__get_args__with_commit_message(self, *_):
27
31
assert args .file is None
28
32
assert args .hash is None
29
33
assert args .from_hash is None
34
+ assert args .quiet is None
30
35
31
36
@patch (
32
37
"argparse.ArgumentParser.parse_args" ,
@@ -88,6 +93,7 @@ class TestCLIMain:
88
93
hash = None ,
89
94
from_hash = None ,
90
95
skip_detail = False ,
96
+ quiet = False ,
91
97
),
92
98
)
93
99
@patch ("sys.stdout.write" )
@@ -107,6 +113,7 @@ def test__main__valid_commit_message(
107
113
hash = None ,
108
114
from_hash = None ,
109
115
skip_detail = True ,
116
+ quiet = False ,
110
117
),
111
118
)
112
119
@patch ("sys.stdout.write" )
@@ -126,6 +133,7 @@ def test__main__valid_commit_message_using_skip_detail(
126
133
hash = None ,
127
134
from_hash = None ,
128
135
skip_detail = False ,
136
+ quiet = False ,
129
137
),
130
138
)
131
139
@patch ("sys.stderr.write" )
@@ -154,6 +162,7 @@ def test__main__invalid_commit_message(
154
162
hash = None ,
155
163
from_hash = None ,
156
164
skip_detail = True ,
165
+ quiet = False ,
157
166
),
158
167
)
159
168
@patch ("sys.stderr.write" )
@@ -177,7 +186,7 @@ def test__main__invalid_commit_message_using_skip_detail(
177
186
178
187
@patch (
179
188
"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 ),
181
190
)
182
191
@patch ("sys.stdout.write" )
183
192
@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, *_):
187
196
188
197
@patch (
189
198
"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 ),
191
200
)
192
201
@patch ("sys.stderr.write" )
193
202
@patch ("sys.exit" )
@@ -209,7 +218,9 @@ def test__main__invalid_commit_message_with_file(
209
218
210
219
@patch (
211
220
"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
+ ),
213
224
)
214
225
@patch ("commitlint.cli.get_commit_message_of_hash" )
215
226
@patch ("sys.stdout.write" )
@@ -222,7 +233,9 @@ def test__main__valid_commit_message_with_hash(
222
233
223
234
@patch (
224
235
"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
+ ),
226
239
)
227
240
@patch ("commitlint.cli.get_commit_message_of_hash" )
228
241
@patch ("sys.stderr.write" )
@@ -251,6 +264,7 @@ def test__main__invalid_commit_message_with_hash(
251
264
from_hash = "start_commit_hash" ,
252
265
to_hash = "end_commit_hash" ,
253
266
skip_detail = False ,
267
+ quiet = False ,
254
268
),
255
269
)
256
270
@patch ("commitlint.cli.get_commit_messages_of_hash_range" )
@@ -273,6 +287,7 @@ def test__main__valid_commit_message_with_hash_range(
273
287
from_hash = "invalid_start_hash" ,
274
288
to_hash = "end_commit_hash" ,
275
289
skip_detail = False ,
290
+ quiet = False ,
276
291
),
277
292
)
278
293
@patch ("sys.stderr.write" )
@@ -308,3 +323,101 @@ def test__main__handle_exceptions(
308
323
main ()
309
324
mock_sys_exit .assert_called_with (1 )
310
325
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