Пример #1
0
def test_usage_and_help_return_a_correct_script_name_on_all_platforms():
    result = run_scan_click(['--help'])
    assert 'Usage: scancode [OPTIONS]' in result.output
    # this was showing up on Windows
    assert 'scancode-script.py' not in result.output

    result = run_scan_click([])
    assert 'Usage: scancode [OPTIONS]' in result.output
    # this was showing up on Windows
    assert 'scancode-script.py' not in result.output

    result = run_scan_click(['-xyz'])
    # this was showing up on Windows
    assert 'scancode-script.py' not in result.output
Пример #2
0
def test_scan_works_with_multiple_processes():
    test_dir = test_env.get_test_loc('multiprocessing', copy=True)

    # run the same scan with one or three processes
    result_file_1 = test_env.get_temp_file('json')
    result1 = run_scan_click([ '--copyright', '--processes', '1', '--format', 'json', test_dir, result_file_1])
    assert result1.exit_code == 0

    result_file_3 = test_env.get_temp_file('json')
    result3 = run_scan_click([ '--copyright', '--processes', '3', '--format', 'json', test_dir, result_file_3])
    assert result3.exit_code == 0
    res1 = json.loads(open(result_file_1).read())
    res3 = json.loads(open(result_file_3).read())
    assert sorted(res1['files']) == sorted(res3['files'])
Пример #3
0
def test_scan_works_with_no_processes_in_single_threaded_mode():
    test_dir = test_env.get_test_loc('multiprocessing', copy=True)

    # run the same scan with zero or one process
    result_file_0 = test_env.get_temp_file('json')
    result0 = run_scan_click([ '--copyright', '--processes', '0', '--format', 'json', test_dir, result_file_0])
    assert result0.exit_code == 0
    assert 'Disabling multi-processing and multi-threading...' in result0.output

    result_file_1 = test_env.get_temp_file('json')
    result1 = run_scan_click([ '--copyright', '--processes', '1', '--format', 'json', test_dir, result_file_1])
    assert result1.exit_code == 0
    res0 = json.loads(open(result_file_0).read())
    res1 = json.loads(open(result_file_1).read())
    assert sorted(res0['files']) == sorted(res1['files'])
Пример #4
0
def test_scan_quiet_to_stdout_only_echoes_json_results():
    test_dir = test_env.extract_test_tar('info/basic.tgz')
    result1_file = test_env.get_temp_file('json')

    result1 = run_scan_click(['--quiet', '--info', test_dir, result1_file])
    assert result1.exit_code == 0
    assert not result1.output

    # also test with an output of JSON to stdout
    result2 = run_scan_click(['--quiet', '--info', test_dir])
    assert result2.exit_code == 0

    # outputs to file or stdout should be identical
    result1_output = open(result1_file).read()
    assert result1_output == result2.output
Пример #5
0
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)
Пример #6
0
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_custom_html_output_can_handle_non_ascii_paths():
    test_file = test_env.get_test_loc('unicode.json')
    result_file = test_env.get_temp_file(extension='html',
                                         file_name='test_html')
    custom_template = test_env.get_test_loc('templated/sample-template.html')

    args = [
        '--from-json', test_file, '--custom-template', custom_template,
        '--custom-output', result_file
    ]
    run_scan_click(args)

    with io.open(result_file, encoding='utf-8') as res:
        results = res.read()

    assert '<td>han/据.svg</td>' in results
def test_scan_license_with_url_template():
    test_dir = test_env.get_test_loc('plugin_license/license_url', copy=True)
    result_file = test_env.get_temp_file('json')
    args = [
        '--license',
        '--license-url-template',
        'https://example.com/urn:{}',
        '--unknown-licenses',
        '--json-pp',
        result_file,
        test_dir,
    ]
    test_loc = test_env.get_test_loc(
        'plugin_license/license_url.expected.json')
    run_scan_click(args)
    check_json_scan(test_loc, result_file, regen=False)
def test_spdx_rdf_tree():
    test_dir = test_env.get_test_loc('spdx/tree/scan')
    result_file = test_env.get_temp_file('rdf')
    expected_file = test_env.get_test_loc('spdx/tree/expected.rdf')
    result = run_scan_click(['--format', 'spdx-rdf', test_dir, result_file])
    assert result.exit_code == 0
    check_rdf_scan(expected_file, result_file)
 def test_package_list_command(self, regen=REGEN_TEST_FIXTURES):
     expected_file = self.get_test_loc('plugin/help.txt')
     result = run_scan_click(['--list-packages'])
     if regen:
         with open(expected_file, 'w') as ef:
             ef.write(result.output)
     assert result.output == open(expected_file).read()
