Repository navigation
fix(SPDX): improve cross-platform output and data handling #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) 2026 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import pytest | ||
| from spdx_tools.spdx.parser.parse_anything import parse_file | ||
| from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document | ||
|
|
||
| from fosslight_source import cli as source_cli | ||
| from fosslight_source._license_matched import MatchedLicense | ||
| from fosslight_source._scan_item import SourceItem | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("matched_text, expected_text", [ | ||
| (' license="BSD",', ' license="BSD",'), | ||
| ("", "BSD"), | ||
| ]) | ||
| def test_spdx_uses_scancode_matched_text_without_reference_sheet( | ||
| tmp_path, monkeypatch, matched_text, expected_text | ||
| ): | ||
| project = tmp_path / "project" | ||
| project.mkdir() | ||
| (project / "setup.py").write_text('license="BSD"\n', encoding="utf-8") | ||
| output = tmp_path / "reports" | ||
| source_item = SourceItem("setup.py") | ||
| source_item.checksum = "a" * 40 | ||
| source_item.licenses = ["BSD-3-Clause"] | ||
| matched_license = MatchedLicense("BSD-3-Clause", "", matched_text, "setup.py") | ||
| license_list = {matched_license.license + matched_license.matched_text: matched_license} | ||
| received_need_matched_text = [] | ||
|
|
||
| def run_scancode(*args, **kwargs): | ||
| received_need_matched_text.append(args[5]) | ||
| return True, "True", [source_item], license_list | ||
|
|
||
| monkeypatch.chdir(tmp_path) | ||
| monkeypatch.setattr(source_cli, "run_scan", run_scancode) | ||
|
|
||
| success, message, scan_item, _licenses, _scanoss_result = source_cli.run_scanners( | ||
| str(project), str(output), selected_scanner="scancode", formats=["spdx-json"], | ||
| print_matched_text=False, correct_mode=False, all_exclude_mode=([], [], set(), 1), | ||
| hide_progress=True, | ||
| ) | ||
|
|
||
| assert success, message | ||
| assert received_need_matched_text == [True] | ||
| assert "scancode_reference" not in scan_item.external_sheets | ||
| assert scan_item.file_items[source_cli.PKG_NAME][0].oss_items[0].license == ["BSD"] | ||
| document = parse_file(str(next(output.glob("*.json")))) | ||
| assert validate_full_spdx_document(document) == [] | ||
| assert document.extracted_licensing_info[0].license_name == "BSD" | ||
| assert document.extracted_licensing_info[0].extracted_text == expected_text | ||
| assert {str(value) for value in document.files[0].license_info_in_file} == {"LicenseRef-BSD"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.