Skip to content

Commit

Permalink
Replace ignore_header with check_header attribute
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
AyanSinhaMahapatra committed Sep 6, 2021
1 parent 57377b8 commit 72ab891
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 102 deletions.
8 changes: 4 additions & 4 deletions src/scancode/cli_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def check_json_scan(
result_file,
regen=False,
remove_file_date=False,
ignore_headers=False
check_headers=False,
):
"""
Check the scan `result_file` JSON results against the `expected_file`
Expand All @@ -188,7 +188,7 @@ def check_json_scan(

expected = load_json_result(expected_file, remove_file_date)

if ignore_headers:
if not check_headers:
results.pop('headers', None)
expected.pop('headers', None)

Expand Down Expand Up @@ -289,7 +289,7 @@ def check_jsonlines_scan(
result_file,
regen=False,
remove_file_date=False,
ignore_headers=False,
check_headers=False,
):
"""
Check the scan result_file JSON Lines results against the expected_file
Expand All @@ -313,7 +313,7 @@ def check_jsonlines_scan(

streamline_jsonlines_scan(expected, remove_file_date)

if ignore_headers:
if not check_headers:
results[0].pop('headers', None)
expected[0].pop('headers', None)

Expand Down
8 changes: 4 additions & 4 deletions tests/cluecode/test_plugin_email_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ def test_scan_email():
result_file = test_env.get_temp_file('json')
args = ['--email', '--strip-root', test_dir, '--json', result_file]
run_scan_click(args)
check_json_scan(test_env.get_test_loc('plugin_email_url/emails.expected.json'), result_file, ignore_headers=True)
check_json_scan(test_env.get_test_loc('plugin_email_url/emails.expected.json'), result_file)


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


def test_scan_url():
test_dir = test_env.get_test_loc('plugin_email_url/files')
result_file = test_env.get_temp_file('json')
args = ['--url', '--strip-root', test_dir, '--json', result_file]
run_scan_click(args)
check_json_scan(test_env.get_test_loc('plugin_email_url/urls.expected.json'), result_file, ignore_headers=True)
check_json_scan(test_env.get_test_loc('plugin_email_url/urls.expected.json'), result_file)


def test_scan_url_with_threshold():
test_dir = test_env.get_test_loc('plugin_email_url/files')
result_file = test_env.get_temp_file('json')
args = ['--url', '--strip-root', '--max-url', '2', test_dir, '--json', result_file]
run_scan_click(args)
check_json_scan(test_env.get_test_loc('plugin_email_url/urls-threshold.expected.json'), result_file, ignore_headers=True)
check_json_scan(test_env.get_test_loc('plugin_email_url/urls-threshold.expected.json'), result_file)
4 changes: 2 additions & 2 deletions tests/cluecode/test_plugin_ignore_copyrights.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def test_ignore_holders(self):
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('plugin_ignore_copyrights/holders.expected.json')
run_scan_click(['-c', '--ignore-copyright-holder', 'Regents', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False, ignore_headers=True)
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)

def test_ignore_authors(self):
test_dir = self.extract_test_tar('plugin_ignore_copyrights/basic.tgz')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('plugin_ignore_copyrights/authors.expected.json')
run_scan_click(['-c', '--ignore-author', 'Berkeley', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False, ignore_headers=True)
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
8 changes: 4 additions & 4 deletions tests/formattedcode/test_output_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_json_pretty_print():
args = ['-clip', test_dir, '--json-pp', result_file]
run_scan_click(args)
expected = test_env.get_test_loc('json/simple-expected.jsonpp')
check_json_scan(expected, result_file, remove_file_date=True, regen=False, ignore_headers=True)
check_json_scan(expected, result_file, remove_file_date=True, regen=False)


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


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


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


@pytest.mark.scanslow
Expand Down
2 changes: 1 addition & 1 deletion tests/formattedcode/test_output_jsonlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_jsonlines():
expected = test_env.get_test_loc('json/simple-expected.jsonlines')
check_jsonlines_scan(
test_env.get_test_loc(expected), result_file,
remove_file_date=True, regen=False, ignore_headers=True)
remove_file_date=True, regen=False)


def test_jsonlines_with_timing():
Expand Down
20 changes: 10 additions & 10 deletions tests/licensedcode/test_plugin_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_license_option_reports_license_expressions():
args = ['--license', '--strip-root', test_dir, '--json', result_file, '--verbose']
run_scan_click(args)
test_loc = test_env.get_test_loc('plugin_license/license-expression/scan.expected.json')
check_json_scan(test_loc, result_file, regen=False, ignore_headers=True)
check_json_scan(test_loc, result_file, regen=False)


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


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


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


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


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


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


def test_get_referenced_filenames():
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_scan_license_with_url_template():
test_dir, '--json-pp', result_file]
test_loc = test_env.get_test_loc('plugin_license/license_url.expected.json')
run_scan_click(args)
check_json_scan(test_loc, result_file, ignore_headers=True)
check_json_scan(test_loc, result_file)


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


@pytest.mark.scanslow
Expand All @@ -164,4 +164,4 @@ def test_detection_is_correct_in_legacy_npm_package_json():
result_file = test_env.get_temp_file('json')
expected_file = test_env.get_test_loc('plugin_license/package/package.expected.json')
run_scan_click(['-lp', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False, ignore_headers=True)
check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
2 changes: 1 addition & 1 deletion tests/licensedcode/test_plugin_license_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def test_is_licensing_works():
test_dir, '--json-pp', result_file, '--verbose']
run_scan_click(args)
check_json_scan(test_env.get_test_loc('plugin_license_text/scan.expected.json'),
result_file, remove_file_date=True, regen=False, ignore_headers=True)
result_file, remove_file_date=True, regen=False)
4 changes: 2 additions & 2 deletions tests/packagedcode/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def test_end2end_scan_can_detect_bazel(self):
expected_file = self.get_test_loc('bazel/end2end-expected.json')
result_file = self.get_temp_file('results.json')
run_scan_click(['--package', test_file, '--json-pp', result_file])
check_json_scan(expected_file, result_file, regen=False, ignore_headers=True)
check_json_scan(expected_file, result_file, regen=False)

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

def test_build_get_package_resources(self):
test_loc = self.get_test_loc('get_package_resources')
Expand Down
Loading

0 comments on commit 72ab891

Please sign in to comment.