Ejemplo n.º 1
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_process_codebase_license_only_valid_policy_file(self):
        test_dir = self.extract_test_tar(
            'plugin_license_policy/policy-codebase.tgz')
        policy_file = self.get_test_loc(
            'plugin_license_policy/process_codebase_license_only_valid_policy_file.yml'
        )

        result_file = self.get_temp_file('json')

        run_scan_click([
            '--license', '--license-policy', policy_file, test_dir,
            '--json-pp', result_file
        ])

        scan_result = load_json_result(result_file)

        for result in scan_result['files']:
            assert 'license_policy' in result.keys()

        approved, restricted = 0, 0
        for result in scan_result['files']:
            if result.get('license_policy') != {}:
                if result.get('license_policy').get(
                        'label') == "Approved License":
                    approved += 1
                if result.get('license_policy').get(
                        'label') == "Restricted License":
                    restricted += 1

        assert approved == 1
        assert restricted == 4
Ejemplo n.º 3
0
 def test_scancode_multiple_ignores(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', '--ignore', '*.doc', test_dir, '--json', result_file]
     run_scan_click(args)
     scan_result = load_json_result(result_file)
     assert 0 == scan_result['headers'][0]['extra_data']['files_count']
     scan_locs = [x['path'] for x in scan_result['files']]
     assert [u'user', u'user/src'] == scan_locs
Ejemplo n.º 4
0
def test_scan_with_timing_jsonpp_return_timings_for_each_scanner():
    test_dir = test_env.extract_test_tar('timing/basic.tgz')
    result_file = test_env.get_temp_file('json')
    args = ['--email', '--url', '--license', '--copyright', '--info',
            '--package', '--timing', '--verbose', '--json-pp', result_file, test_dir]
    run_scan_click(args)
    file_results = load_json_result(result_file)['files']
    # NB: these keys are the name of the scan plugins in setup.py
    expected = set(['emails', 'urls', 'licenses', 'copyrights', 'info', 'packages'])
    check_timings(expected, file_results)
Ejemplo n.º 5
0
 def test_scancode_ignore_vcs_files_and_dirs_by_default_no_multiprocess(self):
     test_dir = self.extract_test_tar('plugin_ignore/vcs.tgz')
     result_file = self.get_temp_file('json')
     args = ['--copyright', '--strip-root', '--processes', '0', test_dir, '--json', result_file]
     run_scan_click(args)
     scan_result = load_json_result(result_file)
     # a single test.tst file and its directory that is not a VCS file should
     # be listed
     assert 1 == scan_result['headers'][0]['extra_data']['files_count']
     scan_locs = [x['path'] for x in scan_result['files']]
     assert [u'vcs', u'vcs/test.txt'] == scan_locs
    def test_process_codebase_info_license_duplicate_key_policy_file(self):
        test_dir = self.extract_test_tar('plugin_license_policy/policy-codebase.tgz')
        policy_file = self.get_test_loc('plugin_license_policy/process_codebase_info_license_duplicate_key_policy_file.yml')

        result_file = self.get_temp_file('json')

        run_scan_click(['--info', '--license', '--license-policy', policy_file, test_dir, '--json-pp', result_file])

        scan_result = load_json_result(result_file)

        for result in scan_result['files']:
            assert 'license_policy' in result.keys()
            assert {} == result['license_policy']
Ejemplo n.º 7
0
 def test_scancode_codebase_attempt_to_access_an_ignored_resourced_cached_to_disk(self):
     test_dir = self.extract_test_tar('plugin_ignore/user.tgz')
     result_file = self.get_temp_file('json')
     args = ['--copyright', '--strip-root', '--ignore', 'test', test_dir, '--max-in-memory', '1', '--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',
     ]
     assert expected == scan_locs
Ejemplo n.º 8
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