Skip to content

refactor: rename spdx.is_compund_expression -> spdx.is_expression #779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cyclonedx/factory/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions cyclonedx/spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

__all__ = [
'is_supported_id', 'fixup_id',
'is_compound_expression'
'is_expression'
]

from json import load as json_load
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_factory_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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')
4 changes: 2 additions & 2 deletions tests/test_spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)