Skip to content

Commit

Permalink
Fix tests and add new tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
  • Loading branch information
AyanSinhaMahapatra committed Jun 7, 2023
1 parent c86490d commit 9d42d1e
Show file tree
Hide file tree
Showing 31 changed files with 17,344 additions and 1,963 deletions.
8 changes: 8 additions & 0 deletions src/packagedcode/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from commoncode import fileutils

from licensedcode.cache import build_spdx_license_expression
from licensedcode.cache import get_cache
from licensedcode.tokenize import query_tokenizer
from licensedcode.detection import detect_licenses
from licensedcode.detection import get_unknown_license_detection
Expand Down Expand Up @@ -122,6 +124,11 @@ def assemble(cls, package_data, resource, codebase, package_adder):
resource=resource,
codebase=codebase,
)
if package.declared_license_expression:
package.declared_license_expression_spdx = str(build_spdx_license_expression(
license_expression=package.declared_license_expression,
licensing=get_cache().licensing,
))

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

yield package


# we yield this as we do not want this further processed
yield resource

Expand Down
6 changes: 3 additions & 3 deletions tests/formattedcode/test_output_cyclonedx.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,22 @@ def test_cyclonedx_plugin_does_not_fail_without_packages():
def test_cyclonedx_plugin_json():
test_dir = test_env.get_test_loc('cyclonedx/simple')
result_file = test_env.get_temp_file('cyclonedx.json')
run_scan_click(['-p', test_dir, '--cyclonedx', result_file])
run_scan_click(['--package', test_dir, '--cyclonedx', result_file])
expected_file = test_env.get_test_loc('cyclonedx/simple-expected.json')
check_cyclone_output(expected_file, result_file, regen=REGEN_TEST_FIXTURES)


def test_cyclonedx_plugin_json_simple_package_icu():
test_dir = test_env.get_test_loc('cyclonedx/simple-icu')
result_file = test_env.get_temp_file('cyclonedx.json')
run_scan_click(['-p', test_dir, '--cyclonedx', result_file])
run_scan_click(['--package', '--license', test_dir, '--cyclonedx', result_file])
expected_file = test_env.get_test_loc('cyclonedx/simple-icu-expected.json')
check_cyclone_output(expected_file, result_file, regen=REGEN_TEST_FIXTURES)


def test_cyclonedx_plugin_xml_components_and_dependencies_are_serialized_correctly():
test_dir = test_env.get_test_loc('cyclonedx/simple')
result_file = test_env.get_temp_file('cyclonedx.xml')
run_scan_click(['-p', test_dir, '--cyclonedx-xml', result_file])
run_scan_click(['--package', test_dir, '--cyclonedx-xml', result_file])
expected_file = test_env.get_test_loc('cyclonedx/expected.xml')
check_cyclone_xml_output(expected_file, result_file, regen=REGEN_TEST_FIXTURES)
26 changes: 3 additions & 23 deletions tests/packagedcode/data/build/buck/end2end-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,29 +247,9 @@
"vcs_url": null,
"copyright": null,
"holder": null,
"declared_license_expression": "apache-2.0",
"declared_license_expression_spdx": "Apache-2.0",
"license_detections": [
{
"license_expression": "apache-2.0",
"matches": [
{
"score": 100.0,
"start_line": 1,
"end_line": 1,
"matched_length": 3,
"match_coverage": 100.0,
"matcher": "1-hash",
"license_expression": "apache-2.0",
"rule_identifier": "spdx_license_id_apache-2.0_for_apache-2.0.RULE",
"rule_relevance": 100,
"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",
"matched_text": "apache-2.0"
}
],
"identifier": "apache_2_0-d66ab77d-a5cc-7104-e702-dc7df61fe9e8"
}
],
"declared_license_expression": null,
"declared_license_expression_spdx": null,
"license_detections": [],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 9d42d1e

Please # to comment.