Skip to content

Commit 9d42d1e

Browse files
Fix tests and add new tests
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent c86490d commit 9d42d1e

31 files changed

+17344
-1963
lines changed

src/packagedcode/build.py

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

1515
from commoncode import fileutils
1616

17+
from licensedcode.cache import build_spdx_license_expression
18+
from licensedcode.cache import get_cache
1719
from licensedcode.tokenize import query_tokenizer
1820
from licensedcode.detection import detect_licenses
1921
from licensedcode.detection import get_unknown_license_detection
@@ -122,6 +124,11 @@ def assemble(cls, package_data, resource, codebase, package_adder):
122124
resource=resource,
123125
codebase=codebase,
124126
)
127+
if package.declared_license_expression:
128+
package.declared_license_expression_spdx = str(build_spdx_license_expression(
129+
license_expression=package.declared_license_expression,
130+
licensing=get_cache().licensing,
131+
))
125132

126133
cls.assign_package_to_resources(
127134
package=package,
@@ -132,6 +139,7 @@ def assemble(cls, package_data, resource, codebase, package_adder):
132139

133140
yield package
134141

142+
135143
# we yield this as we do not want this further processed
136144
yield resource
137145

tests/formattedcode/test_output_cyclonedx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,22 @@ def test_cyclonedx_plugin_does_not_fail_without_packages():
228228
def test_cyclonedx_plugin_json():
229229
test_dir = test_env.get_test_loc('cyclonedx/simple')
230230
result_file = test_env.get_temp_file('cyclonedx.json')
231-
run_scan_click(['-p', test_dir, '--cyclonedx', result_file])
231+
run_scan_click(['--package', test_dir, '--cyclonedx', result_file])
232232
expected_file = test_env.get_test_loc('cyclonedx/simple-expected.json')
233233
check_cyclone_output(expected_file, result_file, regen=REGEN_TEST_FIXTURES)
234234

235235

236236
def test_cyclonedx_plugin_json_simple_package_icu():
237237
test_dir = test_env.get_test_loc('cyclonedx/simple-icu')
238238
result_file = test_env.get_temp_file('cyclonedx.json')
239-
run_scan_click(['-p', test_dir, '--cyclonedx', result_file])
239+
run_scan_click(['--package', '--license', test_dir, '--cyclonedx', result_file])
240240
expected_file = test_env.get_test_loc('cyclonedx/simple-icu-expected.json')
241241
check_cyclone_output(expected_file, result_file, regen=REGEN_TEST_FIXTURES)
242242

243243

244244
def test_cyclonedx_plugin_xml_components_and_dependencies_are_serialized_correctly():
245245
test_dir = test_env.get_test_loc('cyclonedx/simple')
246246
result_file = test_env.get_temp_file('cyclonedx.xml')
247-
run_scan_click(['-p', test_dir, '--cyclonedx-xml', result_file])
247+
run_scan_click(['--package', test_dir, '--cyclonedx-xml', result_file])
248248
expected_file = test_env.get_test_loc('cyclonedx/expected.xml')
249249
check_cyclone_xml_output(expected_file, result_file, regen=REGEN_TEST_FIXTURES)

tests/packagedcode/data/build/buck/end2end-expected.json

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -247,29 +247,9 @@
247247
"vcs_url": null,
248248
"copyright": null,
249249
"holder": null,
250-
"declared_license_expression": "apache-2.0",
251-
"declared_license_expression_spdx": "Apache-2.0",
252-
"license_detections": [
253-
{
254-
"license_expression": "apache-2.0",
255-
"matches": [
256-
{
257-
"score": 100.0,
258-
"start_line": 1,
259-
"end_line": 1,
260-
"matched_length": 3,
261-
"match_coverage": 100.0,
262-
"matcher": "1-hash",
263-
"license_expression": "apache-2.0",
264-
"rule_identifier": "spdx_license_id_apache-2.0_for_apache-2.0.RULE",
265-
"rule_relevance": 100,
266-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/spdx_license_id_apache-2.0_for_apache-2.0.RULE",
267-
"matched_text": "apache-2.0"
268-
}
269-
],
270-
"identifier": "apache_2_0-d66ab77d-a5cc-7104-e702-dc7df61fe9e8"
271-
}
272-
],
250+
"declared_license_expression": null,
251+
"declared_license_expression_spdx": null,
252+
"license_detections": [],
273253
"other_license_expression": null,
274254
"other_license_expression_spdx": null,
275255
"other_license_detections": [],

tests/packagedcode/data/cocoapods/assemble/many-podspecs-expected.json

Lines changed: 6 additions & 46 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)