Skip to content

Commit a93fd62

Browse files
Replace ignore_header with check_header attribute
Replaces ignore_header with check_header attribute with default False, to minimise diff and ignore headers by default. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 57377b8 commit a93fd62

19 files changed

Lines changed: 107 additions & 108 deletions

src/scancode/cli_test_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def check_json_scan(
168168
result_file,
169169
regen=False,
170170
remove_file_date=False,
171-
ignore_headers=False
171+
check_headers=False,
172172
):
173173
"""
174174
Check the scan `result_file` JSON results against the `expected_file`
@@ -188,7 +188,7 @@ def check_json_scan(
188188

189189
expected = load_json_result(expected_file, remove_file_date)
190190

191-
if ignore_headers:
191+
if not check_headers:
192192
results.pop('headers', None)
193193
expected.pop('headers', None)
194194

@@ -289,7 +289,7 @@ def check_jsonlines_scan(
289289
result_file,
290290
regen=False,
291291
remove_file_date=False,
292-
ignore_headers=False,
292+
check_headers=False,
293293
):
294294
"""
295295
Check the scan result_file JSON Lines results against the expected_file
@@ -313,7 +313,7 @@ def check_jsonlines_scan(
313313

314314
streamline_jsonlines_scan(expected, remove_file_date)
315315

316-
if ignore_headers:
316+
if not check_headers:
317317
results[0].pop('headers', None)
318318
expected[0].pop('headers', None)
319319

tests/cluecode/test_plugin_email_url.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ def test_scan_email():
2525
result_file = test_env.get_temp_file('json')
2626
args = ['--email', '--strip-root', test_dir, '--json', result_file]
2727
run_scan_click(args)
28-
check_json_scan(test_env.get_test_loc('plugin_email_url/emails.expected.json'), result_file, ignore_headers=True)
28+
check_json_scan(test_env.get_test_loc('plugin_email_url/emails.expected.json'), result_file)
2929

3030

3131
def test_scan_email_with_threshold():
3232
test_dir = test_env.get_test_loc('plugin_email_url/files')
3333
result_file = test_env.get_temp_file('json')
3434
args = ['--email', '--strip-root', '--max-email', '2', test_dir, '--json', result_file]
3535
run_scan_click(args)
36-
check_json_scan(test_env.get_test_loc('plugin_email_url/emails-threshold.expected.json'), result_file, ignore_headers=True)
36+
check_json_scan(test_env.get_test_loc('plugin_email_url/emails-threshold.expected.json'), result_file)
3737

3838

3939
def test_scan_url():
4040
test_dir = test_env.get_test_loc('plugin_email_url/files')
4141
result_file = test_env.get_temp_file('json')
4242
args = ['--url', '--strip-root', test_dir, '--json', result_file]
4343
run_scan_click(args)
44-
check_json_scan(test_env.get_test_loc('plugin_email_url/urls.expected.json'), result_file, ignore_headers=True)
44+
check_json_scan(test_env.get_test_loc('plugin_email_url/urls.expected.json'), result_file)
4545

4646

4747
def test_scan_url_with_threshold():
4848
test_dir = test_env.get_test_loc('plugin_email_url/files')
4949
result_file = test_env.get_temp_file('json')
5050
args = ['--url', '--strip-root', '--max-url', '2', test_dir, '--json', result_file]
5151
run_scan_click(args)
52-
check_json_scan(test_env.get_test_loc('plugin_email_url/urls-threshold.expected.json'), result_file, ignore_headers=True)
52+
check_json_scan(test_env.get_test_loc('plugin_email_url/urls-threshold.expected.json'), result_file)

tests/cluecode/test_plugin_ignore_copyrights.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def test_ignore_holders(self):
3737
result_file = self.get_temp_file('json')
3838
expected_file = self.get_test_loc('plugin_ignore_copyrights/holders.expected.json')
3939
run_scan_click(['-c', '--ignore-copyright-holder', 'Regents', '--json-pp', result_file, test_dir])
40-
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False, ignore_headers=True)
40+
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
4141

4242
def test_ignore_authors(self):
4343
test_dir = self.extract_test_tar('plugin_ignore_copyrights/basic.tgz')
4444
result_file = self.get_temp_file('json')
4545
expected_file = self.get_test_loc('plugin_ignore_copyrights/authors.expected.json')
4646
run_scan_click(['-c', '--ignore-author', 'Berkeley', '--json-pp', result_file, test_dir])
47-
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False, ignore_headers=True)
47+
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)

