@@ -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,50 @@ 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
+ "argparse.ArgumentParser.parse_args" ,
329
+ return_value = MagicMock (
330
+ commit_message = "Invalid commit message" ,
331
+ file = None ,
332
+ hash = None ,
333
+ from_hash = None ,
334
+ quiet = True ,
335
+ ),
336
+ )
337
+ @patch (
338
+ "commitlint.cli.lint_commit_message" ,
339
+ )
340
+ @patch ("sys.stderr.write" )
341
+ @patch ("sys.exit" )
342
+ def test__main__handle_quiet_option (
343
+ self , mock_sys_exit , mock_stderr_write , mock_lint_commit_message , * _
344
+ ):
345
+ mock_lint_commit_message .side_effect = CommitlintException (
346
+ "Invalid commit message"
347
+ )
348
+ main ()
349
+ mock_sys_exit .assert_called_with (1 )
350
+ mock_stderr_write .assert_called_with ("Invalid commit message\n " )
351
+
352
+ @patch (
353
+ "commitlint.cli.get_args" ,
354
+ return_value = MagicMock (
355
+ commit_message = "feat: valid commit message" ,
356
+ file = None ,
357
+ hash = None ,
358
+ from_hash = None ,
359
+ skip_detail = False ,
360
+ quiet = True ,
361
+ ),
362
+ )
363
+ @patch ("sys.stdout.write" )
364
+ @patch ("sys.stderr.write" )
365
+ @patch ("sys.exit" )
366
+ def test__main__quiet_option_with_valid_commit_message (
367
+ self , mock_sys_exit , mock_stderr_write , mock_stdout_write , * _
368
+ ):
369
+ main ()
370
+ mock_stderr_write .assert_not_called ()
371
+ mock_stdout_write .assert_not_called ()
372
+ mock_sys_exit .assert_not_called ()
0 commit comments