| 1 |
#!/usr/bin/env python3 |
| 2 |
# Copyright: 2026, Maximiliano Curia <[email protected]> |
| 3 |
# |
| 4 |
# License: ISC |
| 5 |
# Permission to use, copy, modify, and/or distribute this software for any |
| 6 |
# purpose with or without fee is hereby granted, provided that the above |
| 7 |
# copyright notice and this permission notice appear in all copies. |
| 8 |
# . |
| 9 |
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH |
| 10 |
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 11 |
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 12 |
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 13 |
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE |
| 14 |
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 15 |
# PERFORMANCE OF THIS SOFTWARE. |
| 16 |
|
| 17 |
"""Tests for the DEP-5 name -> common-licenses file map.""" |
| 18 |
|
| 19 |
from __future__ import annotations |
| 20 |
|
| 21 |
from decopy.licensing.data.common_licenses import ( |
| 22 |
COMMON_LICENSES, |
| 23 |
common_license_for, |
| 24 |
) |
| 25 |
from decopy.licensing.data.loader import common_licenses_index |
| 26 |
from decopy.licensing.spdx import canonical_license_name |
| 27 |
|
| 28 |
|
| 29 |
def test_map_targets_in_index(): |
| 30 |
index = common_licenses_index() |
| 31 |
for key, entry in COMMON_LICENSES.items(): |
| 32 |
assert entry.file in index, (key, entry.file) |
| 33 |
|
| 34 |
|
| 35 |
def test_map_keys_canonical(): |
| 36 |
# Keys are the canonical DEP-5 names decopy emits, so a lookup by a freshly |
| 37 |
# detected name hits directly. Idempotence under canonical_license_name is |
| 38 |
# the invariant that guarantees it. |
| 39 |
for key in COMMON_LICENSES: |
| 40 |
assert canonical_license_name(key) == key |
| 41 |
|
| 42 |
|
| 43 |
def test_or_later_shares_file(): |
| 44 |
# The +/only distinction changes the header, not the referenced text file. |
| 45 |
assert common_license_for("GPL-2") is not None |
| 46 |
assert common_license_for("GPL-2+") == common_license_for("GPL-2") |
| 47 |
|
| 48 |
|
| 49 |
def test_gfdl_niv_shares_text_file(): |
| 50 |
# GFDL-NIV (no-invariants) is a usage choice stated in the notice; the |
| 51 |
# referenced GFDL text file is the same as the invariants-allowing name. |
| 52 |
niv = common_license_for("GFDL-NIV-1.2+") |
| 53 |
plain = common_license_for("GFDL-1.2") |
| 54 |
assert niv is not None |
| 55 |
assert plain is not None |
| 56 |
assert niv.file == "GFDL-1.2" |
| 57 |
assert niv.file == plain.file |
| 58 |
|
| 59 |
|
| 60 |
def test_unknown_returns_none(): |
| 61 |
assert common_license_for("Zlib") is None |