Check that the ``licenses`` a mapping of {key: License} are valid. Return dictionaries of infos, errors and warnings mapping a license key to validation issue messages. Print messages if ``verbose`` is True. NOTE: we DO NOT run this validation as part of loading or
(licenses, verbose=False, no_dupe_urls=False, thorough=False)
| 568 | |
| 569 | @staticmethod |
| 570 | def validate(licenses, verbose=False, no_dupe_urls=False, thorough=False): |
| 571 | """ |
| 572 | Check that the ``licenses`` a mapping of {key: License} are valid. |
| 573 | Return dictionaries of infos, errors and warnings mapping a license key |
| 574 | to validation issue messages. Print messages if ``verbose`` is True. |
| 575 | |
| 576 | NOTE: we DO NOT run this validation as part of loading or constructing |
| 577 | License objects. Instead this is invoked ONLY as part of the test suite. |
| 578 | """ |
| 579 | infos = defaultdict(list) |
| 580 | warnings = defaultdict(list) |
| 581 | errors = defaultdict(list) |
| 582 | |
| 583 | # used for global dedupe of texts |
| 584 | by_spdx_key_lowered = defaultdict(list) |
| 585 | by_text = defaultdict(list) |
| 586 | by_short_name_lowered = defaultdict(list) |
| 587 | by_name_lowered = defaultdict(list) |
| 588 | |
| 589 | for key, lic in licenses.items(): |
| 590 | warn = warnings[key].append |
| 591 | info = infos[key].append |
| 592 | error = errors[key].append |
| 593 | if lic.name: |
| 594 | by_name_lowered[lic.name.lower()].append(lic) |
| 595 | else: |
| 596 | by_name_lowered[lic.name].append(lic) |
| 597 | if lic.short_name: |
| 598 | by_short_name_lowered[lic.short_name.lower()].append(lic) |
| 599 | else: |
| 600 | by_short_name_lowered[lic.short_name].append(lic) |
| 601 | |
| 602 | if lic.key != lic.key.lower(): |
| 603 | error('Incorrect license key case: must be all lowercase.') |
| 604 | |
| 605 | if len(lic.key) > 50: |
| 606 | error('key must be 50 characters or less.') |
| 607 | |
| 608 | if '_'in lic.key: |
| 609 | error('key cannot contain an underscore: this is not valid in SPDX.') |
| 610 | |
| 611 | if not lic.short_name: |
| 612 | error('No short name') |
| 613 | elif len(lic.short_name) > 50: |
| 614 | error('short name must be 50 characters or less.') |
| 615 | |
| 616 | if not lic.name: |
| 617 | error('No name') |
| 618 | |
| 619 | if not lic.category: |
| 620 | error('No category: Use "Unstated License" if not known.') |
| 621 | if lic.category and lic.category not in CATEGORIES: |
| 622 | cats = '\n'.join(sorted(CATEGORIES)) |
| 623 | error( |
| 624 | f'Unknown license category: {lic.category}.\n' + |
| 625 | f'Use one of these valid categories:\n{cats}' |
| 626 | ) |
| 627 |
no test coverage detected