Пример #11
0
def test_scan_can_handle_licenses_with_unicode_metadata():
    test_dir = test_env.get_test_loc('license_with_unicode_meta')
    result_file = test_env.get_temp_file('json')

    result = run_scan_click(['--license', test_dir, result_file])
    assert result.exit_code == 0
    assert 'Scanning done' in result.output
Пример #12
0
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)
Пример #13
0
def test_scan_quiet_to_file_does_not_echo_anything():
    test_dir = test_env.extract_test_tar('info/basic.tgz')
    result1_file = test_env.get_temp_file('json')

    result1 = run_scan_click(['--quiet', '--info', test_dir, result1_file])
    assert result1.exit_code == 0
    assert not result1.output
Пример #14
0
def test_scan_works_with_multiple_processes_and_timeouts():
    # this contains test files with a lot of copyrights that should
    # take more thant timeout to scan
    test_dir = test_env.get_test_loc('timeout', copy=True)
    # add some random bytes to the test files to ensure that the license results will
    # not be cached
    import time, random
    for tf in fileutils.file_iter(test_dir):
        with open(tf, 'ab') as tfh:
            tfh.write('(c)' + str(time.time()) + repr([random.randint(0, 10 ** 6) for _ in range(10000)]) + '(c)')

    result_file = test_env.get_temp_file('json')

    result = run_scan_click(
        [ '--copyright', '--processes', '2',
         '--timeout', '0.000001',
         '--strip-root', '--format', 'json', test_dir, result_file],
    )

    assert result.exit_code == 1
    assert 'Scanning done' in result.output
    expected = [
        [(u'path', u'test1.txt'), (u'scan_errors', [u'ERROR: Processing interrupted: timeout after 0 seconds.'])],
        [(u'path', u'test2.txt'), (u'scan_errors', [u'ERROR: Processing interrupted: timeout after 0 seconds.'])],
        [(u'path', u'test3.txt'), (u'scan_errors', [u'ERROR: Processing interrupted: timeout after 0 seconds.'])],
    ]

    result_json = json.loads(open(result_file).read(), object_pairs_hook=OrderedDict)
    assert sorted(expected) == sorted(x.items() for x in result_json['files'])
Пример #15
0
def test_scan_does_not_fail_when_scanning_unicode_test_files_from_express():

    # On Windows, Python tar cannot extract these files. Other
    # extractors either fail or change the file name, making the test
    # moot. Git cannot check these files. So for now it makes no sense
    # to test this on Windows at all. Extractcode works fine, but does
    # rename the problematic files.

    test_dir = test_env.extract_test_tar_raw(b'unicode_fixtures.tar.gz')
    test_dir = fsencode(test_dir)

    args = [
        '-n0', '--info', '--license', '--copyright', '--package', '--email',
        '--url', '--strip-root', '--json', '-', test_dir
    ]
    run_scan_click(args)
Пример #16
0
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)
Пример #17
0
def test_csv_tree():
    test_dir = test_env.get_test_loc('csv/tree/scan')
    result_file = test_env.get_temp_file('csv')
    expected_file = test_env.get_test_loc('csv/tree/expected.csv')
    result = run_scan_click(['--copyright', '--format', 'csv', test_dir, result_file])
    assert result.exit_code == 0
    check_csvs(result_file, expected_file)
Пример #18
0
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_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',
        '--verbose',
        '--json',
        result_file,
        test_dir,
    ]

    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)
Пример #20
0
def test_scan_progress_display_is_not_damaged_with_long_file_names(
        monkeypatch):
    test_dir = test_env.get_test_loc('long_file_name')
    result_file = test_env.get_temp_file('json')
    args = ['--copyright', test_dir, '--json', result_file]
    result = run_scan_click(args, monkeypatch=monkeypatch)
    if on_windows:
        expected1 = 'Scanned: 0123456789012345678901234567890123456789.c'
        expected2 = 'Scanned: abcdefghijklmnopqrt...0123456789012345678'
        expected3 = 'abcdefghijklmnopqrtu0123456789012345678901234567890123456789abcdefghijklmnopqrtu0123456789012345678901234567890123456789.c'
        try:
            assert expected1 in result.output
            assert expected2 not in result.output
            assert expected3 not in result.output
        except:
            print()
            print('output:')
            print(result.output)
            print()
            raise
    else:
        expected1 = 'Scanned: abcdefghijklmnopqr...234567890123456789.c'
        expected2 = 'Scanned: 0123456789012345678901234567890123456789.c'
        expected3 = 'abcdefghijklmnopqrtu0123456789012345678901234567890123456789abcdefghijklmnopqrtu0123456789012345678901234567890123456789.c'
        assert expected1 in result.output
        assert expected2 in result.output
        assert expected3 not in result.output