tests/formattedcode/test_output_json.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_json_pretty_print():
2727
args = ['-clip', test_dir, '--json-pp', result_file]
2828
run_scan_click(args)
2929
expected = test_env.get_test_loc('json/simple-expected.jsonpp')
30-
check_json_scan(expected, result_file, remove_file_date=True, regen=False, ignore_headers=True)
30+
check_json_scan(expected, result_file, remove_file_date=True, regen=False)
3131

3232

3333
def test_json_compact():
@@ -37,7 +37,7 @@ def test_json_compact():
3737
with open(result_file, 'rb') as res:
3838
assert len(res.read().splitlines()) == 1
3939
expected = test_env.get_test_loc('json/simple-expected.json')
40-
check_json_scan(expected, result_file, remove_file_date=True, regen=False, ignore_headers=True)
40+
check_json_scan(expected, result_file, remove_file_date=True, regen=False)
4141

4242

4343
@pytest.mark.scanslow
@@ -46,7 +46,7 @@ def test_scan_output_does_not_truncate_copyright_json():
4646
result_file = test_env.get_temp_file('test.json')
4747
run_scan_click(['-clip', '--strip-root', test_dir, '--json-pp', result_file])
4848
expected = test_env.get_test_loc('json/tree/expected.json')
49-
check_json_scan(expected, result_file, remove_file_date=True, regen=False, ignore_headers=True)
49+
check_json_scan(expected, result_file, remove_file_date=True, regen=False)
5050

5151

5252
@pytest.mark.scanslow
@@ -56,7 +56,7 @@ def test_scan_output_does_not_truncate_copyright_with_json_to_stdout():
5656
args = ['-clip', '--strip-root', test_dir, '--json-pp', result_file]
5757
run_scan_click(args)
5858
expected = test_env.get_test_loc('json/tree/expected.json')
59-
check_json_scan(expected, result_file, remove_file_date=True, regen=False, ignore_headers=True)
59+
check_json_scan(expected, result_file, remove_file_date=True, regen=False)
6060

6161

6262
@pytest.mark.scanslow

tests/formattedcode/test_output_jsonlines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_jsonlines():
2828
expected = test_env.get_test_loc('json/simple-expected.jsonlines')
2929
check_jsonlines_scan(
3030
test_env.get_test_loc(expected), result_file,
31-
remove_file_date=True, regen=False, ignore_headers=True)
31+
remove_file_date=True, regen=False)
3232

3333

3434
def test_jsonlines_with_timing():

tests/licensedcode/test_plugin_license.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_license_option_reports_license_expressions():
3333
args = ['--license', '--strip-root', test_dir, '--json', result_file, '--verbose']
3434
run_scan_click(args)
3535
test_loc = test_env.get_test_loc('plugin_license/license-expression/scan.expected.json')
36-
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
36+
check_json_scan(test_loc, result_file, regen=False)
3737

3838

3939
def test_license_option_reports_license_texts():
@@ -42,7 +42,7 @@ def test_license_option_reports_license_texts():
4242
args = ['--license', '--license-text', '--strip-root', test_dir, '--json', result_file, '--verbose']
4343
run_scan_click(args)
4444
test_loc = test_env.get_test_loc('plugin_license/text/scan.expected.json')
45-
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
45+
check_json_scan(test_loc, result_file, regen=False)
4646

4747

4848
def test_license_option_reports_license_texts_diag():
@@ -51,7 +51,7 @@ def test_license_option_reports_license_texts_diag():
5151
args = ['--license', '--license-text', '--license-text-diagnostics', '--strip-root', test_dir, '--json', result_file, '--verbose']
5252
run_scan_click(args)
5353
test_loc = test_env.get_test_loc('plugin_license/text/scan-diag.expected.json')
54-
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
54+
check_json_scan(test_loc, result_file, regen=False)
5555

5656

5757
def test_license_option_reports_license_texts_long_lines():
@@ -60,7 +60,7 @@ def test_license_option_reports_license_texts_long_lines():
6060
args = ['--license', '--license-text', '--strip-root', test_dir, '--json', result_file, '--verbose']
6161
run_scan_click(args)
6262
test_loc = test_env.get_test_loc('plugin_license/text_long_lines/scan.expected.json')
63-
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
63+
check_json_scan(test_loc, result_file, regen=False)
6464

