Skip to content

Commit 81c9bb0

Browse files
committed
test: license_matrix
1 parent 437b568 commit 81c9bb0

File tree

9 files changed

+212
-11
lines changed

9 files changed

+212
-11
lines changed

documentation/reference/licensecheck/license_matrix.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ License Matrix
3131

3232
## depCompatWMyLice
3333

34-
[Show source in license_matrix.py:166](../../../licensecheck/license_matrix.py#L166)
34+
[Show source in license_matrix.py:168](../../../licensecheck/license_matrix.py#L168)
3535

3636
Identify if the end user license is compatible with the dependency license(s).
3737

@@ -66,7 +66,7 @@ def depCompatWMyLice(
6666

6767
## licenseLookup
6868

69-
[Show source in license_matrix.py:43](../../../licensecheck/license_matrix.py#L43)
69+
[Show source in license_matrix.py:44](../../../licensecheck/license_matrix.py#L44)
7070

7171
Identify a license from an uppercase string representation of a license.
7272

@@ -93,7 +93,7 @@ def licenseLookup(licenseStr: str) -> L:
9393

9494
## licenseType
9595

96-
[Show source in license_matrix.py:99](../../../licensecheck/license_matrix.py#L99)
96+
[Show source in license_matrix.py:101](../../../licensecheck/license_matrix.py#L101)
9797

9898
Return a list of license types from a license string.
9999

documentation/reference/licensecheck/types.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Types
1212

1313
## License
1414

15-
[Show source in types.py:29](../../../licensecheck/types.py#L29)
15+
[Show source in types.py:30](../../../licensecheck/types.py#L30)
1616

1717
#### Attributes
1818

@@ -48,7 +48,7 @@ class License(Enum):
4848

4949
## PackageInfo
5050

51-
[Show source in types.py:12](../../../licensecheck/types.py#L12)
51+
[Show source in types.py:13](../../../licensecheck/types.py#L13)
5252

5353
PackageInfo type.
5454

licensecheck/get_deps.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import requirements
99

1010
from licensecheck import license_matrix, packageinfo
11-
from licensecheck.types import PackageInfo
11+
from licensecheck.types import JOINS, PackageInfo
1212

1313
USINGS = ["requirements", "poetry"]
1414

@@ -126,7 +126,7 @@ def getDepsWithLicenses(
126126
package.licenseCompat = license_matrix.depCompatWMyLice( # type: ignore
127127
myLice,
128128
license_matrix.licenseType(package.license),
129-
license_matrix.licenseType(", ".join(ignoreLicenses)),
130-
license_matrix.licenseType(", ".join(failLicenses)),
129+
license_matrix.licenseType(JOINS.join(ignoreLicenses)),
130+
license_matrix.licenseType(JOINS.join(failLicenses)),
131131
)
132132
return packages

licensecheck/license_matrix.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"""
3838
from __future__ import annotations
3939

40+
from licensecheck.types import JOINS
4041
from licensecheck.types import License as L
4142

4243

@@ -84,6 +85,7 @@ def licenseLookup(licenseStr: str) -> L:
8485
"GPL-2.0": L.GPL_2,
8586
"GPLV3": L.GPL_3,
8687
"GPL-3.0": L.GPL_3,
88+
"GPL": L.GPL_X,
8789
"MPL": L.MPL,
8890
"EUPL": L.EU,
8991
"PROPRIETARY": L.PROPRIETARY,
@@ -107,7 +109,7 @@ def licenseType(lice: str) -> list[L]:
107109
"""
108110
if len(lice) < 1:
109111
return []
110-
return [licenseLookup(x) for x in lice.upper().split(", ")]
112+
return [licenseLookup(x) for x in lice.upper().split(JOINS)]
111113

112114

113115
# Permissive licenses compatible with GPL

licensecheck/packageinfo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import requests
1111
import tomli
1212

13-
from licensecheck.types import UNKNOWN, PackageInfo
13+
from licensecheck.types import JOINS, UNKNOWN, PackageInfo
1414

1515

1616
def getPackageInfoLocal(requirement: str) -> PackageInfo:
@@ -91,7 +91,7 @@ def licenseFromClassifierlist(classifiers: list[str]) -> str:
9191
lice = val.split(" :: ")[-1]
9292
if lice != "OSI Approved":
9393
licenses.append(lice)
94-
return ", ".join(licenses) if len(licenses) > 0 else UNKNOWN
94+
return JOINS.join(licenses) if len(licenses) > 0 else UNKNOWN
9595

9696

9797
def getPackages(reqs: set[str]) -> set[PackageInfo]:

licensecheck/types.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from enum import Enum
77

88
UNKNOWN = "UNKNOWN"
9+
JOINS = ";; "
910

1011

1112
@dataclass(unsafe_hash=True)

tests/data/licenseCheckLicenses.txt

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
NO_LICENSE
2+
PUBLIC
3+
NO_LICENSE
4+
NO_LICENSE
5+
NO_LICENSE
6+
NO_LICENSE
7+
NO_LICENSE
8+
NO_LICENSE
9+
NO_LICENSE
10+
NO_LICENSE
11+
NO_LICENSE
12+
NO_LICENSE
13+
NO_LICENSE
14+
NO_LICENSE
15+
NO_LICENSE
16+
NO_LICENSE
17+
ACADEMIC_FREE
18+
APACHE
19+
NO_LICENSE
20+
NO_LICENSE
21+
NO_LICENSE
22+
BSD
23+
BOOST
24+
NO_LICENSE
25+
NO_LICENSE
26+
NO_LICENSE
27+
ECLIPSE
28+
ECLIPSE
29+
NO_LICENSE
30+
EU
31+
EU
32+
EU
33+
NO_LICENSE
34+
AGPL_3_PLUS
35+
NO_LICENSE
36+
GPL_X
37+
GPL_2
38+
GPL_2_PLUS
39+
GPL_3
40+
GPL_3_PLUS
41+
LGPL_2
42+
LGPL_2_PLUS
43+
LGPL_3
44+
LGPL_3_PLUS
45+
LGPL_X
46+
ISC
47+
NO_LICENSE
48+
ISC
49+
NO_LICENSE
50+
NO_LICENSE
51+
MIT
52+
MIT
53+
MIT
54+
NO_LICENSE
55+
NO_LICENSE
56+
MPL
57+
MPL
58+
MPL
59+
NO_LICENSE
60+
NO_LICENSE
61+
NO_LICENSE
62+
NO_LICENSE
63+
NO_LICENSE
64+
NO_LICENSE
65+
PSFL
66+
PSFL
67+
NO_LICENSE
68+
NO_LICENSE
69+
NO_LICENSE
70+
NO_LICENSE
71+
NO_LICENSE
72+
NO_LICENSE
73+
UNLICENSE
74+
NO_LICENSE
75+
NCSA
76+
NO_LICENSE
77+
NO_LICENSE
78+
NO_LICENSE
79+
NO_LICENSE
80+
NO_LICENSE
81+
PROPRIETARY
82+
PUBLIC
83+
NO_LICENSE

tests/data/rawLicenses.txt

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Aladdin Free Public License (AFPL)
2+
CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
3+
CeCILL-B Free Software License Agreement (CECILL-B)
4+
CeCILL-C Free Software License Agreement (CECILL-C)
5+
DFSG approved
6+
Eiffel Forum License (EFL)
7+
Free For Educational Use
8+
Free For Home Use
9+
Free To Use But Restricted
10+
Free for non-commercial use
11+
Freely Distributable
12+
Freeware
13+
GUST Font License 1.0
14+
GUST Font License 2006-09-30
15+
Netscape Public License (NPL)
16+
Nokia Open Source License (NOKOS)
17+
Academic Free License (AFL)
18+
Apache Software License
19+
Apple Public Source License
20+
Artistic License
21+
Attribution Assurance License
22+
BSD License
23+
Boost Software License 1.0 (BSL-1.0)
24+
CEA CNRS Inria Logiciel Libre License, version 2.1 (CeCILL-2.1)
25+
Common Development and Distribution License 1.0 (CDDL-1.0)
26+
Common Public License
27+
Eclipse Public License 1.0 (EPL-1.0)
28+
Eclipse Public License 2.0 (EPL-2.0)
29+
Eiffel Forum License
30+
European Union Public Licence 1.0 (EUPL 1.0)
31+
European Union Public Licence 1.1 (EUPL 1.1)
32+
European Union Public Licence 1.2 (EUPL 1.2)
33+
GNU Affero General Public License v3
34+
GNU Affero General Public License v3 or later (AGPLv3+)
35+
GNU Free Documentation License (FDL)
36+
GNU General Public License (GPL)
37+
GNU General Public License v2 (GPLv2)
38+
GNU General Public License v2 or later (GPLv2+)
39+
GNU General Public License v3 (GPLv3)
40+
GNU General Public License v3 or later (GPLv3+)
41+
GNU Lesser General Public License v2 (LGPLv2)
42+
GNU Lesser General Public License v2 or later (LGPLv2+)
43+
GNU Lesser General Public License v3 (LGPLv3)
44+
GNU Lesser General Public License v3 or later (LGPLv3+)
45+
GNU Library or Lesser General Public License (LGPL)
46+
Historical Permission Notice and Disclaimer (HPND)
47+
IBM Public License
48+
ISC License (ISCL)
49+
Intel Open Source License
50+
Jabber Open Source License
51+
MIT License
52+
MIT No Attribution License (MIT-0)
53+
MITRE Collaborative Virtual Workspace License (CVW)
54+
MirOS License (MirOS)
55+
Motosoto License
56+
Mozilla Public License 1.0 (MPL)
57+
Mozilla Public License 1.1 (MPL 1.1)
58+
Mozilla Public License 2.0 (MPL 2.0)
59+
Mulan Permissive Software License v2 (MulanPSL-2.0)
60+
Nethack General Public License
61+
Nokia Open Source License
62+
Open Group Test Suite License
63+
Open Software License 3.0 (OSL-3.0)
64+
PostgreSQL License
65+
Python License (CNRI Python License)
66+
Python Software Foundation License
67+
Qt Public License (QPL)
68+
Ricoh Source Code Public License
69+
SIL Open Font License 1.1 (OFL-1.1)
70+
Sleepycat License
71+
Sun Industry Standards Source License (SISSL)
72+
Sun Public License
73+
The Unlicense (Unlicense)
74+
Universal Permissive License (UPL)
75+
University of Illinois/NCSA Open Source License
76+
Vovida Software License 1.0
77+
W3C License
78+
X.Net License
79+
Zope Public License
80+
zlib/libpng License
81+
Other/Proprietary License
82+
Public Domain
83+
Repoze Public License

tests/test_license_matrix.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import logging
2+
from pathlib import Path
3+
4+
from licensecheck import license_matrix, types
5+
6+
THISDIR = str(Path(__file__).resolve().parent)
7+
8+
9+
def test_licenseLookup():
10+
licenses = []
11+
for rawLicense in Path(f"{THISDIR}/data/rawLicenses.txt").read_text("utf-8").splitlines():
12+
licenseName = license_matrix.licenseLookup(rawLicense.upper())._name_
13+
licenses.append(licenseName)
14+
15+
for x in types.License._member_names_:
16+
if x not in licenses:
17+
logging.error(f"{x} not in licenses")
18+
assert False
19+
20+
# Path(f"{THISDIR}/data/licenseCheckLicenses.txt").write_text("\n".join(licenses), "utf-8")
21+
assert "\n".join(licenses) == Path(f"{THISDIR}/data/licenseCheckLicenses.txt").read_text(
22+
"utf-8"
23+
)
24+
25+
26+
def test_licenseType():
27+
licenses = Path(f"{THISDIR}/data/rawLicenses.txt").read_text("utf-8").replace("\n", types.JOINS)
28+
licenseNames = [x._name_ for x in license_matrix.licenseType(licenses)]
29+
assert (
30+
licenseNames
31+
== Path(f"{THISDIR}/data/licenseCheckLicenses.txt").read_text("utf-8").splitlines()
32+
)

0 commit comments

Comments
 (0)