Пример #21
0
def test_custom_format_with_custom_filename_fails_for_directory():
    test_dir = test_env.get_temp_dir('html')
    result_file = test_env.get_temp_file('html')

    result = run_scan_click(['--format', test_dir, test_dir, result_file])
    assert result.exit_code != 0
    assert 'Unknwow <format> or invalid template file path' in result.output
Пример #22
0
def test_scan_to_json_without_FILE_does_not_write_to_next_option():
    test_file = test_env.get_test_loc('license_text/test.txt')
    args = ['--json', '--info', test_file]
    result = run_scan_click(args, expected_rc=2)
    assert ('Error: Invalid value for "--json": Illegal file name '
            'conflicting with an option name: --info.').replace(
                "'", '"') in result.output.replace("'", '"')
Пример #23
0
def test_VirtualCodebase_output_with_from_json_is_same_as_original():
    test_file = test_env.get_test_loc('virtual_idempotent/codebase.json')
    result_file = test_env.get_temp_file('json')
    args = ['--from-json', test_file, '--json-pp', result_file]
    run_scan_click(args)
    expected = load_json_result(test_file, remove_file_date=True)
    results = load_json_result(result_file, remove_file_date=True)

    expected.pop('summary', None)
    results.pop('summary', None)

    expected_headers = expected.pop('headers', [])
    results_headers = results.pop('headers', [])

    assert json.dumps(results, indent=2) == json.dumps(expected, indent=2)
    assert len(results_headers) == len(expected_headers) + 1
def test_spdx_tv_basic():
    test_dir = test_env.get_test_loc('spdx/simple/test.txt')
    result_file = test_env.get_temp_file('tv')
    expected_file = test_env.get_test_loc('spdx/simple/expected.tv')
    result = run_scan_click(['--format', 'spdx-tv', test_dir, result_file])
    assert result.exit_code == 0
    check_tv_scan(expected_file, result_file)
Пример #25
0
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)
Пример #26
0
def check_scan_does_not_fail_when_scanning_unicode_files_and_paths(verbosity):
    test_dir = test_env.get_test_loc(u'unicodepath/uc')
    result_file = test_env.get_temp_file('json')

    if on_linux and py2:
        test_dir = fsencode(test_dir)
        result_file = fsencode(result_file)

    args = [
        '--info', '--license', '--copyright', '--package', '--email', '--url',
        '--strip-root', test_dir, '--json', result_file
    ] + ([verbosity] if verbosity else [])
    results = run_scan_click(args)

    # the paths for each OS ends up encoded differently.
    # See for details:
    # https://github.com/nexB/scancode-toolkit/issues/390
    # https://github.com/nexB/scancode-toolkit/issues/688
    # https://github.com/nexB/scancode-toolkit/issues/1635

    if on_macos_14_or_higher:
        expected = 'unicodepath/unicodepath.expected-mac14.json' + verbosity
    elif on_linux:
        expected = 'unicodepath/unicodepath.expected-linux.json' + verbosity
    elif on_mac:
        expected = 'unicodepath/unicodepath.expected-mac.json' + verbosity
    elif on_windows:
        expected = 'unicodepath/unicodepath.expected-win.json' + verbosity

    check_json_scan(test_env.get_test_loc(expected),
                    result_file,
                    remove_file_date=True,
                    regen=False)
    return results
def test_custom_format_with_custom_filename_fails_for_directory():
    test_dir = test_env.get_temp_dir('html')
    result_file = test_env.get_temp_file('html')

    result = run_scan_click(['--format', test_dir, test_dir, result_file])
    assert result.exit_code != 0
    assert 'Unknwow <format> or invalid template file path' in result.output
Пример #28
0
def test_scan_cli_help(regen=False):
    expected_file = test_env.get_test_loc('help/help.txt')
    result = run_scan_click(['--help'])
    if regen:
        with io.open(expected_file, 'w', encoding='utf-8') as ef:
            ef.write(result.output)
    assert open(expected_file).read() == result.output
