Skip to content

Commit 4aab0aa

Browse files
committed
Update test cases upto expectations
Signed-off-by: akugarg <[email protected]>
1 parent 5e4928d commit 4aab0aa

File tree

13 files changed

+3152
-40
lines changed

13 files changed

+3152
-40
lines changed

src/licensedcode/plugin_license.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from commoncode import fileutils
1616
from commoncode.cliutils import PluggableCommandLineOption
17+
from licensedcode.models import BasicRule, License
1718
from plugincode.scan import ScanPlugin
1819
from plugincode.scan import scan_impl
1920
from commoncode.cliutils import MISC_GROUP
@@ -118,7 +119,11 @@ def get_scanner(
118119
license_text_diagnostics=license_text_diagnostics,
119120
license_url_template=license_url_template
120121
)
122+
121123
def process_codebase(self, codebase, **kwargs):
124+
125+
if codebase.has_single_resource:
126+
return
122127

123128
for resource in codebase.walk(topdown=False):
124129
match_reference_license(resource,codebase)
@@ -128,37 +133,37 @@ def match_reference_license(resource, codebase):
128133
"""
129134
Find instances for any licenses in referenced filenames
130135
"""
136+
137+
if not resource.is_file:
138+
return
139+
131140
licenses = resource.licenses
132141
license_expressions = resource.license_expressions
133142
if not licenses:
134143
return
135144

136145
location = resource.location
137-
138146
from licensedcode import cache
139147
from scancode.api import get_licenses
140148
idx = cache.get_index()
141149
matches = idx.match(
142150
location=location, min_score=0)
143-
144-
modified = False
145151

146152
for match in matches:
147153
ref_files=match.rule.referenced_filenames
148154
if len(ref_files) != 0:
149155
for i in range(len(ref_files)):
150156
if not ref_files[i].startswith('usr/share/common-licenses'):
151-
new_loc=find_reference_file(location,ref_files[i])
152-
if new_loc != None:
153-
new_lic=get_licenses(new_loc, min_score=0)
154-
licenses.extend(new_lic['licenses'])
155-
license_expressions.extend(new_lic['license_expressions'])
156-
modified = True
157-
158-
if modified:
159-
codebase.save_resource(resource)
157+
new_loc=find_reference_file(location,ref_files[i])
158+
if new_loc:
159+
new_lic=get_licenses(new_loc, min_score=0)
160+
licenses.extend(new_lic['licenses'])
161+
license_expressions.extend(new_lic['license_expressions'])
162+
163+
codebase.save_resource(resource)
160164
return resource
161165

166+
162167
def find_reference_file(location,referenced_filename):
163168
"""
164169
Searches for the referenced filename in the same directory and
@@ -170,5 +175,4 @@ def find_reference_file(location,referenced_filename):
170175
if file_name in files:
171176
path_file = os.path.join(root,file_name)
172177
return path_file
173-
174-
return None
178+

tests/licensedcode/data/plugin_license/license_reference/scan-ref.expected.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"files": [
2222
{
23-
"path": "LICENCE",
23+
"path": "LICENSE",
2424
"type": "file",
2525
"licenses": [
2626
{
@@ -72,7 +72,7 @@
7272
"licenses": [
7373
{
7474
"key": "unknown-license-reference",
75-
"score": 90.0,
75+
"score": 27.0,
7676
"name": "Unknown License file reference",
7777
"short_name": "Unknown License reference",
7878
"category": "Unstated License",
@@ -85,26 +85,26 @@
8585
"scancode_data_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/unknown-license-reference.yml",
8686
"spdx_license_key": "LicenseRef-scancode-unknown-license-reference",
8787
"spdx_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/unknown-license-reference.LICENSE",
88-
"start_line": 1,
89-
"end_line": 1,
88+
"start_line": 34,
89+
"end_line": 34,
9090
"matched_rule": {
91-
"identifier": "unknown-license-reference_39.RULE",
91+
"identifier": "unknown-license-reference_25.RULE",
9292
"license_expression": "unknown-license-reference",
9393
"licenses": [
9494
"unknown-license-reference"
9595
],
9696
"is_license_text": false,
9797
"is_license_notice": false,
98-
"is_license_reference": true,
99-
"is_license_tag": false,
98+
"is_license_reference": false,
99+
"is_license_tag": true,
100100
"is_license_intro": false,
101-
"matcher": "1-hash",
102-
"rule_length": 10,
103-
"matched_length": 10,
101+
"matcher": "2-aho",
102+
"rule_length": 5,
103+
"matched_length": 5,
104104
"match_coverage": 100.0,
105-
"rule_relevance": 90
105+
"rule_relevance": 27
106106
},
107-
"matched_text": "For licensing information, see the file 'LICENCE' in this directory."
107+
"matched_text": "license\": \"SEE LICENSE IN LICENSE."
108108
},
109109
{
110110
"key": "mit",
@@ -146,7 +146,7 @@
146146
"unknown-license-reference",
147147
"mit"
148148
],
149-
"percentage_of_license_text": 100.0,
149+
"percentage_of_license_text": 0.2,
150150
"scan_errors": []
151151
}
152152
]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"headers": [
3+
{
4+
"tool_name": "scancode-toolkit",
5+
"options": {
6+
"input": "<path>",
7+
"--json": "<file>",
8+
"--license": true,
9+
"--license-text": true,
10+
"--license-text-diagnostics": true,
11+
"--strip-root": true
12+
},
13+
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
14+
"message": null,
15+
"errors": [],
16+
"extra_data": {
17+
"files_count": 1
18+
}
19+
}
20+
],
21+
"files": [
22+
{
23+
"path": "license-notice.txt",
24+
"type": "file",
25+
"licenses": [
26+
{
27+
"key": "unknown-license-reference",
28+
"score": 27.0,
29+
"name": "Unknown License file reference",
30+
"short_name": "Unknown License reference",
31+
"category": "Unstated License",
32+
"is_exception": false,
33+
"owner": "Unspecified",
34+
"homepage_url": null,
35+
"text_url": "",
36+
"reference_url": "https://scancode-licensedb.aboutcode.org/unknown-license-reference",
37+
"scancode_text_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/unknown-license-reference.LICENSE",
38+
"scancode_data_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/unknown-license-reference.yml",
39+
"spdx_license_key": "LicenseRef-scancode-unknown-license-reference",
40+
"spdx_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/unknown-license-reference.LICENSE",
41+
"start_line": 34,
42+
"end_line": 34,
43+
"matched_rule": {
44+
"identifier": "unknown-license-reference_25.RULE",
45+
"license_expression": "unknown-license-reference",
46+
"licenses": [
47+
"unknown-license-reference"
48+
],
49+
"is_license_text": false,
50+
"is_license_notice": false,
51+
"is_license_reference": false,
52+
"is_license_tag": true,
53+
"is_license_intro": false,
54+
"matcher": "2-aho",
55+
"rule_length": 5,
56+
"matched_length": 5,
57+
"match_coverage": 100.0,
58+
"rule_relevance": 27
59+
},
60+
"matched_text": "license\": \"SEE LICENSE IN LICENSE."
61+
}
62+
],
63+
"license_expressions": [
64+
"unknown-license-reference"
65+
],
66+
"percentage_of_license_text": 0.2,
67+
"scan_errors": []
68+
}
69+
]
70+
}

tests/licensedcode/data/plugin_license/license_reference/scan/license-notice.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/licensedcode/data/plugin_license/license_reference/scan/LICENCE renamed to tests/licensedcode/data/plugin_license/license_reference/scan/scan-ref/LICENSE

File renamed without changes.

0 commit comments

Comments
 (0)