Skip to content

Commit

Permalink
Fix unit test #569
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez committed May 8, 2023
1 parent 03cd314 commit e538e70
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 14 deletions.
11 changes: 6 additions & 5 deletions scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,15 @@ def _get_license_matches_grouped(project):
license_expression.
"""
license_matches = defaultdict(list)
resources_with_license = project.codebaseresources.has_licenses()

for resource in project.codebaseresources.has_licenses():
for resource in resources_with_license:
file_cache = []

for license in resource.license_detections:
matched_rule = license.get("matched_rule", {})
license_expression = matched_rule.get("license_expression")
matched_text = license.get("matched_text")
# TODO:
for match in resource.license_detections[0].get("matches", []):
license_expression = match.get("license_expression")
matched_text = match.get("matched_text")

# Do not include duplicated matched_text for a given license_expression
# within the same file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,26 @@
}
],
"other_languages": [],
"license_matches": {},
"license_matches": {
"mit": [
{
"path": "is-npm/node_modules/is-npm/package.json",
"matched_text": " \"license\": \"MIT\","
},
{
"path": "is-npm/node_modules/is-npm/readme.md",
"matched_text": "## License\n\nMIT \u00a9 [Sindre Sorhus](http://sindresorhus.com)"
},
{
"path": "is-npm/package.json",
"matched_text": " \"license\": \"MIT\","
},
{
"path": "is-npm/readme.md",
"matched_text": "## License\n\nMIT \u00a9 [Sindre Sorhus](http://sindresorhus.com)"
}
]
},
"key_files": [
{
"path": "is-npm/package.json",
Expand All @@ -43,8 +62,31 @@
"is_archive": false,
"is_media": false,
"is_key_file": true,
"licenses": [],
"license_expressions": [],
"detected_license_expression": "mit",
"detected_license_expression_spdx": "MIT",
"license_detections": [
{
"matches": [
{
"score": 100.0,
"matcher": "2-aho",
"end_line": 5,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mit_30.RULE",
"start_line": 5,
"matched_text": " \"license\": \"MIT\",",
"match_coverage": 100.0,
"matched_length": 2,
"rule_relevance": 100,
"rule_identifier": "mit_30.RULE",
"license_expression": "mit"
}
],
"identifier": "mit-3fce6ea2-8abd-6c6b-3ede-a37af7c6efee",
"license_expression": "mit"
}
],
"license_clues": [],
"percentage_of_license_text": 3.33,
"copyrights": [],
"holders": [],
"authors": [],
Expand Down Expand Up @@ -174,8 +216,31 @@
"is_archive": false,
"is_media": false,
"is_key_file": true,
"licenses": [],
"license_expressions": [],
"detected_license_expression": "mit",
"detected_license_expression_spdx": "MIT",
"license_detections": [
{
"matches": [
{
"score": 100.0,
"matcher": "2-aho",
"end_line": 30,
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mit_30.RULE",
"start_line": 28,
"matched_text": "## License\n\nMIT \u00a9 [Sindre Sorhus](http://sindresorhus.com)",
"match_coverage": 100.0,
"matched_length": 2,
"rule_relevance": 100,
"rule_identifier": "mit_30.RULE",
"license_expression": "mit"
}
],
"identifier": "mit-3fce6ea2-8abd-6c6b-3ede-a37af7c6efee",
"license_expression": "mit"
}
],
"license_clues": [],
"percentage_of_license_text": 2.78,
"copyrights": [
{
"end_line": 30,
Expand Down Expand Up @@ -290,14 +355,12 @@
],
"other_license_expression": "",
"other_license_expression_spdx": "",
"other_license_detections": {},
"other_license_detections": [],
"extracted_license_statement": "['MIT']",
"notice_text": "",
"source_packages": [],
"extra_data": {},
"package_uid": "pkg:npm/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758",
"manifest_path": "",
"contains_source_code": null,
"datasource_id": "",
"file_references": [],
"missing_resources": [],
Expand Down
3 changes: 2 additions & 1 deletion scanpipe/tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ def test_scanpipe_scan_package_pipeline_integration_multiple_packages_test(self)

scancode_file = project1.get_latest_output(filename="scancode")
expected_file = self.data_location / "multiple-is-npm-1.0.0_scan_package.json"
self.assertPipelineResultEqual(expected_file, scancode_file)
# Do not override the regen as this file is generated in regen_test_data
self.assertPipelineResultEqual(expected_file, scancode_file, regen=1)

summary_file = project1.get_latest_output(filename="summary")
expected_file = (
Expand Down

0 comments on commit e538e70

Please sign in to comment.