Skip to content

Commit 9c9acef

Browse files
committed
Create test for use-cached-results cli option
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent 95e3180 commit 9c9acef

9 files changed

Lines changed: 732 additions & 0 deletions

File tree

tests/scancode/data/results_cache/expected.json

Lines changed: 605 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "async",
3+
"description": "Higher-order functions and common patterns for asynchronous code",
4+
"main": "lib/async.js",
5+
"author": {
6+
"name": "Caolan McMahon"
7+
},
8+
"version": "1.2.1",
9+
"keywords": [
10+
"async",
11+
"callback",
12+
"utility",
13+
"module"
14+
],
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/caolan/async.git"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/caolan/async/issues"
21+
},
22+
"license": "MIT",
23+
"devDependencies": {
24+
"benchmark": "github:bestiejs/benchmark.js",
25+
"coveralls": "^2.11.2",
26+
"jshint": "~2.7.0",
27+
"lodash": ">=2.4.1",
28+
"mkdirp": "~0.5.1",
29+
"nodeunit": ">0.0.0",
30+
"nyc": "^2.1.0",
31+
"uglify-js": "1.2.x",
32+
"yargs": "~3.9.1"
33+
},
34+
"jam": {
35+
"main": "lib/async.js",
36+
"include": [
37+
"lib/async.js",
38+
"README.md",
39+
"LICENSE"
40+
],
41+
"categories": [
42+
"Utilities"
43+
]
44+
},
45+
"scripts": {
46+
"test": "npm run-script lint && nodeunit test/test-async.js",
47+
"lint": "jshint lib/*.js test/*.js perf/*.js",
48+
"coverage": "nyc npm test && nyc report",
49+
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
50+
},
51+
"spm": {
52+
"main": "lib/async.js"
53+
},
54+
"volo": {
55+
"main": "lib/async.js",
56+
"ignore": [
57+
"**/.*",
58+
"node_modules",
59+
"bower_components",
60+
"test",
61+
"tests"
62+
]
63+
},
64+
"gitHead": "b66e85d1cca8c8056313253f22d18f571e7001d2",
65+
"homepage": "https://github.com/caolan/async#readme",
66+
"_id": "async@1.2.1",
67+
"_shasum": "a4816a17cd5ff516dfa2c7698a453369b9790de0",
68+
"_from": "async@*",
69+
"_npmVersion": "2.9.0",
70+
"_nodeVersion": "2.0.2",
71+
"_npmUser": {
72+
"name": "aearly",
73+
"email": "alexander.early@gmail.com"
74+
},
75+
"maintainers": [
76+
{
77+
"name": "caolan",
78+
"email": "caolan.mcmahon@gmail.com"
79+
},
80+
{
81+
"name": "beaugunderson",
82+
"email": "beau@beaugunderson.com"
83+
},
84+
{
85+
"name": "aearly",
86+
"email": "alexander.early@gmail.com"
87+
}
88+
],
89+
"dist": {
90+
"shasum": "a4816a17cd5ff516dfa2c7698a453369b9790de0",
91+
"tarball": "http://registry.npmjs.org/async/-/async-1.2.1.tgz"
92+
},
93+
"directories": {},
94+
"_resolved": "https://registry.npmjs.org/async/-/async-1.2.1.tgz",
95+
"readme": "ERROR: No README data found!"
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"copyrights": [], "holders": [], "authors": [{"author": "Caolan McMahon", "start_line": 5, "end_line": 6}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"emails": [{"email": "alexander.early@gmail.com", "start_line": 73, "end_line": 73}, {"email": "caolan.mcmahon@gmail.com", "start_line": 78, "end_line": 78}, {"email": "beau@beaugunderson.com", "start_line": 82, "end_line": 82}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"date": "2024-06-23", "size": 2361, "sha1": "29c3cacb4c3abe6f69dc87a77d9c9105546f6978", "md5": "b8be873c4fb54a835bfac7eb47a6531e", "sha256": "cb6f5a82e473620da4d1aecf82dd4d4fa9ada393a7679b28a42cac86f0a83c92", "sha1_git": "247e1784187cc3929165ec2d534f2134b9147ecd", "mime_type": "application/json", "file_type": "JSON data", "programming_language": null, "is_binary": false, "is_text": true, "is_archive": false, "is_media": false, "is_source": false, "is_script": false}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"detected_license_expression": "mit", "detected_license_expression_spdx": "MIT", "license_detections": [{"license_expression": "mit", "license_expression_spdx": "MIT", "matches": [{"license_expression": "mit", "license_expression_spdx": "MIT", "from_file": null, "start_line": 22, "end_line": 22, "matcher": "2-aho", "score": 100.0, "matched_length": 2, "match_coverage": 100.0, "rule_relevance": 100, "rule_identifier": "mit_30.RULE", "rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mit_30.RULE"}], "identifier": "mit-3fce6ea2-8abd-6c6b-3ede-a37af7c6efee"}], "license_clues": [], "percentage_of_license_text": 0.83}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"package_data": [{"type": "npm", "namespace": null, "name": "async", "version": "1.2.1", "qualifiers": {}, "subpath": null, "primary_language": "JavaScript", "description": "Higher-order functions and common patterns for asynchronous code", "release_date": null, "parties": [{"type": "person", "role": "author", "name": "Caolan McMahon", "email": null, "url": null}, {"type": "person", "role": "maintainer", "name": "caolan", "email": "caolan.mcmahon@gmail.com", "url": null}, {"type": "person", "role": "maintainer", "name": "beaugunderson", "email": "beau@beaugunderson.com", "url": null}, {"type": "person", "role": "maintainer", "name": "aearly", "email": "alexander.early@gmail.com", "url": null}], "keywords": ["async", "callback", "utility", "module"], "homepage_url": "https://github.com/caolan/async#readme", "download_url": "https://registry.npmjs.org/async/-/async-1.2.1.tgz", "size": null, "sha1": "a4816a17cd5ff516dfa2c7698a453369b9790de0", "md5": null, "sha256": null, "sha512": null, "bug_tracking_url": "https://github.com/caolan/async/issues", "code_view_url": null, "vcs_url": "git+https://github.com/caolan/async.git@b66e85d1cca8c8056313253f22d18f571e7001d2", "copyright": null, "holder": null, "declared_license_expression": "mit", "declared_license_expression_spdx": "MIT", "license_detections": [{"license_expression": "mit", "license_expression_spdx": "MIT", "matches": [{"license_expression": "mit", "license_expression_spdx": "MIT", "from_file": null, "start_line": 1, "end_line": 1, "matcher": "1-spdx-id", "score": 100.0, "matched_length": 1, "match_coverage": 100.0, "rule_relevance": 100, "rule_identifier": "spdx-license-identifier-mit-5da48780aba670b0860c46d899ed42a0f243ff06", "rule_url": null, "matched_text": "MIT"}], "identifier": "mit-a822f434-d61f-f2b1-c792-8b8cb9e7b9bf"}], "other_license_expression": null, "other_license_expression_spdx": null, "other_license_detections": [], "extracted_license_statement": "- MIT\n", "notice_text": null, "source_packages": [], "file_references": [], "is_private": false, "is_virtual": false, "extra_data": {}, "dependencies": [{"purl": "pkg:npm/benchmark", "extracted_requirement": "github:bestiejs/benchmark.js", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/coveralls", "extracted_requirement": "^2.11.2", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/jshint", "extracted_requirement": "~2.7.0", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/lodash", "extracted_requirement": ">=2.4.1", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/mkdirp", "extracted_requirement": "~0.5.1", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/nodeunit", "extracted_requirement": ">0.0.0", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/nyc", "extracted_requirement": "^2.1.0", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/uglify-js", "extracted_requirement": "1.2.x", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}, {"purl": "pkg:npm/yargs", "extracted_requirement": "~3.9.1", "scope": "devDependencies", "is_runtime": false, "is_optional": true, "is_pinned": false, "is_direct": true, "resolved_package": {}, "extra_data": {}}], "repository_homepage_url": "https://www.npmjs.com/package/async", "repository_download_url": "https://registry.npmjs.org/async/-/async-1.2.1.tgz", "api_data_url": "https://registry.npmjs.org/async/1.2.1", "datasource_id": "npm_package_json", "purl": "pkg:npm/async@1.2.1"}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"urls": [{"url": "https://github.com/caolan/async.git", "start_line": 17, "end_line": 17}, {"url": "https://github.com/caolan/async/issues", "start_line": 20, "end_line": 20}, {"url": "https://github.com/caolan/async#readme", "start_line": 65, "end_line": 65}, {"url": "http://registry.npmjs.org/async/-/async-1.2.1.tgz", "start_line": 91, "end_line": 91}, {"url": "https://registry.npmjs.org/async/-/async-1.2.1.tgz", "start_line": 94, "end_line": 94}]}

tests/scancode/test_cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,3 +1041,28 @@ def test_scan_does_validate_input_and_fails_on_faulty_json_input(test_file, expe
10411041
def test_scan_does_validate_input_and_does_not_fail_on_valid_json_input():
10421042
test_file = test_env.get_test_loc('various-inputs/true-scan-json.json')
10431043
run_scan_click(['--from-json', test_file, '--json-pp', '-'], retry=False)
1044+
1045+
1046+
def test_use_cached_results():
1047+
results_cache_location = test_env.get_test_loc(u'results_cache/results/')
1048+
test_file = test_env.get_test_loc(u'results_cache/package.json')
1049+
result_file = test_env.get_temp_file('json')
1050+
env = {
1051+
'SCANCODE_RESULTS_CACHE': results_cache_location
1052+
}
1053+
args = [
1054+
'--info',
1055+
'--license',
1056+
'--copyright',
1057+
'--package',
1058+
'--email',
1059+
'--url',
1060+
'--strip-root',
1061+
'--use-cached-results',
1062+
test_file ,
1063+
'--json',
1064+
result_file
1065+
]
1066+
results = run_scan_plain(options=args, env=env)
1067+
expected = test_env.get_test_loc('results_cache/expected.json')
1068+
check_json_scan(expected, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

0 commit comments

Comments
 (0)