Пример #29
0
def test_scan_info_returns_full_root():
    test_dir = test_env.extract_test_tar('info/basic.tgz')

    result = run_scan_click(['--info', '--full-root', test_dir])
    assert result.exit_code == 0
    assert 'Scanning done' in result.output
    assert fileutils.as_posixpath(test_dir) in result.output
Пример #30
0
def test_scan_can_handle_licenses_with_unicode_metadata():
    test_dir = test_env.get_test_loc('license_with_unicode_meta')
    result_file = test_env.get_temp_file('json')

    result = run_scan_click(['--license', test_dir, result_file])
    assert result.exit_code == 0
    assert 'Scanning done' in result.output
Пример #31
0
 def test_scancode_ignore_glob_path(self):
     test_dir = self.extract_test_tar('plugin_ignore/user.tgz')
     result_file = self.get_temp_file('json')
     args = ['--copyright', '--strip-root', '--ignore', '*/src/test/*', test_dir, '--json', result_file]
     run_scan_click(args)
     scan_result = load_json_result(result_file)
     assert 2 == scan_result['headers'][0]['extra_data']['files_count']
     scan_locs = [x['path'] for x in scan_result['files']]
     expected = [
         u'user',
         u'user/ignore.doc',
         u'user/src',
         u'user/src/ignore.doc',
         u'user/src/test'
     ]
     assert expected == scan_locs
Пример #32
0
def test_scan_quiet_to_file_does_not_echo_anything():
    test_dir = test_env.extract_test_tar('info/basic.tgz')
    result1_file = test_env.get_temp_file('json')

    result1 = run_scan_click(['--quiet', '--info', test_dir, result1_file])
    assert result1.exit_code == 0
    assert not result1.output
def test_spdx_tv_with_license_ref_with_text():
    test_dir = test_env.get_test_loc('spdx/license_ref/scan')
    result_file = test_env.get_temp_file('tv')
    expected_file = test_env.get_test_loc('spdx/license_ref/expected_with_text.tv')
    result = run_scan_click(['--format', 'spdx-tv', '--license-text', test_dir, result_file])
    assert result.exit_code == 0
    check_tv_scan(expected_file, result_file)
def test_spdx_rdf_with_known_licenses_with_text():
    test_dir = test_env.get_test_loc('spdx/license_known/scan')
    result_file = test_env.get_temp_file('rdf')
    expected_file = test_env.get_test_loc('spdx/license_known/expected_with_text.rdf')
    result = run_scan_click(['--format', 'spdx-rdf', '--license-text', test_dir, result_file])
    assert result.exit_code == 0
    check_rdf_scan(expected_file, result_file)
Пример #35
0
 def test_full_summary_by_facet(self):
     test_dir = self.get_test_loc('tallies/full_tallies/scan')
     result_file = self.get_temp_file('json')
     expected_file = self.get_test_loc(
         'tallies/full_tallies/tallies_by_facet.expected.json')
     run_scan_click([
         '-clpieu', '--facet', 'dev=*.java', '--facet', 'dev=*.cs',
         '--facet', 'dev=*ada*', '--facet', 'data=*.S', '--facet',
         'tests=*infback9*', '--facet', 'docs=*README', '--tallies',
         '--tallies-by-facet', '--json-pp', result_file, test_dir
     ])
     check_json_scan(expected_file,
                     result_file,
                     remove_uuid=True,
                     remove_file_date=True,
                     regen=REGEN_TEST_FIXTURES)
Пример #36
0
def test_scan_should_not_fail_on_faulty_pdf_or_pdfminer_bug_but_instead_report_errors_and_keep_trucking_with_html_app():
    test_file = test_env.get_test_loc('failing/patchelf.pdf')
    result_file = test_env.get_temp_file('test.app.html')

    result = run_scan_click([ '--copyright', '--format', 'html-app', test_file, result_file])
    assert result.exit_code == 1
    assert 'Scanning done' in result.output
