Skip to content

Commit 7185ecd

Browse files
committed
Add extended license check
USe a JSON assertion on full scan results Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 5854716 commit 7185ecd

File tree

2 files changed

+145
-3
lines changed

2 files changed

+145
-3
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"license_detections": [
3+
{
4+
"identifier": "mit-6fc93e6a-0319-6943-7be7-2e20513a43e0",
5+
"license_expression": "mit",
6+
"license_expression_spdx": "MIT",
7+
"detection_count": 1,
8+
"detection_log": [],
9+
"reference_matches": [
10+
{
11+
"license_expression": "mit",
12+
"license_expression_spdx": "MIT",
13+
"from_file": "scan-ref/LICENSE",
14+
"start_line": 1,
15+
"end_line": 1,
16+
"matcher": "1-hash",
17+
"score": 100.0,
18+
"matched_length": 10,
19+
"match_coverage": 100.0,
20+
"rule_relevance": 100,
21+
"rule_identifier": "mit_66.RULE",
22+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mit_66.RULE",
23+
"matched_text": "that is licensed under [MIT](http://opensource.org/licenses/MIT).",
24+
"matched_text_diagnostics": "that is licensed under [MIT](http://opensource.org/licenses/MIT)."
25+
}
26+
]
27+
},
28+
{
29+
"identifier": "unknown_license_reference-8637bfcb-e3d3-84a6-a4f2-cf82132b6a78",
30+
"license_expression": "unknown-license-reference",
31+
"license_expression_spdx": "LicenseRef-scancode-unknown-license-reference",
32+
"detection_count": 1,
33+
"detection_log": [],
34+
"reference_matches": [
35+
{
36+
"license_expression": "unknown-license-reference",
37+
"license_expression_spdx": "LicenseRef-scancode-unknown-license-reference",
38+
"from_file": "scan-ref/license-notice.txt",
39+
"start_line": 34,
40+
"end_line": 34,
41+
"matcher": "2-aho",
42+
"score": 100.0,
43+
"matched_length": 6,
44+
"match_coverage": 100.0,
45+
"rule_relevance": 100,
46+
"rule_identifier": "unknown-license-reference_417.RULE",
47+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/unknown-license-reference_417.RULE",
48+
"matched_text": " \"license\": \"SEE LICENSE IN LICENSE.txt\",",
49+
"matched_text_diagnostics": "license\": \"SEE LICENSE IN LICENSE.txt\","
50+
}
51+
]
52+
}
53+
],
54+
"files": [
55+
{
56+
"path": "scan-ref",
57+
"type": "directory",
58+
"detected_license_expression": null,
59+
"detected_license_expression_spdx": null,
60+
"license_detections": [],
61+
"license_clues": [],
62+
"percentage_of_license_text": 0,
63+
"scan_errors": []
64+
},
65+
{
66+
"path": "scan-ref/LICENSE",
67+
"type": "file",
68+
"detected_license_expression": "mit",
69+
"detected_license_expression_spdx": "MIT",
70+
"license_detections": [
71+
{
72+
"license_expression": "mit",
73+
"license_expression_spdx": "MIT",
74+
"matches": [
75+
{
76+
"license_expression": "mit",
77+
"license_expression_spdx": "MIT",
78+
"from_file": "scan-ref/LICENSE",
79+
"start_line": 1,
80+
"end_line": 1,
81+
"matcher": "1-hash",
82+
"score": 100.0,
83+
"matched_length": 10,
84+
"match_coverage": 100.0,
85+
"rule_relevance": 100,
86+
"rule_identifier": "mit_66.RULE",
87+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mit_66.RULE",
88+
"matched_text": "that is licensed under [MIT](http://opensource.org/licenses/MIT).",
89+
"matched_text_diagnostics": "that is licensed under [MIT](http://opensource.org/licenses/MIT)."
90+
}
91+
],
92+
"detection_log": [],
93+
"identifier": "mit-6fc93e6a-0319-6943-7be7-2e20513a43e0"
94+
}
95+
],
96+
"license_clues": [],
97+
"percentage_of_license_text": 100.0,
98+
"scan_errors": []
99+
},
100+
{
101+
"path": "scan-ref/license-notice.txt",
102+
"type": "file",
103+
"detected_license_expression": "unknown-license-reference",
104+
"detected_license_expression_spdx": "LicenseRef-scancode-unknown-license-reference",
105+
"license_detections": [
106+
{
107+
"license_expression": "unknown-license-reference",
108+
"license_expression_spdx": "LicenseRef-scancode-unknown-license-reference",
109+
"matches": [
110+
{
111+
"license_expression": "unknown-license-reference",
112+
"license_expression_spdx": "LicenseRef-scancode-unknown-license-reference",
113+
"from_file": "scan-ref/license-notice.txt",
114+
"start_line": 34,
115+
"end_line": 34,
116+
"matcher": "2-aho",
117+
"score": 100.0,
118+
"matched_length": 6,
119+
"match_coverage": 100.0,
120+
"rule_relevance": 100,
121+
"rule_identifier": "unknown-license-reference_417.RULE",
122+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/unknown-license-reference_417.RULE",
123+
"matched_text": " \"license\": \"SEE LICENSE IN LICENSE.txt\",",
124+
"matched_text_diagnostics": "license\": \"SEE LICENSE IN LICENSE.txt\","
125+
}
126+
],
127+
"detection_log": [],
128+
"identifier": "unknown_license_reference-8637bfcb-e3d3-84a6-a4f2-cf82132b6a78"
129+
}
130+
],
131+
"license_clues": [],
132+
"percentage_of_license_text": 0.25,
133+
"scan_errors": []
134+
}
135+
]
136+
}

tests/licensedcode/test_plugin_license_detection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,25 @@ def test_find_referenced_resource_does_not_find_based_file_name_suffix():
297297
def test_match_reference_license():
298298
# Setup: Create a new scan to use for a virtual codebase
299299
test_dir = test_env.get_test_loc('plugin_license/license_reference/scan/scan-ref', copy=True)
300-
scan_loc = test_env.get_temp_file('json')
300+
result_file = test_env.get_temp_file('json')
301301
args = [
302302
'--license',
303303
'--license-text',
304304
'--license-text-diagnostics',
305305
'--license-diagnostics',
306-
'--json', scan_loc,
306+
'--json', result_file,
307307
test_dir,
308308
]
309309
run_scan_click(args)
310310

311311
# test proper
312312
from commoncode.resource import VirtualCodebase
313-
codebase = VirtualCodebase(scan_loc)
313+
codebase = VirtualCodebase(result_file)
314314
resource = codebase.get_resource(path='scan-ref/license-notice.txt')
315315
assert len(resource.license_detections[0]["matches"]) == 1
316+
317+
expected_loc = test_env.get_test_loc(
318+
'plugin_license/license_reference/scan/scan-ref.expected.json',
319+
must_exist=False,
320+
)
321+
check_json_scan(expected_loc, result_file, regen=REGEN_TEST_FIXTURES)

0 commit comments

Comments
 (0)