diff --git a/cyclonedx/factory/license.py b/cyclonedx/factory/license.py index f96cb697..40d4484d 100644 --- a/cyclonedx/factory/license.py +++ b/cyclonedx/factory/license.py @@ -19,7 +19,7 @@ from ..exception.factory import InvalidLicenseExpressionException, InvalidSpdxLicenseException from ..model.license import DisjunctiveLicense, LicenseExpression -from ..spdx import fixup_id as spdx_fixup, is_compound_expression as is_spdx_compound_expression +from ..spdx import fixup_id as spdx_fixup, is_expression as is_spdx_expression if TYPE_CHECKING: # pragma: no cover from ..model import AttachedText, XsUri @@ -57,11 +57,11 @@ def make_with_expression(self, expression: str, *, ) -> LicenseExpression: """Make a :class:`cyclonedx.model.license.LicenseExpression` with a compound expression. - Utilizes :func:`cyclonedx.spdx.is_compound_expression`. + Utilizes :func:`cyclonedx.spdx.is_expression`. :raises InvalidLicenseExpressionException: if param `value` is not known/supported license expression """ - if is_spdx_compound_expression(expression): + if is_spdx_expression(expression): return LicenseExpression(expression, acknowledgement=acknowledgement) raise InvalidLicenseExpressionException(expression) diff --git a/cyclonedx/spdx.py b/cyclonedx/spdx.py index 8f7e30b1..9781af54 100644 --- a/cyclonedx/spdx.py +++ b/cyclonedx/spdx.py @@ -18,7 +18,7 @@ __all__ = [ 'is_supported_id', 'fixup_id', - 'is_compound_expression' + 'is_expression' ] from json import load as json_load @@ -47,26 +47,26 @@ def is_supported_id(value: str) -> bool: - """Validate a SPDX-ID according to current spec.""" + """Validate SPDX-ID according to current spec.""" return value in __IDS def fixup_id(value: str) -> Optional[str]: - """Fixup a SPDX-ID. + """Fixup SPDX-ID. :returns: repaired value string, or `None` if fixup was unable to help. """ return __IDS_LOWER_MAP.get(value.lower()) -def is_compound_expression(value: str) -> bool: - """Validate compound expression. +def is_expression(value: str) -> bool: + """Validate SPDX license expression. .. note:: Utilizes `license-expression library`_ to validate SPDX compound expression according to `SPDX license expression spec`_. - .. _SPDX license expression spec: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/ + .. _SPDX license expression spec: https://spdx.github.io/spdx-spec/v3.0.1/annexes/spdx-license-expressions/ .. _license-expression library: https://github.com/nexB/license-expression """ try: diff --git a/tests/test_factory_license.py b/tests/test_factory_license.py index f7fd7b99..051a88b3 100644 --- a/tests/test_factory_license.py +++ b/tests/test_factory_license.py @@ -33,7 +33,7 @@ def test_make_from_string_with_id(self) -> None: expected = DisjunctiveLicense(id='bar', text=text, url=url, acknowledgement=acknowledgement) with unittest.mock.patch('cyclonedx.factory.license.spdx_fixup', return_value='bar'), \ - unittest.mock.patch('cyclonedx.factory.license.is_spdx_compound_expression', return_value=True): + unittest.mock.patch('cyclonedx.factory.license.is_spdx_expression', return_value=True): actual = LicenseFactory().make_from_string('foo', license_text=text, license_url=url, @@ -48,7 +48,7 @@ def test_make_from_string_with_name(self) -> None: expected = DisjunctiveLicense(name='foo', text=text, url=url, acknowledgement=acknowledgement) with unittest.mock.patch('cyclonedx.factory.license.spdx_fixup', return_value=None), \ - unittest.mock.patch('cyclonedx.factory.license.is_spdx_compound_expression', return_value=False): + unittest.mock.patch('cyclonedx.factory.license.is_spdx_expression', return_value=False): actual = LicenseFactory().make_from_string('foo', license_text=text, license_url=url, @@ -61,7 +61,7 @@ def test_make_from_string_with_expression(self) -> None: expected = LicenseExpression('foo', acknowledgement=acknowledgement) with unittest.mock.patch('cyclonedx.factory.license.spdx_fixup', return_value=None), \ - unittest.mock.patch('cyclonedx.factory.license.is_spdx_compound_expression', return_value=True): + unittest.mock.patch('cyclonedx.factory.license.is_spdx_expression', return_value=True): actual = LicenseFactory().make_from_string('foo', license_acknowledgement=acknowledgement) @@ -94,11 +94,11 @@ def test_make_with_name(self) -> None: def test_make_with_expression(self) -> None: acknowledgement = unittest.mock.NonCallableMock(spec=LicenseAcknowledgement) expected = LicenseExpression('foo', acknowledgement=acknowledgement) - with unittest.mock.patch('cyclonedx.factory.license.is_spdx_compound_expression', return_value=True): + with unittest.mock.patch('cyclonedx.factory.license.is_spdx_expression', return_value=True): actual = LicenseFactory().make_with_expression(expression='foo', acknowledgement=acknowledgement) self.assertEqual(expected, actual) def test_make_with_expression_raises(self) -> None: with self.assertRaises(InvalidLicenseExpressionException, msg='foo'): - with unittest.mock.patch('cyclonedx.factory.license.is_spdx_compound_expression', return_value=False): + with unittest.mock.patch('cyclonedx.factory.license.is_spdx_expression', return_value=False): LicenseFactory().make_with_expression('foo') diff --git a/tests/test_spdx.py b/tests/test_spdx.py index a174e5c0..334fde4d 100644 --- a/tests/test_spdx.py +++ b/tests/test_spdx.py @@ -82,7 +82,7 @@ class TestSpdxIsCompoundExpression(TestCase): @idata(VALID_COMPOUND_EXPRESSIONS) def test_positive(self, valid_expression: str) -> None: - actual = spdx.is_compound_expression(valid_expression) + actual = spdx.is_expression(valid_expression) self.assertTrue(actual) @data( @@ -92,5 +92,5 @@ def test_positive(self, valid_expression: str) -> None: 'Apache License, Version 2.0' ) def test_negative(self, invalid_expression: str) -> None: - actual = spdx.is_compound_expression(invalid_expression) + actual = spdx.is_expression(invalid_expression) self.assertFalse(actual)