Пример #37
0
def test_scan_works_with_multiple_processes_and_timeouts():
    # this contains test files with a lot of copyrights that should
    # take more thant timeout to scan
    test_dir = test_env.get_test_loc('timeout', copy=True)
    # add some random bytes to the test files to ensure that the license results will
    # not be cached
    import time, random
    for tf in fileutils.resource_iter(test_dir, with_dirs=False):
        with open(tf, 'ab') as tfh:
            tfh.write('(c)' + str(time.time()) +
                      repr([random.randint(0, 10**6)
                            for _ in range(10000)]) + '(c)')

    result_file = test_env.get_temp_file('json')

    args = [
        '--copyright', '--processes', '2', '--timeout', '0.000001',
        '--strip-root', test_dir, '--json', result_file
    ]
    run_scan_click(args, expected_rc=1)

    expected = [
        [(u'path', u'test1.txt'), (u'type', u'file'), (u'authors', []),
         (u'copyrights', []), (u'holders', []),
         (u'scan_errors',
          [
              u'ERROR: for scanner: copyrights:\nERROR: Processing interrupted: timeout after 0 seconds.'
          ])],
        [(u'path', u'test2.txt'), (u'type', u'file'), (u'authors', []),
         (u'copyrights',
          []),
         (u'holders',
          []),
         (u'scan_errors', [
             u'ERROR: for scanner: copyrights:\nERROR: Processing interrupted: timeout after 0 seconds.'
         ])],
        [(u'path', u'test3.txt'), (u'type', u'file'), (u'authors', []),
         (u'copyrights', []), (u'holders', []),
         (u'scan_errors', [
             u'ERROR: for scanner: copyrights:\nERROR: Processing interrupted: timeout after 0 seconds.'
         ])]
    ]

    result_json = json.loads(open(result_file).read(),
                             object_pairs_hook=OrderedDict)
    assert sorted(sorted(x) for x in expected) == sorted(
        sorted(x.items()) for x in result_json['files'])
Пример #38
0
def test_csv_tree():
    test_dir = test_env.get_test_loc('csv/tree/scan')
    result_file = test_env.get_temp_file('csv')
    expected_file = test_env.get_test_loc('csv/tree/expected.csv')
    result = run_scan_click(
        ['--copyright', '--format', 'csv', test_dir, result_file])
    assert result.exit_code == 0
    check_csvs(result_file, expected_file)
Пример #39
0
def test_scan_license_with_url_template():
    test_dir = test_env.get_test_loc('license_url', copy=True)

    result = run_scan_click(['--license', '--license-url-template', 'https://example.com/urn:{}', test_dir])
    assert result.exit_code == 0
    assert 'Scanning done' in result.output
    assert 'https://example.com/urn:apache-1.0' in result.output
    assert 'https://example.com/urn:public-domain' in result.output
Пример #40
0
def test_merge_multiple_scans():
    test_file_1 = test_env.get_test_loc(
        'resource/virtual_codebase/sample.json')
    test_file_2 = test_env.get_test_loc(
        'resource/virtual_codebase/thirdparty.json')
    result_file = test_env.get_temp_file('json')
    args = [
        '--from-json', test_file_1, '--from-json', test_file_2, '--json',
        result_file
    ]
    run_scan_click(args, expected_rc=0)
    expected = test_env.get_test_loc('resource/virtual_codebase/out.json')
    with open(expected, read_mode) as f:
        expected_files = json.loads(f.read())['files']
    with open(result_file, read_mode) as f:
        result_files = json.loads(f.read())['files']
    assert expected_files == result_files
Пример #41
0
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_paths_are_posix_in_html_format_output():
    test_dir = test_env.get_test_loc('templated/simple')
    result_file = test_env.get_temp_file('html')

    result = run_scan_click(['--copyright', '--format', 'html', test_dir, result_file])
    assert result.exit_code == 0
    assert 'Scanning done' in result.output
    assert '/copyright_acme_c-c.c' in open(result_file).read()
def test_custom_format_with_custom_filename():
    test_dir = test_env.get_test_loc('templated/simple')
    custom_template = test_env.get_test_loc('templated/sample-template.html')
    result_file = test_env.get_temp_file('html')

    result = run_scan_click(['--format', custom_template, test_dir, result_file])
    assert result.exit_code == 0
    assert 'Custom Template' in open(result_file).read()
Пример #44
0
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_consolidate_package_files_should_not_be_considered_in_license_holder_consolidated_component(
         self):
     scan_loc = self.get_test_loc(
         'plugin_consolidate/package-files-not-counted-in-license-holders')
     result_file = self.get_temp_file('json')
     # There should not be a consolidated component for license-holder, even
     # though every single file in this directory contains the same license
     # expression and holder
     expected_file = self.get_test_loc(
         'plugin_consolidate/package-files-not-counted-in-license-holders-expected.json'
     )
     run_scan_click(
         ['-clip', scan_loc, '--consolidate', '--json', result_file])
     check_json_scan(expected_file,
                     result_file,
                     regen=False,
                     remove_file_date=True)
