def test_can_process_live_scan_for_packages_with_root():
    test_dir = test_env.get_test_loc('csv/packages/scan')
    result_file = test_env.get_temp_file('csv')
    args = ['--package', test_dir, '--csv', result_file]
    run_scan_plain(args)
    expected_file = test_env.get_test_loc('csv/packages/expected.csv')
    check_csvs(result_file, expected_file)
def test_output_handles_non_standard_data():
    test_file = test_env.get_test_loc('csv/non-standard/identified.json')
    result_file = test_env.get_temp_file('csv')
    args = ['--from-json', test_file, '--csv', result_file]
    run_scan_plain(args)
    expected_file = test_env.get_test_loc('csv/non-standard/identified.csv')
    check_csvs(result_file, expected_file, regen=False)
Esempio n. 3
0
def test_can_process_live_scan_with_all_options():
    test_dir = test_env.get_test_loc('csv/livescan/scan')
    result_file = test_env.get_temp_file('csv')
    args = ['-clip', '--email', '--url', '--strip-root', test_dir, '--csv', result_file]
    run_scan_plain(args)
    expected_file = test_env.get_test_loc('csv/livescan/expected.csv')
    check_csvs(result_file, expected_file, regen=False)
def test_can_process_live_scan_for_packages_strip_root():
    test_dir = test_env.get_test_loc('csv/packages/scan')
    result_file = test_env.get_temp_file('csv')
    args = ['--package', '--strip-root', test_dir, '--csv', result_file]
    run_scan_plain(args)
    expected_file = test_env.get_test_loc('csv/packages/expected-no-root.csv')
    check_csvs(result_file, expected_file, regen=False)
Esempio n. 5
0
def test_spdx_tv_with_empty_scan():
    test_file = test_env.get_test_loc('spdx/empty/scan')
    result_file = test_env.get_temp_file('spdx.tv')
    expected_file = test_env.get_test_loc('spdx/empty/expected.tv')
    args = ['--license', '--strip-root', '--info', '--only-findings', test_file, '--spdx-tv', result_file]
    run_scan_plain(args)
    check_tv_scan(expected_file, result_file, regen=False)
def test_output_contains_license_expression():
    test_file = test_env.get_test_loc('csv/expressions/scan.json')
    result_file = test_env.get_temp_file('csv')
    args = ['--from-json', test_file, '--csv', result_file]
    run_scan_plain(args)
    expected_file = test_env.get_test_loc('csv/expressions/expected.csv')
    check_csvs(result_file, expected_file, regen=False)
def check_debian_copyright_output(test_dir,
                                  expected_file,
                                  regen=REGEN_TEST_FIXTURES):
    """
    Rrun a scan on ``test_dir`` with a debian output and check if the created
    file matches ``expected_file``.
    """
    result_file = test_env.get_temp_file('copyright')
    args = [
        '--copyright',
        '--license',
        '--license-text',
        '--debian',
        result_file,
        test_dir,
    ]

    run_scan_plain(args)

    if regen:
        shutil.copyfile(result_file, expected_file)

    with open(expected_file) as exp:
        expected = exp.read()

    with open(result_file) as res:
        result = res.read()

    assert result == expected
Esempio n. 8
0
def test_spdx_rdf_with_empty_scan():
    test_file = test_env.get_test_loc('spdx/empty/scan')
    result_file = test_env.get_temp_file('spdx.rdf')
    args = ['--license', '--strip-root', '--info', '--only-findings', test_file, '--spdx-rdf', result_file]
    run_scan_plain(args)
    expected = "<!-- No results for package 'scan'. -->\n"
    results = open(result_file).read()
    assert results == expected
Esempio n. 9
0
def test_spdx_rdf_with_or_later_license_does_not_fail():
    test_file = test_env.get_test_loc('spdx/or_later/test.java')
    result_file = test_env.get_temp_file('rdf')
    expected_file = test_env.get_test_loc('spdx/or_later/expected.rdf')
    args = ['--license', '--copyright', '--info', '--strip-root',
            '--license-text', test_file, '--spdx-rdf', result_file]
    run_scan_plain(args)
    check_rdf_scan(expected_file, result_file)
Esempio n. 10
0
def test_spdx_rdf_with_unicode_license_text_does_not_fail():
    test_file = test_env.get_test_loc('spdx/unicode/et131x.h')
    result_file = test_env.get_temp_file('rdf')
    expected_file = test_env.get_test_loc('spdx/unicode/expected.rdf')
    args = ['--license', '--copyright', '--info', '--strip-root',
            '--license-text', test_file, '--spdx-rdf', result_file]
    run_scan_plain(args)
    check_rdf_scan(expected_file, result_file)
