Skip to content

Commit 00d15db

Browse files
committed
feat!: don't "fix" licenses if not needed #995
1 parent 1879caa commit 00d15db

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/test_utils.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pytest
2+
from cyclonedx.model.component import Component
3+
from cyclonedx.model.license import DisjunctiveLicense, LicenseExpression
4+
from cyclonedx_py._internal.utils.cdx import licenses_fixup
5+
6+
def test_single_expression_no_change():
7+
comp = Component(
8+
name="test-component",
9+
licenses=(LicenseExpression("MIT"),)
10+
)
11+
licenses_fixup(comp)
12+
assert comp.licenses[0].value == "MIT"
13+
assert comp.evidence is None
14+
15+
def test_multiple_named_no_change():
16+
comp = Component(
17+
name="test-component",
18+
licenses=(DisjunctiveLicense(name="MIT"),
19+
DisjunctiveLicense(name="Apache-2.0"))
20+
)
21+
licenses_fixup(comp)
22+
names = {l.name for l in comp.licenses}
23+
assert names == {"MIT", "Apache-2.0"}
24+
assert comp.evidence is None
25+
26+
def test_expression_plus_named_moves_named_to_evidence():
27+
comp = Component(
28+
name="test-component",
29+
licenses=(LicenseExpression("MIT"),
30+
DisjunctiveLicense(name="Apache-2.0"))
31+
)
32+
licenses_fixup(comp)
33+
# Check expression stays
34+
assert comp.licenses[0].value == "MIT"
35+
# Check named moved to evidence
36+
assert comp.evidence is not None
37+
moved = {l.name for l in comp.evidence.licenses}
38+
assert moved == {"Apache-2.0"}
39+
40+
def test_empty_licenses_no_change():
41+
comp = Component(
42+
name="test-component",
43+
licenses=()
44+
)
45+
licenses_fixup(comp)
46+
assert tuple(comp.licenses) == ()
47+
assert comp.evidence is None

0 commit comments

Comments
 (0)