Skip to content
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

[issue-774] fix tag-value output when related_spdx_element_id is "NONE" or "NOASSERTION" #778

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def scan_relationships(
files_by_spdx_id = {file.spdx_id: file for file in files}
packages_spdx_ids = [package.spdx_id for package in packages]
for relationship in relationships:
if (
if relationship.related_spdx_element_id in [SpdxNoAssertion(), SpdxNone()]:
relationships_to_write.append(relationship)
elif (
relationship.relationship_type == RelationshipType.CONTAINS
and relationship.spdx_element_id in packages_spdx_ids
and relationship.related_spdx_element_id in files_by_spdx_id.keys()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from spdx_tools.spdx.model import ActorType, RelationshipType, SpdxNoAssertion
from spdx_tools.spdx.model import ActorType, RelationshipType, SpdxNoAssertion, SpdxNone
from spdx_tools.spdx.writer.tagvalue.tagvalue_writer_helper_functions import scan_relationships, write_actor
from tests.spdx.fixtures import actor_fixture, file_fixture, package_fixture, relationship_fixture

Expand All @@ -16,6 +16,18 @@ def test_scan_relationships():
packages = [package_fixture(spdx_id=first_package_spdx_id), package_fixture(spdx_id=second_package_spdx_id)]
file_spdx_id = "SPDXRef-File"
files = [file_fixture(spdx_id=file_spdx_id)]
no_assertion_relationship = relationship_fixture(
spdx_element_id=second_package_spdx_id,
relationship_type=RelationshipType.CONTAINS,
related_spdx_element_id=SpdxNoAssertion(),
comment=None,
)
none_relationship = relationship_fixture(
spdx_element_id=second_package_spdx_id,
relationship_type=RelationshipType.CONTAINS,
related_spdx_element_id=SpdxNone(),
comment=None,
)
relationships = [
relationship_fixture(
spdx_element_id=first_package_spdx_id,
Expand All @@ -29,11 +41,13 @@ def test_scan_relationships():
related_spdx_element_id=file_spdx_id,
comment=None,
),
no_assertion_relationship,
none_relationship,
]

relationships_to_write, contained_files_by_package_id = scan_relationships(relationships, packages, files)

assert relationships_to_write == []
assert relationships_to_write == [no_assertion_relationship, none_relationship]
assert contained_files_by_package_id == {first_package_spdx_id: files, second_package_spdx_id: files}


Expand Down
Loading