Skip to content

Commit ff606e8

Browse files
committed
#267 Catch exceptions in CLI tests
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 06a176a commit ff606e8

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

tests/scancode/test_cli.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_package_option_detects_packages(monkeypatch):
9292
test_dir = test_env.get_test_loc('package', copy=True)
9393
runner = CliRunner()
9494
result_file = test_env.get_temp_file('json')
95-
result = runner.invoke(cli.scancode, ['--package', test_dir, result_file], catch_exceptions=False)
95+
result = runner.invoke(cli.scancode, ['--package', test_dir, result_file], catch_exceptions=True)
9696
assert result.exit_code == 0
9797
assert 'Scanning done' in result.output
9898
assert 'package.json' in result.output
@@ -105,7 +105,7 @@ def test_verbose_option_with_packages(monkeypatch):
105105
test_dir = test_env.get_test_loc('package', copy=True)
106106
runner = CliRunner()
107107
result_file = test_env.get_temp_file('json')
108-
result = runner.invoke(cli.scancode, ['--package', '--verbose', test_dir, result_file], catch_exceptions=False)
108+
result = runner.invoke(cli.scancode, ['--package', '--verbose', test_dir, result_file], catch_exceptions=True)
109109
assert result.exit_code == 0
110110
assert 'Scanning done' in result.output
111111
assert 'package.json' in result.output
@@ -118,7 +118,7 @@ def test_copyright_option_detects_copyrights(monkeypatch):
118118
test_dir = test_env.get_test_loc('copyright', copy=True)
119119
runner = CliRunner()
120120
result_file = test_env.get_temp_file('json')
121-
result = runner.invoke(cli.scancode, ['--copyright', test_dir, result_file], catch_exceptions=False)
121+
result = runner.invoke(cli.scancode, ['--copyright', test_dir, result_file], catch_exceptions=True)
122122
assert result.exit_code == 0
123123
assert 'Scanning done' in result.output
124124
assert os.path.exists(result_file)
@@ -130,7 +130,7 @@ def test_verbose_option_with_copyrights(monkeypatch):
130130
test_dir = test_env.get_test_loc('copyright', copy=True)
131131
runner = CliRunner()
132132
result_file = test_env.get_temp_file('json')
133-
result = runner.invoke(cli.scancode, ['--copyright', '--verbose', test_dir, result_file], catch_exceptions=False)
133+
result = runner.invoke(cli.scancode, ['--copyright', '--verbose', test_dir, result_file], catch_exceptions=True)
134134
assert result.exit_code == 0
135135
assert 'Scanning done' in result.output
136136
assert 'copyright_acme_c-c.c' in result.output
@@ -143,7 +143,7 @@ def test_license_option_detects_licenses(monkeypatch):
143143
test_dir = test_env.get_test_loc('license', copy=True)
144144
runner = CliRunner()
145145
result_file = test_env.get_temp_file('json')
146-
result = runner.invoke(cli.scancode, ['--license', test_dir, result_file], catch_exceptions=False)
146+
result = runner.invoke(cli.scancode, ['--license', test_dir, result_file], catch_exceptions=True)
147147
assert result.exit_code == 0
148148
assert 'Scanning done' in result.output
149149
assert os.path.exists(result_file)
@@ -155,7 +155,7 @@ def test_scancode_skip_vcs_files_and_dirs_by_default(monkeypatch):
155155
test_dir = test_env.extract_test_tar('ignore/vcs.tgz')
156156
runner = CliRunner()
157157
result_file = test_env.get_temp_file('json')
158-
result = runner.invoke(cli.scancode, ['--copyright', test_dir, result_file], catch_exceptions=False)
158+
result = runner.invoke(cli.scancode, ['--copyright', test_dir, result_file], catch_exceptions=True)
159159
assert result.exit_code == 0
160160
scan_result = _load_json_result(result_file, test_dir)
161161
# a single test.tst file and its directory that is not a VCS file should be listed
@@ -172,12 +172,12 @@ def test_usage_and_help_return_a_correct_script_name_on_all_platforms(monkeypatc
172172
# this was showing up on Windows
173173
assert 'scancode-script.py' not in result.output
174174

175-
result = runner.invoke(cli.scancode, [], catch_exceptions=False)
175+
result = runner.invoke(cli.scancode, [], catch_exceptions=True)
176176
assert 'Usage: scancode [OPTIONS]' in result.output
177177
# this was showing up on Windows
178178
assert 'scancode-script.py' not in result.output
179179

180-
result = runner.invoke(cli.scancode, ['-xyz'], catch_exceptions=False)
180+
result = runner.invoke(cli.scancode, ['-xyz'], catch_exceptions=True)
181181
# this was showing up on Windows
182182
assert 'scancode-script.py' not in result.output
183183

@@ -187,7 +187,7 @@ def test_scan_info_does_collect_infos(monkeypatch):
187187
test_dir = test_env.extract_test_tar('info/basic.tgz')
188188
runner = CliRunner()
189189
result_file = test_env.get_temp_file('json')
190-
result = runner.invoke(cli.scancode, ['--info', test_dir, result_file], catch_exceptions=False)
190+
result = runner.invoke(cli.scancode, ['--info', test_dir, result_file], catch_exceptions=True)
191191
assert result.exit_code == 0
192192
assert 'Scanning done' in result.output
193193
check_scan(test_env.get_test_loc('info/basic.expected.json'), result_file, test_dir)
@@ -198,7 +198,7 @@ def test_scan_info_license_copyrights(monkeypatch):
198198
test_dir = test_env.extract_test_tar('info/basic.tgz')
199199
runner = CliRunner()
200200
result_file = test_env.get_temp_file('json')
201-
result = runner.invoke(cli.scancode, ['--info', '--license', '--copyright', test_dir, result_file], catch_exceptions=False)
201+
result = runner.invoke(cli.scancode, ['--info', '--license', '--copyright', test_dir, result_file], catch_exceptions=True)
202202
assert result.exit_code == 0
203203
assert 'Scanning done' in result.output
204204
check_scan(test_env.get_test_loc('info/all.expected.json'), result_file, test_dir)
@@ -207,12 +207,9 @@ def test_scan_info_license_copyrights(monkeypatch):
207207
def test_scan_email_url_info(monkeypatch):
208208
monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
209209
test_dir = test_env.extract_test_tar('info/basic.tgz')
210-
print('############################')
211-
print(test_dir)
212-
print('############################')
213210
runner = CliRunner()
214211
result_file = test_env.get_temp_file('json')
215-
result = runner.invoke(cli.scancode, ['--email', '--url', '--info', test_dir, result_file], catch_exceptions=False)
212+
result = runner.invoke(cli.scancode, ['--email', '--url', '--info', test_dir, result_file], catch_exceptions=True)
216213
assert result.exit_code == 0
217214
assert 'Scanning done' in result.output
218215
check_scan(test_env.get_test_loc('info/email_url_info.expected.json'), result_file, test_dir)
@@ -223,7 +220,7 @@ def test_paths_are_posix_paths_in_html_app_format_output(monkeypatch):
223220
test_dir = test_env.get_test_loc('posix_path', copy=True)
224221
runner = CliRunner()
225222
result_file = test_env.get_temp_file(extension='html', file_name='test_html')
226-
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'html-app', test_dir, result_file], catch_exceptions=False)
223+
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'html-app', test_dir, result_file], catch_exceptions=True)
227224
assert result.exit_code == 0
228225
assert 'Scanning done' in result.output
229226
# the data we want to test is in the data.json file
@@ -236,7 +233,7 @@ def test_paths_are_posix_in_html_format_output(monkeypatch):
236233
test_dir = test_env.get_test_loc('posix_path', copy=True)
237234
runner = CliRunner()
238235
result_file = test_env.get_temp_file('html')
239-
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'html', test_dir, result_file], catch_exceptions=False)
236+
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'html', test_dir, result_file], catch_exceptions=True)
240237
assert result.exit_code == 0
241238
assert 'Scanning done' in result.output
242239
assert '/posix_path/copyright_acme_c-c.c' in open(result_file).read()
@@ -247,7 +244,7 @@ def test_paths_are_posix_in_json_format_output(monkeypatch):
247244
test_dir = test_env.get_test_loc('posix_path', copy=True)
248245
runner = CliRunner()
249246
result_file = test_env.get_temp_file('json')
250-
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'json', test_dir, result_file], catch_exceptions=False)
247+
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'json', test_dir, result_file], catch_exceptions=True)
251248
assert result.exit_code == 0
252249
assert 'Scanning done' in result.output
253250
assert '/posix_path/copyright_acme_c-c.c' in open(result_file).read()
@@ -258,7 +255,7 @@ def test_format_with_custom_filename_fails_for_directory(monkeypatch):
258255
test_dir = test_env.get_test_loc('posix_path', copy=True)
259256
runner = CliRunner()
260257
result_file = test_env.get_temp_file('html')
261-
result = runner.invoke(cli.scancode, [ '--format', test_dir, test_dir, result_file], catch_exceptions=False)
258+
result = runner.invoke(cli.scancode, [ '--format', test_dir, test_dir, result_file], catch_exceptions=True)
262259
assert result.exit_code != 0
263260
assert 'Invalid template file' in result.output
264261