Esempio n. 11
0
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)
    args = ['-ci', '--strip-root', test_file, '--json', result_file]
    run_scan_plain(args, cwd=work_dir)
    check_json_scan(test_env.get_test_loc(expected_file), result_file, remove_file_date=True, regen=False)
Esempio n. 12
0
def test_scan_does_not_report_errors_on_incorrect_package_manifest():
    test_file = test_env.get_test_loc('errors/broken_packages')
    args = ['-pi', '--verbose', '-n', '0', test_file, '--json', '-']
    _rc, stdout, stderr = run_scan_plain(args, expected_rc=0)
    assert 'Some files failed to scan properly:' not in stderr
    assert 'ERROR: Processing interrupted: timeout after 0 seconds.' not in stdout
    assert 'ERROR: Processing interrupted: timeout after 0 seconds.' not in stderr
Esempio n. 13
0
def test_scan_logs_errors_messages():
    test_file = test_env.get_test_loc('errors', copy=True)
    rc, stdout, stderr = run_scan_plain(['-pi', test_file, ])
    assert rc == 1
    assert 'package.json' in stderr
    assert 'delimiter: line 5 column 12' in stdout
    assert 'ValueError: Expecting' not in stdout
Esempio n. 14
0
def test_scan_logs_errors_messages_not_verbosely_on_stderr():
    test_file = test_env.get_test_loc('errors/many_copyrights.c')
    # we use very short timeouts to simulate an error
    args = ['-c', '-n', '0', '--timeout', '0.0001', test_file, '--json', '-']
    _rc, stdout, stderr = run_scan_plain(args, expected_rc=1)
    assert 'Some files failed to scan properly:' in stderr
    assert 'Path: many_copyrights.c' in stderr
    assert 'ERROR: Processing interrupted: timeout after 0 seconds.' in stdout, stdout
    assert 'ERROR: Processing interrupted: timeout after 0 seconds.' not in stderr, stderr
Esempio n. 15
0
def test_scan_logs_errors_messages_verbosely_with_verbose_and_multiprocessing():
    test_file = test_env.get_test_loc('errors/many_copyrights.c')
    # we use a short timeout and a --test-slow-mode --email scan to simulate an error
    args = ['-e', '--test-slow-mode', '--verbose', '-n', '2', '--timeout', '0.0001',
            test_file, '--json', '-']
    _rc, stdout, stderr = run_scan_plain(args, expected_rc=1)
    assert 'Some files failed to scan properly:' in stderr
    assert 'Path: many_copyrights.c' in stderr
    assert 'ERROR: Processing interrupted: timeout after 0 seconds.' in stdout
    assert 'ERROR: Processing interrupted: timeout after 0 seconds.' in stderr
Esempio n. 16
0
def test_scan_logs_errors_messages():
    test_file = test_env.get_test_loc('errors', copy=True)
    rc, stdout, stderr = run_scan_plain([
        '-pi',
        test_file,
    ])
    assert rc == 1
    assert 'package.json' in stderr
    assert 'delimiter: line 5 column 12' in stdout
    assert 'ValueError: Expecting' not in stdout
Esempio n. 17
0
def test_spdx_rdf_with_or_later_license_does_not_fail():
    test_file = test_env.get_test_loc('spdx/or_later/test.java')
    result_file = test_env.get_temp_file('rdf')
    expected_file = test_env.get_test_loc('spdx/or_later/expected.rdf')
    rc, stdout, stderr = run_scan_plain([
        '--license', '--copyright', '--info', '--format', 'spdx-rdf',
        '--strip-root', '--license-text', '--diag', test_file, result_file
    ])
    if rc != 0:
        print('stdout', stdout)
        print('stderr', stderr)
    assert rc == 0
    check_rdf_scan(expected_file, result_file, regen=False)
Esempio n. 18
0
def test_spdx_tv_with_unicode_license_text_does_not_fail():
    test_file = test_env.get_test_loc('spdx/unicode/et131x.h')
    result_file = test_env.get_temp_file('tv')
    expected_file = test_env.get_test_loc('spdx/unicode/expected.tv')
    rc, stdout, stderr = run_scan_plain([
        '--license', '--copyright', '--info', '--format', 'spdx-tv',
        '--strip-root', '--license-text', '--diag', test_file, result_file
    ])
    if rc != 0:
        print('stdout', stdout)
        print('stderr', stderr)
    assert rc == 0
    check_tv_scan(expected_file, result_file, regen=False)
