8
8
from wily .helper .custom_enums import ReportFormat
9
9
10
10
11
- def test_init ():
12
- with patch .object (main , "cli" , return_value = None ) as cli :
13
- with patch .object (main , "__name__" , "__main__" ):
14
- __import__ ("wily.__main__" )
15
- assert cli .called_once
16
-
17
-
18
11
def test_help ():
19
12
"""
20
13
Test that CLI when called with help options
@@ -33,7 +26,7 @@ def test_setup():
33
26
runner = CliRunner ()
34
27
result = runner .invoke (main .cli , ["setup" ])
35
28
assert result .exit_code == 0
36
- assert handle_no_cache .called_once
29
+ assert handle_no_cache .called
37
30
38
31
39
32
def test_handle_no_cache_no ():
@@ -43,7 +36,7 @@ def test_handle_no_cache_no():
43
36
with patch ("wily.__main__.input" , return_value = "n" ) as mock_input :
44
37
with pytest .raises (SystemExit ):
45
38
main .handle_no_cache (None )
46
- assert mock_input .called_once
39
+ assert mock_input .called
47
40
48
41
49
42
def test_handle_no_cache ():
@@ -55,8 +48,10 @@ def test_handle_no_cache():
55
48
runner = CliRunner ()
56
49
runner .invoke (main .cli , ["setup" ])
57
50
assert mock_input .called
58
- assert build_command .called_once
59
- assert build_command .called_with ("1" )
51
+ assert build_command .called
52
+ build_command .assert_called_with (
53
+ max_revisions = 11 , targets = ["." ], operators = None
54
+ )
60
55
61
56
62
57
def test_build ():
@@ -67,7 +62,7 @@ def test_build():
67
62
runner = CliRunner ()
68
63
result = runner .invoke (main .cli , ["build" , "wily" ])
69
64
assert result .exit_code == 0
70
- assert build .called_once
65
+ assert build .called
71
66
72
67
73
68
def test_build_with_opts ():
@@ -80,7 +75,7 @@ def test_build_with_opts():
80
75
main .cli , ["build" , "wily" , "-n 1" , "-o raw,maintainability" ]
81
76
)
82
77
assert result .exit_code == 0
83
- assert build .called_once
78
+ assert build .called
84
79
assert build .call_args [1 ]["config" ].max_revisions == 1
85
80
assert build .call_args [1 ]["config" ].operators == ["raw" , "maintainability" ]
86
81
@@ -94,8 +89,8 @@ def test_index():
94
89
runner = CliRunner ()
95
90
result = runner .invoke (main .cli , ["index" ])
96
91
assert result .exit_code == 0
97
- assert index .called_once
98
- assert check_cache .called_once
92
+ assert index .called
93
+ assert check_cache .called
99
94
100
95
101
96
def test_index_with_opts ():
@@ -107,8 +102,8 @@ def test_index_with_opts():
107
102
runner = CliRunner ()
108
103
result = runner .invoke (main .cli , ["index" , "--message" ])
109
104
assert result .exit_code == 0
110
- assert index .called_once
111
- assert check_cache .called_once
105
+ assert index .called
106
+ assert check_cache .called
112
107
assert index .call_args [1 ]["include_message" ]
113
108
114
109
@@ -121,8 +116,8 @@ def test_index_with_no_message():
121
116
runner = CliRunner ()
122
117
result = runner .invoke (main .cli , ["index" , "--no-message" ])
123
118
assert result .exit_code == 0
124
- assert index .called_once
125
- assert check_cache .called_once
119
+ assert index .called
120
+ assert check_cache .called
126
121
assert not index .call_args [1 ]["include_message" ]
127
122
128
123
@@ -139,12 +134,12 @@ def test_report():
139
134
runner = CliRunner ()
140
135
result = runner .invoke (main .cli , ["report" , "foo.py" ])
141
136
assert result .exit_code == 0 , result .stdout
142
- assert report .called_once
143
- assert check_cache .called_once
137
+ assert report .called
138
+ assert check_cache .called
144
139
assert report .call_args [1 ]["path" ] == "foo.py"
145
140
assert report .call_args [1 ]["format" ] == ReportFormat .CONSOLE
146
141
assert "maintainability.mi" in report .call_args [1 ]["metrics" ]
147
- assert gdf .called_once
142
+ assert gdf .called
148
143
149
144
150
145
def test_report_with_opts ():
@@ -158,8 +153,8 @@ def test_report_with_opts():
158
153
main .cli , ["report" , "foo.py" , "example_metric" , "-n 101" , "--message" ]
159
154
)
160
155
assert result .exit_code == 0 , result .stdout
161
- assert report .called_once
162
- assert check_cache .called_once
156
+ assert report .called
157
+ assert check_cache .called
163
158
assert report .call_args [1 ]["path" ] == "foo.py"
164
159
assert report .call_args [1 ]["metrics" ] == ("example_metric" ,)
165
160
assert report .call_args [1 ]["include_message" ]
@@ -187,8 +182,8 @@ def test_report_html_format():
187
182
)
188
183
189
184
assert result .exit_code == 0 , result .stdout
190
- assert report .called_once
191
- assert check_cache .called_once
185
+ assert report .called
186
+ assert check_cache .called
192
187
assert report .call_args [1 ]["path" ] == "foo.py"
193
188
assert report .call_args [1 ]["metrics" ] == ("example_metric" ,)
194
189
assert report .call_args [1 ]["include_message" ]
@@ -215,8 +210,8 @@ def test_report_console_format():
215
210
],
216
211
)
217
212
assert result .exit_code == 0 , result .stdout
218
- assert report .called_once
219
- assert check_cache .called_once
213
+ assert report .called
214
+ assert check_cache .called
220
215
assert report .call_args [1 ]["path" ] == "foo.py"
221
216
assert report .call_args [1 ]["metrics" ] == ("example_metric" ,)
222
217
assert report .call_args [1 ]["include_message" ]
@@ -243,8 +238,6 @@ def test_report_not_existing_format():
243
238
],
244
239
)
245
240
assert result .exit_code == 2 , result .stdout
246
- assert report .called_once
247
- assert check_cache .called_once
248
241
249
242
250
243
def test_report_html_format_with_output ():
@@ -268,8 +261,8 @@ def test_report_html_format_with_output():
268
261
)
269
262
270
263
assert result .exit_code == 0 , result .stdout
271
- assert report .called_once
272
- assert check_cache .called_once
264
+ assert report .called
265
+ assert check_cache .called
273
266
assert report .call_args [1 ]["path" ] == "foo.py"
274
267
assert report .call_args [1 ]["metrics" ] == ("example_metric" ,)
275
268
assert report .call_args [1 ]["include_message" ]
@@ -291,8 +284,8 @@ def test_graph():
291
284
main .cli , ["graph" , "foo.py" , "-m" , "example_metric" ]
292
285
)
293
286
assert result .exit_code == 0
294
- assert graph .called_once
295
- assert check_cache .called_once
287
+ assert graph .called
288
+ assert check_cache .called
296
289
assert graph .call_args [1 ]["path" ] == ("foo.py" ,)
297
290
assert graph .call_args [1 ]["metrics" ] == "example_metric"
298
291
@@ -309,8 +302,8 @@ def test_graph_multiple_paths():
309
302
["graph" , "foo.py" , "bar.py" , "baz.py" , "-m" , "example_metric" ],
310
303
)
311
304
assert result .exit_code == 0
312
- assert graph .called_once
313
- assert check_cache .called_once
305
+ assert graph .called
306
+ assert check_cache .called
314
307
assert graph .call_args [1 ]["path" ] == ("foo.py" , "bar.py" , "baz.py" )
315
308
assert graph .call_args [1 ]["metrics" ] == "example_metric"
316
309
@@ -326,8 +319,8 @@ def test_graph_multiple_metrics():
326
319
main .cli , ["graph" , "foo.py" , "-m" , "example_metric,another_metric" ]
327
320
)
328
321
assert result .exit_code == 0
329
- assert graph .called_once
330
- assert check_cache .called_once
322
+ assert graph .called
323
+ assert check_cache .called
331
324
assert graph .call_args [1 ]["path" ] == ("foo.py" ,)
332
325
assert graph .call_args [1 ]["metrics" ] == "example_metric,another_metric"
333
326
@@ -343,8 +336,8 @@ def test_graph_with_output():
343
336
main .cli , ["graph" , "foo.py" , "-m" , "example_metric" , "-o" , "foo.html" ]
344
337
)
345
338
assert result .exit_code == 0
346
- assert graph .called_once
347
- assert check_cache .called_once
339
+ assert graph .called
340
+ assert check_cache .called
348
341
assert graph .call_args [1 ]["path" ] == ("foo.py" ,)
349
342
assert graph .call_args [1 ]["metrics" ] == "example_metric"
350
343
assert graph .call_args [1 ]["output" ] == "foo.html"
@@ -363,10 +356,10 @@ def test_diff():
363
356
runner = CliRunner ()
364
357
result = runner .invoke (main .cli , ["diff" , "foo.py" , "x/b.py" ])
365
358
assert result .exit_code == 0
366
- assert diff .called_once
367
- assert check_cache .called_once
359
+ assert diff .called
360
+ assert check_cache .called
368
361
assert diff .call_args [1 ]["files" ] == ("foo.py" , "x/b.py" )
369
- assert gdf .called_once
362
+ assert gdf .called
370
363
assert "maintainability.mi" in diff .call_args [1 ]["metrics" ]
371
364
372
365
@@ -392,8 +385,8 @@ def test_diff_with_metrics():
392
385
],
393
386
)
394
387
assert result .exit_code == 0
395
- assert diff .called_once
396
- assert check_cache .called_once
388
+ assert diff .called
389
+ assert check_cache .called
397
390
assert diff .call_args [1 ]["files" ] == ("foo.py" , "x/b.py" )
398
391
assert not gdf .called
399
392
assert "maintainability.mi" in diff .call_args [1 ]["metrics" ]
@@ -409,8 +402,8 @@ def test_clean():
409
402
runner = CliRunner ()
410
403
result = runner .invoke (main .cli , ["clean" , "--yes" ])
411
404
assert result .exit_code == 0
412
- assert clean .called_once
413
- assert check_cache .called_once
405
+ assert clean .called
406
+ assert check_cache .called
414
407
415
408
416
409
def test_clean_with_prompt ():
@@ -423,9 +416,9 @@ def test_clean_with_prompt():
423
416
runner = CliRunner ()
424
417
result = runner .invoke (main .cli , ["clean" ])
425
418
assert result .exit_code == 0
426
- assert clean .called_once
427
- assert check_cache .called_once
428
- assert mock_input .called_once
419
+ assert clean .called
420
+ assert check_cache .called
421
+ assert mock_input .called
429
422
430
423
431
424
def test_clean_with_prompt_no_value ():
@@ -439,5 +432,5 @@ def test_clean_with_prompt_no_value():
439
432
result = runner .invoke (main .cli , ["clean" ])
440
433
assert result .exit_code == 0
441
434
assert not clean .called
442
- assert check_cache .called_once
443
- assert mock_input .called_once
435
+ assert check_cache .called
436
+ assert mock_input .called
0 commit comments