Пример #46
0
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)
Пример #47
0
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)
Пример #48
0
def test_verbose_option_with_copyrights(monkeypatch):
    test_dir = test_env.get_test_loc('copyright', copy=True)
    result_file = test_env.get_temp_file('json')
    args = ['--copyright', '--verbose', test_dir, '--json', result_file]
    result = run_scan_click(args, monkeypatch=monkeypatch)
    assert os.path.exists(result_file)
    assert 'copyright_acme_c-c.c' in result.output
    assert len(open(result_file).read()) > 10
Пример #49
0
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)
Пример #50
0
def test_csv_minimal():
    test_dir = test_env.get_test_loc('csv/srp')
    result_file = test_env.get_temp_file('csv')
    expected_file = test_env.get_test_loc('csv/srp.csv')
    result = run_scan_click(['--copyright', '--format', 'csv', test_dir, result_file])
    assert result.exit_code == 0
    assert 'Scanning done' in result.output
    check_csvs(result_file, expected_file)
Пример #51
0
def test_scan_errors_out_with_conflicting_verbosity_options():
    test_file = test_env.get_test_loc('license_text/test.txt')
    result_file = test_env.get_temp_file('results.json')
    args = ['--quiet', '--verbose', '--json', result_file, '--info', test_file]
    result = run_scan_click(args, expected_rc=2)
    assert ('Error: The option --quiet cannot be used together with the '
            '--verbose option(s) and --verbose is used. You can set only one of '
            'these options at a time.') in result.output
Пример #52
0
def test_scan_quiet_to_stdout_only_echoes_json_results():
    test_dir = test_env.extract_test_tar('info/basic.tgz')
    result_file = test_env.get_temp_file('json')
    args = ['--quiet', '--info', test_dir, '--json-pp', result_file]
    result_to_file = run_scan_click(args)
    assert not result_to_file.output

    # also test with an output of JSON to stdout
    args = ['--quiet', '--info', test_dir, '--json-pp', '-']
    result_to_stdout = run_scan_click(args)

    # outputs to file or stdout should be identical
    result1_output = open(result_file).read()
    json_result1_output = load_json_result_from_string(result1_output)
    json_result_to_stdout = load_json_result_from_string(result_to_stdout.output)
    # cleanup JSON
    assert json_result_to_stdout == json_result1_output
Пример #53
0
 def test_full_summary_by_facet(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_by_facet.expected.json')
     run_scan_click([
         '-clpieu',
         '--facet', 'dev=*.java',
         '--facet', 'dev=*.cs',
         '--facet', 'dev=*ada*',
         '--facet', 'data=*.S',
         '--facet', 'tests=*infback9*',
         '--facet', 'docs=*README',
         '--summary',
         '--summary-by-facet',
         '--json-pp', result_file, test_dir
     ])
     check_json_scan(expected_file, result_file, remove_file_date=True, regen=False)
Пример #54
0
 def test_scancode_ignore_single_file(self):
     test_dir = self.extract_test_tar('plugin_ignore/user.tgz')
     result_file = self.get_temp_file('json')
     args = [
         '--copyright', '--strip-root', '--ignore', 'sample.doc', test_dir,
         '--json', result_file
     ]
     run_scan_click(args)
     scan_result = load_json_result(result_file)
     assert scan_result['headers'][0]['extra_data']['files_count'] == 3
     # FIXME: add assert 3 == scan_result['dirs_count']
     scan_locs = [x['path'] for x in scan_result['files']]
     expected = [
         'user', 'user/ignore.doc', 'user/src', 'user/src/ignore.doc',
         'user/src/test', 'user/src/test/sample.txt'
     ]
     assert scan_locs == expected
Пример #55
0
def test_verbose_option_with_packages(monkeypatch):
    test_dir = test_env.get_test_loc('package', copy=True)
    result_file = test_env.get_temp_file('json')
    args = ['--package', '--verbose', test_dir, '--json', result_file]
    result = run_scan_click(args, monkeypatch=monkeypatch)
    assert 'package.json' in result.output
    assert os.path.exists(result_file)
    result = open(result_file).read()
    assert 'package.json' in result
Пример #56
0
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
Пример #57
0
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)
Пример #58
0
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)
Пример #59
0
def test_copyright_option_detects_copyrights():
    test_dir = test_env.get_test_loc('copyright', copy=True)
    result_file = test_env.get_temp_file('json')

    result = run_scan_click(['--copyright', test_dir, result_file])
    assert result.exit_code == 0
    assert 'Scanning done' in result.output
    assert os.path.exists(result_file)
    assert len(open(result_file).read()) > 10
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)