Skip to content

Commit a9ad3f6

Browse files
[issue-540] change validation: allow no DESCRIBES relationship if there is a single package only
Signed-off-by: Armin Tänzer <armin.taenzer@tngtech.com>
1 parent 0138e9c commit a9ad3f6

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/spdx/validation/document_validator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ def validate_full_spdx_document(document: Document, spdx_version: str = None) ->
7070
document.relationships, RelationshipType.DESCRIBED_BY, document_id
7171
)
7272

73-
if not document_describes_relationships + described_by_document_relationships:
73+
only_a_single_package = len(document.packages) == 1 and not document.files and not document.snippets
74+
if not only_a_single_package and not document_describes_relationships + described_by_document_relationships:
7475
validation_messages.append(
7576
ValidationMessage(
7677
f'there must be at least one relationship "{document_id} DESCRIBES ..." or "... DESCRIBED_BY '
77-
f'{document_id}"',
78+
f'{document_id}" when there is not only a single package present',
7879
ValidationContext(spdx_id=document_id, element_type=SpdxElementType.DOCUMENT),
7980
)
8081
)

tests/spdx/validation/test_document_validator.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,20 @@ def test_document_describes_at_least_one_element(relationships):
9494
assert validation_messages == []
9595

9696

97-
def test_document_does_not_describe_an_element():
97+
def test_document_does_not_describe_an_element_with_only_one_package():
98+
document = document_fixture(
99+
packages=[package_fixture()],
100+
files=[],
101+
snippets=[],
102+
relationships=[],
103+
annotations=[],
104+
)
105+
validation_messages: List[ValidationMessage] = validate_full_spdx_document(document)
106+
107+
assert validation_messages == []
108+
109+
110+
def test_document_does_not_describe_an_element_with_multiple_elements():
98111
document = document_fixture(
99112
relationships=[Relationship("SPDXRef-Package", RelationshipType.DESCRIBES, "SPDXRef-File")]
100113
)
@@ -103,7 +116,7 @@ def test_document_does_not_describe_an_element():
103116
assert validation_messages == [
104117
ValidationMessage(
105118
f'there must be at least one relationship "{DOCUMENT_SPDX_ID} DESCRIBES ..." or "... DESCRIBED_BY '
106-
f'{DOCUMENT_SPDX_ID}"',
119+
f'{DOCUMENT_SPDX_ID}" when there is not only a single package present',
107120
ValidationContext(spdx_id=DOCUMENT_SPDX_ID, element_type=SpdxElementType.DOCUMENT),
108121
)
109122
]

0 commit comments

Comments
 (0)