6565

6666
def test_license_option_reports_license_texts_diag_long_lines():
@@ -69,7 +69,7 @@ def test_license_option_reports_license_texts_diag_long_lines():
6969
args = ['--license', '--license-text', '--license-text-diagnostics', '--strip-root', test_dir, '--json', result_file, '--verbose']
7070
run_scan_click(args)
7171
test_loc = test_env.get_test_loc('plugin_license/text_long_lines/scan-diag.expected.json')
72-
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
72+
check_json_scan(test_loc, result_file, regen=False)
7373

7474

7575
def test_license_match_reference():
@@ -78,7 +78,7 @@ def test_license_match_reference():
7878
args = ['--license', '--license-text', '--license-text-diagnostics', '--strip-root', test_dir, '--json', result_file, '--verbose']
7979
run_scan_click(args)
8080
test_loc = test_env.get_test_loc('plugin_license/license_reference/scan-ref.expected.json')
81-
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
81+
check_json_scan(test_loc, result_file, regen=False)
8282

8383

8484
def test_license_match_without_reference():
@@ -87,7 +87,7 @@ def test_license_match_without_reference():
8787
args = ['--license', '--license-text', '--license-text-diagnostics', '--strip-root', test_dir, '--json', result_file, '--verbose']
8888
run_scan_click(args)
8989
test_loc = test_env.get_test_loc('plugin_license/license_reference/scan-wref.expected.json')
90-
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
90+
check_json_scan(test_loc, result_file, regen=False)
9191

9292

9393
def test_get_referenced_filenames():
@@ -145,7 +145,7 @@ def test_scan_license_with_url_template():
145145
test_dir, '--json-pp', result_file]
146146
test_loc = test_env.get_test_loc('plugin_license/license_url.expected.json')
147147
run_scan_click(args)
148-
check_json_scan(test_loc, result_file, ignore_headers=True)
148+
check_json_scan(test_loc, result_file)
149149

150150

151151
@pytest.mark.scanslow
@@ -155,7 +155,7 @@ def test_detection_does_not_timeout_on_sqlite3_amalgamation():
155155
expected_file = test_env.get_test_loc('plugin_license/sqlite/sqlite.expected.json')
156156
# we use the default 120 seconds timeout
157157
run_scan_click(['-l', '--license-text', '--json-pp', result_file, test_dir])
158-
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False, ignore_headers=True)
158+
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
159159

160160

161161
@pytest.mark.scanslow
@@ -164,4 +164,4 @@ def test_detection_is_correct_in_legacy_npm_package_json():
164164
result_file = test_env.get_temp_file('json')
165165
expected_file = test_env.get_test_loc('plugin_license/package/package.expected.json')
166166
run_scan_click(['-lp', '--json-pp', result_file, test_dir])
167-
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False, ignore_headers=True)
167+
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)

tests/licensedcode/test_plugin_license_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ def test_is_licensing_works():
3333
test_dir, '--json-pp', result_file, '--verbose']
3434
run_scan_click(args)
3535
check_json_scan(test_env.get_test_loc('plugin_license_text/scan.expected.json'),
36-
result_file, remove_file_date=True, regen=False, ignore_headers=True)
36+
result_file, remove_file_date=True, regen=False)

tests/packagedcode/test_build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ def test_end2end_scan_can_detect_bazel(self):
2525
expected_file = self.get_test_loc('bazel/end2end-expected.json')
2626
result_file = self.get_temp_file('results.json')
2727
run_scan_click(['--package', test_file, '--json-pp', result_file])
28-
check_json_scan(expected_file, result_file, regen=False, ignore_headers=True)
28+
check_json_scan(expected_file, result_file, regen=False)
2929

3030
def test_end2end_scan_can_detect_buck(self):
3131
test_file = self.get_test_loc('buck/end2end')
3232
expected_file = self.get_test_loc('buck/end2end-expected.json')
3333
result_file = self.get_temp_file('results.json')
3434
run_scan_click(['--package', test_file, '--json-pp', result_file])
35-
check_json_scan(expected_file, result_file, regen=False, ignore_headers=True)
35+
check_json_scan(expected_file, result_file, regen=False)
3636

3737
def test_build_get_package_resources(self):
3838
test_loc = self.get_test_loc('get_package_resources')

0 commit comments

Comments
 (0)