Esempio n. 19
0
def test_scan_progress_display_is_not_damaged_with_long_file_names_plain():
    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]
    _rc, stdout, stderr = run_scan_plain(args)
    expected1 = 'Scanned: abcdefghijklmnopqr...234567890123456789.c'
    expected2 = 'Scanned: 0123456789012345678901234567890123456789.c'
    expected3 = 'abcdefghijklmnopqrtu0123456789012345678901234567890123456789abcdefghijklmnopqrtu0123456789012345678901234567890123456789.c'
    assert expected1 not in stdout
    assert expected2 not in stdout
    assert expected3 not in stdout
    assert expected1 not in stderr
    assert expected2 not in stderr
    assert expected3 not in stderr
def test_spdx_rdf_with_or_later_license_does_not_fail():
    test_file = test_env.get_test_loc('spdx/or_later/test.java')
    result_file = test_env.get_temp_file('rdf')
    expected_file = test_env.get_test_loc('spdx/or_later/expected.rdf')
    rc, stdout, stderr = run_scan_plain([
        '--license', '--copyright', '--info',
        '--format', 'spdx-rdf', '--strip-root', '--license-text',
        '--diag',
         test_file, result_file
    ])
    if rc != 0:
        print('stdout', stdout)
        print('stderr', stderr)
    assert rc == 0
    check_rdf_scan(expected_file, result_file, regen=False)
def test_can_process_live_scan_with_all_options():
    test_dir = test_env.get_test_loc('csv/livescan/scan')
    result_file = test_env.get_temp_file('csv')
    rc, stdout, stderr = run_scan_plain(
        ['-clip', '--email', '--url', '--strip-root', '--format', 'csv',
         test_dir, result_file])
    try:
        assert rc == 0
    except:
        print(stdout, stderr)
        print(stdout, stderr)
        raise

    expected_file = test_env.get_test_loc('csv/livescan/expected.csv')
    check_csvs(result_file, expected_file, regen=False)
def test_spdx_tv_with_unicode_license_text_does_not_fail():
    test_file = test_env.get_test_loc('spdx/unicode/et131x.h')
    result_file = test_env.get_temp_file('tv')
    expected_file = test_env.get_test_loc('spdx/unicode/expected.tv')
    rc, stdout, stderr = run_scan_plain([
        '--license', '--copyright', '--info',
        '--format', 'spdx-tv', '--strip-root', '--license-text',
        '--diag',
         test_file, result_file
    ])
    if rc != 0:
        print('stdout', stdout)
        print('stderr', stderr)
    assert rc == 0
    check_tv_scan(expected_file, result_file, regen=False)
Esempio n. 23
0
def test_can_process_live_scan_with_all_options():
    test_dir = test_env.get_test_loc('csv/livescan/scan')
    result_file = test_env.get_temp_file('csv')
    rc, stdout, stderr = run_scan_plain([
        '-clip', '--email', '--url', '--strip-root', '--format', 'csv',
        test_dir, result_file
    ])
    try:
        assert rc == 0
    except:
        print(stdout, stderr)
        print(stdout, stderr)
        raise

    expected_file = test_env.get_test_loc('csv/livescan/expected.csv')
    check_csvs(result_file, expected_file, regen=False)
Esempio n. 24
0
def test_scan_keep_temp_files_is_false_by_default():
    test_file = test_env.get_test_loc('tempfiles/samples')
    result_file = test_env.get_temp_file('json')
    # mock using a well defined temporary directory
    temp_directory = test_env.get_temp_dir()
    env = dict(os.environ)
    env.update({'SCANCODE_TEMP': temp_directory})
    args = [
        '--info', test_file, '--json', result_file,
        # this forces using a temp file cache so that we have temp files
        '--max-in-memory', '-1']
    _ = run_scan_plain(args, expected_rc=0, env=env)
    # the SCANCODE_TEMP dir is not deleted, but it should be empty
    assert os.path.exists(temp_directory)
    # this does not make sense but that's what is seen in practice
    expected = 2 if (on_windows or on_mac_new_py) else 1
    assert len(list(os.walk(temp_directory))) == expected
Esempio n. 25
0
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)
Esempio n. 26
0
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)
Esempio n. 27
0
def test_scan_keep_temp_files_keeps_files():
    test_file = test_env.get_test_loc('tempfiles/samples')
    result_file = test_env.get_temp_file('json')
    # mock using a well defined temporary directory
    temp_directory = test_env.get_temp_dir()
    env = dict(os.environ)
    env.update({'SCANCODE_TEMP': temp_directory})
    args = [
        '--keep-temp-files',
        '--info',
        test_file,
        '--json',
        result_file,
        # this forces using a temp file cache
        '--max-in-memory',
        '-1'
    ]
    _rc, _stdout, _stderr = run_scan_plain(args, expected_rc=0, env=env)

    # the SCANCODE_TEMP dir is not deleted, but it should not be empty
    assert os.path.exists(temp_directory)
    # this does not make sense but that's what is seen in practice
    expected = 8 if on_windows else 7
    assert expected == len(list(os.walk(temp_directory)))