diff --git a/src/packagedcode/rubygems.py b/src/packagedcode/rubygems.py index e38c798646..e98d1ffb23 100644 --- a/src/packagedcode/rubygems.py +++ b/src/packagedcode/rubygems.py @@ -676,7 +676,6 @@ def get_dependencies(dependencies): 'ISC': 'isc', 'LGPL-2.1+': 'lgpl-2.1-plus', 'LGPL-3': 'lgpl-3.0', - 'LGPL': 'lgpl', 'LGPL': 'lgpl-2.0-plus', 'LGPLv2.1+': 'lgpl-2.1-plus', 'MIT': 'mit', diff --git a/tests/packagedcode/test_rubygems.py b/tests/packagedcode/test_rubygems.py index fffee60c3e..37ece9e876 100644 --- a/tests/packagedcode/test_rubygems.py +++ b/tests/packagedcode/test_rubygems.py @@ -7,9 +7,11 @@ # See https://aboutcode.org for more information about nexB OSS projects. # +import ast import io import json import os +from pathlib import Path from commoncode import text from commoncode.testcase import FileBasedTesting @@ -113,6 +115,36 @@ def test_build_rubygem_package_does_not_crash(self): rubygems.GemMetadataArchiveExtractedHandler.parse(test_file) +class TestRubygemsLicensesMapping(object): + + def test_licenses_mapping_has_no_duplicated_declared_license(self): + # A duplicated key in a dict literal is silently dropped by Python, so + # this has to be checked on the source rather than on the loaded dict. + source = Path(rubygems.__file__).read_text(encoding='utf-8') + + mapping = None + for node in ast.walk(ast.parse(source)): + if isinstance(node, ast.Assign) and any( + isinstance(target, ast.Name) and target.id == 'LICENSES_MAPPING' + for target in node.targets + ): + mapping = node.value + + assert mapping is not None, 'LICENSES_MAPPING not found in rubygems.py' + + declared = [ + key.value for key in mapping.keys + if isinstance(key, ast.Constant) + ] + duplicated = sorted( + {key for key in declared if declared.count(key) > 1} + ) + assert duplicated == [] + + def test_licenses_mapping_maps_bare_lgpl_to_lgpl_2_0_plus(self): + assert rubygems.LICENSES_MAPPING['LGPL'] == 'lgpl-2.0-plus' + + def relative_walk(dir_path, extension='.gem'): """ Walk `dir_path` and yield paths that end with `extension` relative to