Skip to content

Commit 0fd8122

Browse files
committed
Unify two very similar functions
1 parent 30d5e96 commit 0fd8122

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed

pyp2spec/license_processor.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def _is_compliant_with_fedora(identifier, fedora_licenses):
146146
return False
147147

148148

149-
def good_for_fedora(spdx_identifiers, *, licenses_dict=None, session=None):
150-
"""Determine whether all of the given SPDX identifiers are good for Fedora.
149+
def check_compliance(license, *, licenses_dict=None, session=None):
150+
"""Determine whether the license is good for Fedora.
151151
152152
Store the results in the checked_identifiers dictionary, under the
153153
respective `bad` and `good` keys.
@@ -167,6 +167,7 @@ def good_for_fedora(spdx_identifiers, *, licenses_dict=None, session=None):
167167
"good": [],
168168
}
169169

170+
spdx_identifiers = license_keyword_to_spdx_identifiers(license)
170171
if not spdx_identifiers:
171172
return (False, checked_identifies)
172173
for spdx_identifier in spdx_identifiers:
@@ -179,17 +180,6 @@ def good_for_fedora(spdx_identifiers, *, licenses_dict=None, session=None):
179180
return (True, checked_identifies)
180181

181182

182-
def check_compliance(license, *, session=None, licenses_dict=None):
183-
identifiers = license_keyword_to_spdx_identifiers(license)
184-
185-
is_compliant, checked_identifiers = good_for_fedora(
186-
identifiers,
187-
session=session,
188-
licenses_dict=licenses_dict
189-
)
190-
return is_compliant, checked_identifiers
191-
192-
193183
def transform_to_spdx(license_field, classifiers):
194184
"""Return SPDX identifiers and expression based on the found
195185
package license metadata (classifiers or license keyword).

tests/test_license_processor.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from pyp2spec.license_processor import classifiers_to_spdx_identifiers, license_keyword_to_spdx_identifiers
4-
from pyp2spec.license_processor import _is_compliant_with_fedora, good_for_fedora
4+
from pyp2spec.license_processor import _is_compliant_with_fedora
55
from pyp2spec.license_processor import NoSuchClassifierError, check_compliance, generate_spdx_expression
66

77

@@ -82,21 +82,6 @@ def test_compliance_check_with_fedora(identifier, expected, fake_fedora_licenses
8282
assert _is_compliant_with_fedora(identifier, fake_fedora_licenses) is expected
8383

8484

85-
@pytest.mark.parametrize(
86-
("identifiers", "expected"),
87-
(
88-
(["AAL", "MIT", "CECILL-B"], (True, {"bad": [], "good": ["AAL", "MIT", "CECILL-B"]})),
89-
([], (False, {"bad": [], "good": []})),
90-
(["LicenseRef-LPPL", "MIT"], (False, {"bad": ["LicenseRef-LPPL"], "good": ["MIT"]})), # mixed not allowed/allowed
91-
(["LicenseRef-LPPL", "Aladdin", "LicenseRef-OpenFlow", "APL-1.0"], (False, {"bad": ["LicenseRef-LPPL", "Aladdin", "LicenseRef-OpenFlow", "APL-1.0"], "good": []})),
92-
),
93-
)
94-
def test_is_allowed_in_fedora(identifiers, expected, fake_fedora_licenses):
95-
"""Test the function logic, bear in mind that Fedora status may change in time"""
96-
97-
assert good_for_fedora(identifiers, licenses_dict=fake_fedora_licenses) == expected
98-
99-
10085
def test_no_license_classifiers_and_no_license_keyword():
10186
classifiers = []
10287
license_keyword = ""
@@ -151,6 +136,10 @@ def test_license_keyword_and_classifiers():
151136
("MIT AND EUPL-1.0", ["MIT"], ["EUPL-1.0"], False),
152137
("RSCPL", [], ["RSCPL"], False),
153138
("Fake-identifier", [], [], False), # not a valid identifier, ergo not in "bad" list
139+
("AAL AND MIT AND CECILL-B", ["AAL", "CECILL-B", "MIT"], [], True),
140+
("", [], [], False),
141+
142+
154143
)
155144
)
156145
def test_check_compliance(license, good, bad, expected, fake_fedora_licenses):

0 commit comments

Comments
 (0)