test\unit\test_cli.py
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
-- -- --- --- --- --- --- --- ------- ------- ------- | from pathlib import Path
-- -- --- --- --- --- --- --- ------- ------- ------- | from unittest.mock import patch
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import pytest
-- -- --- --- --- --- --- --- ------- ------- ------- | from click.testing import CliRunner
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import wily.__main__ as main
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.helper.custom_enums import ReportFormat
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def test_init():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | with patch.object(main, "cli", return_value=None) as cli:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | with patch.object(main, "__name__", "__main__"):
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | __import__("wily.__main__")
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 | assert cli.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_help():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that CLI when called with help options
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.logger") as logger:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(main.cli, ["--help", "--debug"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_setup():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that CLI when called with help options
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.__main__.handle_no_cache", return_value=True) as handle_no_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(main.cli, ["setup"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert handle_no_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def test_handle_no_cache_no():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | Test that setup cancels when "n" typed
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | with patch("wily.__main__.input", return_value="n") as mock_input:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | with pytest.raises(SystemExit):
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | main.handle_no_cache(None)
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 | assert mock_input.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def test_handle_no_cache():
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | Test that setup works
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | with patch("wily.__main__.build", return_value="n") as build_command:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | with patch("wily.__main__.input", side_effect=["y", "11", "."]) as mock_input:
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | runner = CliRunner()
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | runner.invoke(main.cli, ["setup"])
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 | assert mock_input.called
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 | assert build_command.called_once
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 | assert build_command.called_with("1")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_build():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that build calls the build command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.commands.build.build") as build:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(main.cli, ["build", "wily"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert build.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_build_with_opts():
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | Test that build calls the build command
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with patch("wily.commands.build.build") as build:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | runner = CliRunner()
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | result = runner.invoke(
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | main.cli, ["build", "wily", "-n 1", "-o raw,maintainability"]
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | )
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert result.exit_code == 0
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert build.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert build.call_args[1]["config"].max_revisions == 1
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert build.call_args[1]["config"].operators == ["raw", "maintainability"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_index():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that index calls the index command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.commands.index.index") as index:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(main.cli, ["index"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert index.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_index_with_opts():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that index calls the index command with options
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.commands.index.index") as index:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(main.cli, ["index", "--message"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert index.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert check_cache.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert index.call_args[1]["include_message"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | def test_index_with_no_message():
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | """
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | Test that index calls the index command with options
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | """
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | with patch("wily.commands.index.index") as index:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | runner = CliRunner()
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | result = runner.invoke(main.cli, ["index", "--no-message"])
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 | assert result.exit_code == 0
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 | assert index.called_once
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 | assert check_cache.called_once
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 | assert not index.call_args[1]["include_message"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | def test_report():
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | """
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | Test that report calls the report command
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | """
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | with patch(
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | "wily.__main__.get_default_metrics",
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | return_value=["maintainability.mi", "raw.loc"],
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | ) as gdf:
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | with patch("wily.commands.report.report") as report:
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | runner = CliRunner()
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 | result = runner.invoke(main.cli, ["report", "foo.py"])
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 | assert result.exit_code == 0, result.stdout
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 | assert report.called_once
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 | assert check_cache.called_once
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 | assert report.call_args[1]["path"] == "foo.py"
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 | assert report.call_args[1]["format"] == ReportFormat.CONSOLE
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 | assert "maintainability.mi" in report.call_args[1]["metrics"]
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 | assert gdf.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | def test_report_with_opts():
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | """
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | Test that report calls the report command with options
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | """
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | with patch("wily.commands.report.report") as report:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | runner = CliRunner()
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | result = runner.invoke(
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | main.cli, ["report", "foo.py", "example_metric", "-n 101", "--message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | )
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert result.exit_code == 0, result.stdout
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert check_cache.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["path"] == "foo.py"
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["include_message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["n"] == 101
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["format"] == ReportFormat.CONSOLE
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | def test_report_html_format():
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | """
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | Test that report calls the report command with HTML as format
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | """
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | with patch("wily.commands.report.report") as report:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | runner = CliRunner()
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | result = runner.invoke(
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | main.cli,
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | [
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "report",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "foo.py",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "example_metric",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "-n 101",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "--message",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "--format=HTML",
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | ],
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | )
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 |
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert result.exit_code == 0, result.stdout
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert check_cache.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["path"] == "foo.py"
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["include_message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["n"] == 101
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["format"] == ReportFormat.HTML
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | def test_report_console_format():
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | """
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | Test that report calls the report command with console as format
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | """
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | with patch("wily.commands.report.report") as report:
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | runner = CliRunner()
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | result = runner.invoke(
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | main.cli,
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | [
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "report",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "foo.py",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "example_metric",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "-n 101",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "--message",
-- 01 001 010 005 010 011 015 0051.89 0025.95 0000.50 | "--format=CONSOLE",
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | ],
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | )
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert result.exit_code == 0, result.stdout
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert check_cache.called_once
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["path"] == "foo.py"
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["include_message"]
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["n"] == 101
-- -- 001 010 005 010 011 015 0051.89 0025.95 0000.50 | assert report.call_args[1]["format"] == ReportFormat.CONSOLE
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_report_not_existing_format():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that report calls the report command with a non-existing format
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.commands.report.report") as report:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | main.cli,
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | [
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "report",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "foo.py",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "example_metric",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "-n 101",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "--message",
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | "--format=non-existing",
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | ],
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | )
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 2, result.stdout
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert report.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | def test_report_html_format_with_output():
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | """
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | Test that report calls the report command with HTML as format and specified output
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | """
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | with patch("wily.commands.report.report") as report:
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | runner = CliRunner()
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | result = runner.invoke(
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | main.cli,
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | [
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "report",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "foo.py",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "example_metric",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "-n 101",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "--message",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "--format=HTML",
-- 01 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "--output=reports/out.html",
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | ],
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | )
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 |
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert result.exit_code == 0, result.stdout
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert report.called_once
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert check_cache.called_once
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert report.call_args[1]["path"] == "foo.py"
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert report.call_args[1]["metrics"] == ("example_metric",)
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert report.call_args[1]["include_message"]
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert report.call_args[1]["n"] == 101
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert report.call_args[1]["format"] == ReportFormat.HTML
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | assert report.call_args[1]["output"] == Path().cwd() / Path(
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | "reports/out.html"
-- -- 002 014 007 014 016 021 0084.00 0084.00 0001.00 | )
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_graph():
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | Test that graph calls the graph command
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with patch("wily.commands.graph.graph") as graph:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | runner = CliRunner()
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | result = runner.invoke(main.cli, ["graph", "foo.py", "example_metric"])
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert result.exit_code == 0
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert graph.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert check_cache.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert graph.call_args[1]["path"] == "foo.py"
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert graph.call_args[1]["metrics"] == ("example_metric",)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_graph_multiple_metrics():
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | Test that graph calls the graph command with multiple metrics
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with patch("wily.commands.graph.graph") as graph:
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | runner = CliRunner()
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | result = runner.invoke(
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | main.cli, ["graph", "foo.py", "example_metric", "another_metric"]
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | )
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert result.exit_code == 0
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert graph.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert check_cache.called_once
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert graph.call_args[1]["path"] == "foo.py"
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert graph.call_args[1]["metrics"] == ("example_metric", "another_metric")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | def test_graph_with_output():
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | """
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | Test that graph calls the graph command with output
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | """
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | with patch("wily.commands.graph.graph") as graph:
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | runner = CliRunner()
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | result = runner.invoke(
-- 01 001 008 004 008 009 012 0038.04 0019.02 0000.50 | main.cli, ["graph", "foo.py", "example_metric", "-o", "foo.html"]
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 | )
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 | assert result.exit_code == 0
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 | assert graph.called_once
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 | assert check_cache.called_once
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 | assert graph.call_args[1]["path"] == "foo.py"
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 | assert graph.call_args[1]["metrics"] == ("example_metric",)
-- -- 001 008 004 008 009 012 0038.04 0019.02 0000.50 | assert graph.call_args[1]["output"] == "foo.html"
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | def test_diff():
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | """
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | Test that diff calls the diff command
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | """
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | with patch(
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | "wily.__main__.get_default_metrics",
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | return_value=["maintainability.mi", "raw.loc"],
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | ) as gdf:
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | with patch("wily.commands.diff.diff") as diff:
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | runner = CliRunner()
-- 01 002 006 003 006 008 009 0027.00 0027.00 0001.00 | result = runner.invoke(main.cli, ["diff", "foo.py", "x/b.py"])
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert result.exit_code == 0
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert diff.called_once
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert check_cache.called_once
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert diff.call_args[1]["files"] == ("foo.py", "x/b.py")
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert gdf.called_once
-- -- 002 006 003 006 008 009 0027.00 0027.00 0001.00 | assert "maintainability.mi" in diff.call_args[1]["metrics"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | def test_diff_with_metrics():
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | """
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | Test that diff calls the diff command with additional metrics
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | """
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | with patch(
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | "wily.__main__.get_default_metrics",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | return_value=["maintainability.mi", "raw.loc"],
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | ) as gdf:
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | with patch("wily.commands.diff.diff") as diff:
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | runner = CliRunner()
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | result = runner.invoke(
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | main.cli,
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | [
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | "diff",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | "foo.py",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | "x/b.py",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | "--metrics",
-- 01 004 009 005 009 013 014 0051.81 0103.61 0002.00 | "maintainability.mi,raw.sloc",
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | ],
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | )
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | assert result.exit_code == 0
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | assert diff.called_once
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | assert check_cache.called_once
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | assert diff.call_args[1]["files"] == ("foo.py", "x/b.py")
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | assert not gdf.called
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | assert "maintainability.mi" in diff.call_args[1]["metrics"]
-- -- 004 009 005 009 013 014 0051.81 0103.61 0002.00 | assert "raw.loc" not in diff.call_args[1]["metrics"]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_clean():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that graph calls the clean command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.cache.clean") as clean:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(main.cli, ["clean", "--yes"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert clean.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | def test_clean_with_prompt():
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | Test that graph calls the clean command
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | """
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.cache.clean") as clean:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | with patch("wily.__main__.input", return_value="y") as mock_input:
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | runner = CliRunner()
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 | result = runner.invoke(main.cli, ["clean"])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert result.exit_code == 0
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert clean.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert check_cache.called_once
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 | assert mock_input.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | def test_clean_with_prompt_no_value():
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | """
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | Test that graph calls the clean command and if enter type "n" it doesn't clean index
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | """
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | with patch("wily.__main__.exists", return_value=True) as check_cache:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | with patch("wily.cache.clean") as clean:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | with patch("wily.__main__.input", return_value="n") as mock_input:
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | runner = CliRunner()
-- 01 002 003 002 003 005 005 0011.61 0011.61 0001.00 | result = runner.invoke(main.cli, ["clean"])
-- -- 002 003 002 003 005 005 0011.61 0011.61 0001.00 | assert result.exit_code == 0
-- -- --- --- --- --- --- --- ------- ------- ------- | assert not clean.called
-- -- --- --- --- --- --- --- ------- ------- ------- | assert check_cache.called_once
-- -- --- --- --- --- --- --- ------- ------- ------- | assert mock_input.called_once