@@ -269,7 +266,7 @@ def test_format_with_custom_filename(monkeypatch):
269266
runner = CliRunner()
270267
template = test_env.get_test_loc('template/sample-template.html')
271268
result_file = test_env.get_temp_file('html')
272-
result = runner.invoke(cli.scancode, [ '--format', template, test_dir, result_file], catch_exceptions=False)
269+
result = runner.invoke(cli.scancode, [ '--format', template, test_dir, result_file], catch_exceptions=True)
273270
assert result.exit_code == 0
274271
assert 'Custom Template' in open(result_file).read()
275272

@@ -279,7 +276,7 @@ def test_scanned_path_is_present_in_html_app_output(monkeypatch):
279276
test_dir = test_env.get_test_loc('html_app')
280277
runner = CliRunner()
281278
result_file = test_env.get_temp_file('test.html')
282-
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'html-app', test_dir, result_file], catch_exceptions=False)
279+
result = runner.invoke(cli.scancode, [ '--copyright', '--format', 'html-app', test_dir, result_file], catch_exceptions=True)
283280
assert result.exit_code == 0
284281
assert 'Scanning done' in result.output
285282
html_file = open(result_file).read()
@@ -291,7 +288,7 @@ def test_scan_should_not_fail_on_faulty_pdf_or_pdfminer_bug_but_instead_report_e
291288
test_file = test_env.get_test_loc('failing/patchelf.pdf')
292289
runner = CliRunner()
293290
result_file = test_env.get_temp_file('test.json')
294-
result = runner.invoke(cli.scancode, [ '--copyright', test_file, result_file], catch_exceptions=False)
291+
result = runner.invoke(cli.scancode, [ '--copyright', test_file, result_file], catch_exceptions=True)
295292
assert result.exit_code == 0
296293
assert 'Scanning done' in result.output
297294
check_scan(test_env.get_test_loc('failing/patchelf.expected.json'), result_file, test_file)

0 commit comments

Comments
 (0)