def test_scan_only_findings(monkeypatch): test_dir = test_env.extract_test_tar('info/basic.tgz') result_file = test_env.get_temp_file('json') expected_file = test_env.get_test_loc('only_findings/expected.json') _result = run_scan_click(['--only-findings', test_dir, result_file], monkeypatch) check_json_scan(expected_file, result_file)
def test_scan_does_not_fail_when_scanning_unicode_files_and_paths(): test_dir = test_env.get_test_loc(u'unicodepath/uc') result_file = test_env.get_temp_file('json') if on_linux: test_dir = path_to_bytes(test_dir) result_file = path_to_bytes(result_file) args = ['--info', '--license', '--copyright', '--package', '--email', '--url', '--strip-root', test_dir , result_file] result = run_scan_click(args) if result.exit_code != 0: raise Exception(result.output, args) assert result.exit_code == 0 assert 'Scanning done' in result.output # the paths for each OS end up encoded differently. # See for details: # https://github.com/nexB/scancode-toolkit/issues/390 # https://github.com/nexB/scancode-toolkit/issues/688 if on_linux: expected = 'unicodepath/unicodepath.expected-linux.json' elif on_mac: expected = 'unicodepath/unicodepath.expected-mac.json' elif on_windows: expected = 'unicodepath/unicodepath.expected-win.json' check_json_scan(test_env.get_test_loc(expected), result_file, strip_dates=True, regen=False)
def test_scan_can_handle_non_utf8_file_names_on_posix(): test_dir = test_env.extract_test_tar_raw('non_utf8/non_unicode.tgz') result_file = test_env.get_temp_file('json') if on_linux: test_dir = path_to_bytes(test_dir) result_file = path_to_bytes(result_file) result = run_scan_click(['-i', '--strip-root', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output # the paths for each OS end up encoded differently. # See for details: # https://github.com/nexB/scancode-toolkit/issues/390 # https://github.com/nexB/scancode-toolkit/issues/688 if on_linux: expected = 'non_utf8/expected-linux.json' elif on_mac: expected = 'non_utf8/expected-mac.json' elif on_windows: expected = 'non_utf8/expected-win.json' check_json_scan(test_env.get_test_loc(expected), result_file, regen=False)
def test_scan_mark_source_with_info(monkeypatch): test_dir = test_env.extract_test_tar('mark_source/JGroups.tgz') result_file = test_env.get_temp_file('json') expected_file = test_env.get_test_loc('mark_source/with_info.expected.json') _result = run_scan_click(['--info', '--mark-source', test_dir, result_file], monkeypatch) check_json_scan(expected_file, result_file)
def test_scan_can_return_matched_license_text(): test_file = test_env.get_test_loc('license_text/test.txt') expected_file = test_env.get_test_loc('license_text/test.expected') result_file = test_env.get_temp_file('json') result = run_scan_click(['--license', '--license-text', '--strip-root', test_file, result_file]) assert result.exit_code == 0 check_json_scan(test_env.get_test_loc(expected_file), result_file)
def test_scan_email_url_info(): test_dir = test_env.extract_test_tar('info/basic.tgz') result_file = test_env.get_temp_file('json') result = run_scan_click(['--email', '--url', '--info', '--strip-root', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output check_json_scan(test_env.get_test_loc('info/email_url_info.expected.json'), result_file)
def test_scan_noinfo_license_copyrights_with_root(): test_dir = test_env.extract_test_tar('info/basic.tgz') result_file = test_env.get_temp_file('json') result = run_scan_click(['--email', '--url', '--license', '--copyright', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output check_json_scan(test_env.get_test_loc('info/all.rooted.expected.json'), result_file)
def test_scan_info_does_collect_infos_with_root(): test_dir = test_env.extract_test_tar('info/basic.tgz') result_file = test_env.get_temp_file('json') result = run_scan_click(['--info', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output check_json_scan(test_env.get_test_loc('info/basic.rooted.expected.json'), result_file)
def test_scan_does_scan_php_composer(): test_file = test_env.get_test_loc('composer/composer.json') expected_file = test_env.get_test_loc('composer/composer.expected.json') result_file = test_env.get_temp_file('results.json') result = run_scan_click(['--package', test_file, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output check_json_scan(expected_file, result_file)
def test_package_command_scan_chef(self): test_dir = self.get_test_loc('chef/package') result_file = self.get_temp_file('json') expected_file = self.get_test_loc('plugin/chef-package-expected.json') run_scan_click([ '--package', '--strip-root', '--processes', '-1', test_dir, '--json', result_file ]) check_json_scan(expected_file, result_file, regen=False)
def test_scan_does_scan_rpm(): test_file = test_env.get_test_loc('rpm/fping-2.4-0.b2.rhfc1.dag.i386.rpm') expected_file = test_env.get_test_loc('rpm/fping-2.4-0.b2.rhfc1.dag.i386.rpm.expected.json') result_file = test_env.get_temp_file('results.json') result = run_scan_click(['--package', test_file, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output check_json_scan(expected_file, result_file, regen=False)
def test_json_pretty_print(): test_dir = test_env.get_test_loc('json/simple') result_file = test_env.get_temp_file('json') result = run_scan_click(['-clip', '--format', 'json-pp', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output expected = test_env.get_test_loc('json/simple-expected.jsonpp') check_json_scan(test_env.get_test_loc(expected), result_file, strip_dates=True, regen=False)
def test_consolidate_component_package_from_json_can_run_twice(self): scan_loc = self.get_test_loc('plugin_consolidate/component-package.json') result_file = self.get_temp_file('json') expected_file = self.get_test_loc('plugin_consolidate/component-package-expected.json') run_scan_click(['--from-json', scan_loc, '--consolidate', '--json', result_file]) check_json_scan(expected_file, result_file, regen=False, remove_file_date=True, ignore_headers=True) result_file2 = self.get_temp_file('json') run_scan_click(['--from-json', result_file, '--consolidate', '--json', result_file2]) check_json_scan(expected_file, result_file2, regen=False, remove_file_date=True, ignore_headers=True)
def test_win_reg_end_to_end(self): test_dir = self.get_test_loc( 'win_reg/get_installed_packages_docker/layer') expected_file = self.get_test_loc( 'win_reg/get_installed_packages_docker/expected-results', must_exist=False, ) result_file = self.get_temp_file('results.json') run_scan_click(['--package', test_dir, '--json-pp', result_file]) check_json_scan(expected_file, result_file, regen=REGEN_TEST_FIXTURES)
def test_scan_can_return_matched_license_text(): test_file = test_env.get_test_loc('license_text/test.txt') expected_file = test_env.get_test_loc('license_text/test.expected') result_file = test_env.get_temp_file('json') result = run_scan_click([ '--license', '--license-text', '--strip-root', test_file, result_file ]) assert result.exit_code == 0 check_json_scan(test_env.get_test_loc(expected_file), result_file)
def test_scan_email_url_info(): test_dir = test_env.extract_test_tar('info/basic.tgz') result_file = test_env.get_temp_file('json') result = run_scan_click( ['--email', '--url', '--info', '--strip-root', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output check_json_scan(test_env.get_test_loc('info/email_url_info.expected.json'), result_file)
def test_copyright_summary_does_not_crash(self): test_dir = self.get_test_loc('tallies/copyright_tallies/scan2') result_file = self.get_temp_file('json') expected_file = self.get_test_loc( 'tallies/copyright_tallies/tallies2.expected.json') run_scan_click(['-c', '--tallies', '--json-pp', result_file, test_dir]) check_json_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)
def test_scan_does_scan_rpm(): test_file = test_env.get_test_loc('rpm/fping-2.4-0.b2.rhfc1.dag.i386.rpm') expected_file = test_env.get_test_loc( 'rpm/fping-2.4-0.b2.rhfc1.dag.i386.rpm.expected.json') result_file = test_env.get_temp_file('results.json') result = run_scan_click(['--package', test_file, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output check_json_scan(expected_file, result_file, regen=False)
def test_scan_does_scan_rpm(): test_file = test_env.get_test_loc('rpm/fping-2.4-0.b2.rhfc1.dag.i386.rpm') expected_file = test_env.get_test_loc( 'rpm/fping-2.4-0.b2.rhfc1.dag.i386.rpm.expected.json') result_file = test_env.get_temp_file('results.json') run_scan_click(['--package', test_file, '--json', result_file]) check_json_scan(expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES)
def test_scan_info_returns_does_not_strip_root_with_single_file(): test_file = test_env.get_test_loc('single/iproute.c') result_file = test_env.get_temp_file('json') args = ['--info', '--strip-root', test_file, '--json', result_file] run_scan_click(args) expected = test_env.get_test_loc('single/iproute.expected.json') check_json_scan(expected, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)
def test_scan_should_not_fail_on_faulty_pdf_or_pdfminer_bug_but_instead_report_errors_and_keep_trucking_with_json(): test_file = test_env.get_test_loc('failing/patchelf.pdf') result_file = test_env.get_temp_file('test.json') result = run_scan_click([ '--copyright', '--strip-root', test_file, result_file]) assert result.exit_code == 1 assert 'Scanning done' in result.output check_json_scan(test_env.get_test_loc('failing/patchelf.expected.json'), result_file) assert 'Some files failed to scan' in result.output assert 'patchelf.pdf' in result.output
def test_summary_with_packages_reports_packages_with_files(self): test_dir = self.get_test_loc('packages/scan') result_file = self.get_temp_file('json') expected_file = self.get_test_loc('packages/expected.json') run_scan_click([ '--package', '--summary', '--json-pp', result_file, test_dir ]) check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
def test_scan_only_findings(self): test_dir = self.extract_test_tar('plugin_only_findings/basic.tgz') result_file = self.get_temp_file('json') expected_file = self.get_test_loc('plugin_only_findings/expected.json') run_scan_click( ['-clip', '--only-findings', '--json', result_file, test_dir]) check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
def test_license_option_reports_license_texts(): test_dir = test_env.get_test_loc('plugin_license/text/scan', copy=True) result_file = test_env.get_temp_file('json') 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)
def test_npm_electron_scan(self): test_file = self.get_test_loc('npm/electron/package') expected_file = self.get_test_loc('npm/electron/package.expected.json', must_exist=False) result_file = self.get_temp_file('results.json') run_scan_click(['--package', test_file, '--json', result_file]) check_json_scan(expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES)
def test_copyright_summary_does_not_crash(self): test_dir = self.get_test_loc('copyright_summary/scan2') result_file = self.get_temp_file('json') expected_file = self.get_test_loc( 'copyright_summary/summary2.expected.json') run_scan_click(['-c', '--summary', '--json-pp', result_file, test_dir]) check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
def test_full_summary_base(self): test_dir = self.get_test_loc('full_summary/scan') result_file = self.get_temp_file('json') expected_file = self.get_test_loc('full_summary/summary.expected.json') run_scan_click( ['-clip', '--summary', '--json-pp', result_file, test_dir]) check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
def test_scan_plugin_filter_clues_for_rule(): # this test fies is a copy of apache-1.1_63.RULE that contains # several emails, authors, urls and copyrights # it has been modified to include more unrelated clues test_dir = test_env.get_test_loc('plugin_filter_clues/files/LICENSE') result_file = test_env.get_temp_file('json') args = ['-clieu', '--filter-clues', test_dir, '--json', result_file] run_scan_click(args) expected = test_env.get_test_loc('plugin_filter_clues/filtered-expected.json') check_json_scan(expected, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)
def test_scan_plugin_filter_clues_does_not_filter_incorrectly(): # this test fies is a copy of pygres-2.2_1.RULE that contains # several emails, authors, urls and copyrights that have all been modified # to differ from the one in the license rule test_dir = test_env.get_test_loc('plugin_filter_clues/files/LICENSE2') result_file = test_env.get_temp_file('json') args = ['-clieu', '--filter-clues', test_dir, '--json', result_file] run_scan_click(args) expected = test_env.get_test_loc('plugin_filter_clues/filtered-expected2.json') check_json_scan(expected, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)
def test_scan_plugin_filter_clues_for_license(): # this test fies is a copy of pcre.LICENSE that contains # several emails, authors, urls test_dir = test_env.get_test_loc('plugin_filter_clues/files/LICENSE3') result_file = test_env.get_temp_file('json') args = ['-clieu', '--filter-clues', test_dir, '--json', result_file] run_scan_click(args) expected = test_env.get_test_loc( 'plugin_filter_clues/filtered-expected3.json') check_json_scan(expected, result_file, remove_file_date=True, regen=False)
def test_package_command_scan_pubspec_lock_package(self): test_dir = self.get_test_loc('pubspec/locks/dart-pubspec.lock') result_file = self.get_temp_file('json') expected_file = self.get_test_loc('plugin/pubspec-lock-expected.json', must_exist=False) run_scan_click([ '--package', '--strip-root', '--processes', '-1', test_dir, '--json', result_file ]) check_json_scan(expected_file, result_file, regen=False)
def test_scan_can_return_matched_license_text(): test_file = test_env.get_test_loc('license_text/test.txt') expected_file = test_env.get_test_loc('license_text/test.expected') result_file = test_env.get_temp_file('json') args = [ '--license', '--license-text', '--strip-root', test_file, '--json', result_file ] run_scan_click(args) check_json_scan(test_env.get_test_loc(expected_file), result_file)
def test_json_pretty_print(): test_dir = test_env.get_test_loc('json/simple') result_file = test_env.get_temp_file('json') 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=REGEN_TEST_FIXTURES)
def test_cocoapods_can_assemble_with_solo_podfile(self): test_file = self.get_test_loc('cocoapods/assemble/solo/Podfile') expected_file = self.get_test_loc( 'cocoapods/assemble/solo/Podfile-expected.json', must_exist=False) result_file = self.get_temp_file('results.json') run_scan_click(['--package', test_file, '--json', result_file]) check_json_scan(expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES)
def test_scan_email_url_info(): test_dir = test_env.extract_test_tar('info/basic.tgz') result_file = test_env.get_temp_file('json') args = [ '--email', '--url', '--info', '--strip-root', test_dir, '--json', result_file ] run_scan_click(args) check_json_scan(test_env.get_test_loc('info/email_url_info.expected.json'), result_file)
def test_scan_should_not_fail_on_faulty_pdf_or_pdfminer_bug_but_instead_keep_trucking_with_json( ): test_file = test_env.get_test_loc('failing/patchelf.pdf') result_file = test_env.get_temp_file('test.json') args = ['--copyright', '--strip-root', test_file, '--json', result_file] result = run_scan_click(args, expected_rc=0) expected = test_env.get_test_loc('failing/patchelf.expected.json') check_json_scan(expected, result_file, regen=False) assert 'Some files failed to scan' not in result.output assert 'patchelf.pdf' not in result.output
def test_scan_noinfo_license_copyrights_with_root(): test_dir = test_env.extract_test_tar('info/basic.tgz') result_file = test_env.get_temp_file('json') args = [ '--email', '--url', '--license', '--copyright', test_dir, '--json', result_file ] run_scan_click(args) expected = test_env.get_test_loc('info/all.rooted.expected.json') check_json_scan(expected, result_file, regen=False)
def test_classify_cli_option(self): test_dir = self.get_test_loc('classify/cli') result_file = self.get_temp_file('json') expected_file = self.get_test_loc('classify/cli.expected.json') run_scan_click( ['--info', '--classify', '--json-pp', result_file, test_dir]) check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
def test_detection_is_correct_in_legacy_npm_package_json(): test_dir = test_env.get_test_loc('plugin_license/package/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)
def test_scan_output_does_not_truncate_copyright_with_json_to_stdout(): test_dir = test_env.get_test_loc('json/tree/scan/') result_file = test_env.get_temp_file('test.json') 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=REGEN_TEST_FIXTURES)
def test_can_parse_solo_metadata_from_command_line(self): test_file = self.get_test_loc('pypi/solo-metadata/PKG-INFO') expected_file = self.get_test_loc('pypi/solo-metadata/expected.json', must_exist=False) result_file = self.get_temp_file('results.json') run_scan_click(['--package', test_file, '--json', result_file]) check_json_scan(expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES)
def test_scan_output_does_not_truncate_copyright_with_json_to_stdout(): test_dir = test_env.get_test_loc('json/tree/scan/') result_file = test_env.get_temp_file('test.json') result = run_scan_click( ['-clip', '--strip-root', '--format', 'json', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output expected = test_env.get_test_loc('json/tree/expected.json') check_json_scan(test_env.get_test_loc(expected), result_file, strip_dates=True, regen=False)
def test_scan_can_handle_weird_file_names(): test_dir = test_env.extract_test_tar('weird_file_name/weird_file_name.tar.gz') result_file = test_env.get_temp_file('json') args = ['-c', '-i', '--strip-root', test_dir, '--json', result_file] result = run_scan_click(args) assert "KeyError: 'sha1'" not in result.output # Some info vary on each OS # See https://github.com/nexB/scancode-toolkit/issues/438 for details expected = 'weird_file_name/expected-posix.json' check_json_scan(test_env.get_test_loc(expected), result_file, regen=False)
def test_json_compact(): test_dir = test_env.get_test_loc('json/simple') result_file = test_env.get_temp_file('json') result = run_scan_click(['-clip', '--format', 'json', test_dir, result_file]) assert result.exit_code == 0 assert 'Scanning done' in result.output 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(test_env.get_test_loc(expected), result_file, strip_dates=True, regen=False)
def test_scan_can_handle_weird_file_names(): test_dir = test_env.extract_test_tar('weird_file_name/weird_file_name.tar.gz') result_file = test_env.get_temp_file('json') result = run_scan_click(['-c', '-i', '--strip-root', test_dir, result_file]) assert result.exit_code == 0 assert "KeyError: 'sha1'" not in result.output assert 'Scanning done' in result.output # Some info vary on each OS # See https://github.com/nexB/scancode-toolkit/issues/438 for details if on_linux: expected = 'weird_file_name/expected-linux.json' elif on_mac: expected = 'weird_file_name/expected-mac.json' else: raise Exception('Not a supported OS?') check_json_scan(test_env.get_test_loc(expected), result_file, regen=False)
def test_scan_can_run_from_other_directory(): test_file = test_env.get_test_loc('altpath/copyright.c') expected_file = test_env.get_test_loc('altpath/copyright.expected.json') result_file = test_env.get_temp_file('json') work_dir = os.path.dirname(result_file) rc, stdout, stderr = run_scan_plain( ['-ci', '--strip-root', test_file, result_file], cwd=work_dir) if rc != 0: print() print('stdout:') print(stdout) print() print('stderr:') print(stderr) assert rc == 0 check_json_scan(test_env.get_test_loc(expected_file), result_file, strip_dates=True)