Skip to content
Open
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
1 change: 0 additions & 1 deletion src/packagedcode/rubygems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
32 changes: 32 additions & 0 deletions tests/packagedcode/test_rubygems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading