Skip to content

Commit 8cea673

Browse files
committed
Fixup tests
1 parent 3d48d84 commit 8cea673

1 file changed

Lines changed: 17 additions & 40 deletions

File tree

tests/test_sbom_reporter.py

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
from unittest.mock import MagicMock, patch
99

10+
import pytest
1011
from cyclonedx.model import AttachedText, Encoding, Property
1112
from cyclonedx.model.component import Component, ComponentType
1213
from cyclonedx.model.component_evidence import ComponentEvidence
@@ -364,54 +365,30 @@ def test_noassertion_has_concluded_acknowledgement(self):
364365
)
365366
assert noassertion.acknowledgement == LicenseAcknowledgement.CONCLUDED
366367

367-
def test_noassertion_finding_property_mentions_filename(self):
368-
"""The dfetch:license:finding property (not the license object) carries the filename."""
369-
component = _make_bare_component()
370-
scan = LicenseScanResult(
371-
unclassified_files=["LICENSE"],
372-
was_scanned=True,
373-
threshold=0.80,
374-
)
375-
SbomReporter._apply_licenses(component, scan)
376-
val = _get_property_value(component, "dfetch:license:finding")
377-
assert val is not None and "LICENSE" in val
378-
379-
def test_multiple_unclassified_files_sorted_in_finding_property(self):
380-
"""Multiple unclassified files appear sorted in the dfetch:license:finding property."""
381-
component = _make_bare_component()
382-
scan = LicenseScanResult(
383-
unclassified_files=["COPYING", "LICENSE"],
384-
was_scanned=True,
385-
threshold=0.80,
386-
)
387-
SbomReporter._apply_licenses(component, scan)
388-
val = _get_property_value(component, "dfetch:license:finding")
389-
assert val is not None
390-
assert "COPYING" in val
391-
assert "LICENSE" in val
392-
393-
def test_noassertion_reason_property_is_unclassifiable(self):
394-
component = _make_bare_component()
395-
scan = LicenseScanResult(
396-
unclassified_files=["LICENSE"],
397-
was_scanned=True,
398-
threshold=0.80,
399-
)
400-
SbomReporter._apply_licenses(component, scan)
401-
val = _get_property_value(component, "dfetch:license:noassertion:reason")
402-
assert val == "UNCLASSIFIABLE_LICENSE_TEXT"
403-
404-
def test_finding_property_is_set(self):
368+
@pytest.mark.parametrize(
369+
"unclassified_files, expected_filenames",
370+
[
371+
(["LICENSE"], ["LICENSE"]),
372+
(["COPYING", "LICENSE"], ["COPYING", "LICENSE"]),
373+
],
374+
)
375+
def test_finding_and_reason_properties(
376+
self, unclassified_files, expected_filenames
377+
):
378+
"""dfetch:license:finding lists all unclassified files; reason is UNCLASSIFIABLE_LICENSE_TEXT."""
405379
component = _make_bare_component()
406380
scan = LicenseScanResult(
407-
unclassified_files=["LICENSE"],
381+
unclassified_files=unclassified_files,
408382
was_scanned=True,
409383
threshold=0.80,
410384
)
411385
SbomReporter._apply_licenses(component, scan)
412386
val = _get_property_value(component, "dfetch:license:finding")
413387
assert val is not None
414-
assert "LICENSE" in val
388+
for filename in expected_filenames:
389+
assert filename in val
390+
reason = _get_property_value(component, "dfetch:license:noassertion:reason")
391+
assert reason == "UNCLASSIFIABLE_LICENSE_TEXT"
415392

416393
def test_tool_and_threshold_properties_present(self):
417394
component = _make_bare_component()

0 commit comments

Comments
 (0)