|
7 | 7 | import json |
8 | 8 | from unittest.mock import MagicMock, patch |
9 | 9 |
|
| 10 | +import pytest |
10 | 11 | from cyclonedx.model import AttachedText, Encoding, Property |
11 | 12 | from cyclonedx.model.component import Component, ComponentType |
12 | 13 | from cyclonedx.model.component_evidence import ComponentEvidence |
@@ -364,54 +365,30 @@ def test_noassertion_has_concluded_acknowledgement(self): |
364 | 365 | ) |
365 | 366 | assert noassertion.acknowledgement == LicenseAcknowledgement.CONCLUDED |
366 | 367 |
|
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.""" |
405 | 379 | component = _make_bare_component() |
406 | 380 | scan = LicenseScanResult( |
407 | | - unclassified_files=["LICENSE"], |
| 381 | + unclassified_files=unclassified_files, |
408 | 382 | was_scanned=True, |
409 | 383 | threshold=0.80, |
410 | 384 | ) |
411 | 385 | SbomReporter._apply_licenses(component, scan) |
412 | 386 | val = _get_property_value(component, "dfetch:license:finding") |
413 | 387 | 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" |
415 | 392 |
|
416 | 393 | def test_tool_and_threshold_properties_present(self): |
417 | 394 | component = _make_bare_component() |
|
0 commit comments