| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Unit tests for decopy |
| 4 |
# Copyright: 2016, Maximiliano Curia <[email protected]> |
| 5 |
# |
| 6 |
# License: ISC |
| 7 |
# Permission to use, copy, modify, and/or distribute this software for any |
| 8 |
# purpose with or without fee is hereby granted, provided that the above |
| 9 |
# copyright notice and this permission notice appear in all copies. |
| 10 |
# . |
| 11 |
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH |
| 12 |
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 13 |
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 14 |
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 15 |
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE |
| 16 |
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 17 |
# PERFORMANCE OF THIS SOFTWARE. |
| 18 |
|
| 19 |
import json |
| 20 |
import unittest |
| 21 |
from pathlib import Path |
| 22 |
|
| 23 |
try: |
| 24 |
import regex as rex |
| 25 |
except ImportError: |
| 26 |
import re as rex # type: ignore[no-redef] |
| 27 |
|
| 28 |
from decopy.licensing import license_parsers, licenses |
| 29 |
from decopy.licensing.holders import ( |
| 30 |
CopyrightHolders, |
| 31 |
iter_lines, |
| 32 |
parse_copyright, |
| 33 |
parse_holders, |
| 34 |
) |
| 35 |
|
| 36 |
|
| 37 |
class TestMatchers(unittest.TestCase): |
| 38 |
def test_clean_comments(self): |
| 39 |
test = ( |
| 40 |
"\n" |
| 41 |
"c Fortran\n" |
| 42 |
"C Idem\n" |
| 43 |
" /* C // C++ */\n" |
| 44 |
";; Lisp\n" |
| 45 |
" <!-- HTML -->\n" |
| 46 |
"dnl m4\n" |
| 47 |
" * continuation *\n" |
| 48 |
"\n" |
| 49 |
) |
| 50 |
|
| 51 |
result = licenses.clean_comments(test) |
| 52 |
self.assertEqual(result, " Fortran Idem C C++ Lisp HTML m4 continuation ") |
| 53 |
|
| 54 |
def test_parse_copyright(self): |
| 55 |
line = "Copyright: Foo Bar <[email protected]>" |
| 56 |
continuation = None |
| 57 |
copyrights, continuation = parse_copyright(line, continuation) |
| 58 |
assert copyrights is not None |
| 59 |
self.assertEqual(len(copyrights), 1) |
| 60 |
self.assertEqual(copyrights[0], "Foo Bar <[email protected]>") |
| 61 |
line = " 2050- Baz <[email protected]>" |
| 62 |
copyrights, continuation = parse_copyright(line, continuation) |
| 63 |
assert copyrights is not None |
| 64 |
self.assertEqual(len(copyrights), 1) |
| 65 |
self.assertEqual(copyrights[0], "2050- Baz <[email protected]>") |
| 66 |
line = "Copyright (c) William Boo, (c) La Momia" |
| 67 |
copyrights, _continuation = parse_copyright(line, continuation) |
| 68 |
assert copyrights is not None |
| 69 |
self.assertEqual(len(copyrights), 2) |
| 70 |
self.assertEqual(copyrights[0], "William Boo") |
| 71 |
self.assertEqual(copyrights[1], "La Momia") |
| 72 |
|
| 73 |
def test_iter_lines_leading_newline(self): |
| 74 |
# Regression: end <= 0 broke when text starts with '\n' (end == 0 is a |
| 75 |
# valid position, not a sentinel; only end == -1 means "not found"). |
| 76 |
lines = list(iter_lines("\nhello\nworld")) |
| 77 |
self.assertEqual(lines[0][0], "") # empty line before first \n |
| 78 |
self.assertEqual(lines[1][0], "hello") |
| 79 |
self.assertEqual(lines[2][0], "world") |
| 80 |
|
| 81 |
def test_no_false_positive_from_unlicense_text(self): |
| 82 |
# Regression: "copyright laws, the author or authors of this" must not |
| 83 |
# produce a holder - the indicator fires on "copyright laws" because a |
| 84 |
# space satisfies [:\s]+, and the plural "laws" slipped past the |
| 85 |
# r"^\s*law[.:]?\b" post-ignore (word boundary fails between 'w' and 's'). |
| 86 |
text = ( |
| 87 |
" * In jurisdictions that recognize copyright laws, the author or authors of\n" # noqa: E501 |
| 88 |
" * this software dedicate any and all copyright and related and neighboring\n" # noqa: E501 |
| 89 |
" * rights to this software to the public domain worldwide.\n" |
| 90 |
) |
| 91 |
holders = parse_holders(text) |
| 92 |
self.assertEqual(holders, []) |
| 93 |
|
| 94 |
def test_python_unicode_string_assignment_in_copyright(self): |
| 95 |
# Regression: patch hunk header "@@ ... @@ copyright = u'YEAR NAME'" |
| 96 |
# must not produce "= u" as a copyright holder. |
| 97 |
holders = parse_holders( |
| 98 |
"@@ -54,7 +54,7 @@ copyright = u'2013, 2014, 2015 CERN'" |
| 99 |
) |
| 100 |
names = [h.name for h in holders] |
| 101 |
self.assertNotIn("= u", names) |
| 102 |
self.assertEqual(len(holders), 1) |
| 103 |
self.assertEqual(holders[0].name, "CERN") |
| 104 |
self.assertEqual(str(holders[0].years), "2013-2015") |
| 105 |
|
| 106 |
def test_markdown_reference_link_in_copyright(self): |
| 107 |
# Regression: [Aptible][aptible] must produce holder "Aptible", not |
| 108 |
# "Aptible][aptible" (strip() removes outer brackets but not the inner ][). |
| 109 |
holders = parse_holders( |
| 110 |
"Copyright (c) 2019 [Aptible][aptible]. All rights reserved." |
| 111 |
) |
| 112 |
self.assertEqual(len(holders), 1) |
| 113 |
self.assertEqual(holders[0].name, "Aptible") |
| 114 |
self.assertEqual(str(holders[0].years), "2019") |
| 115 |
|
| 116 |
def test_markdown_inline_link_in_copyright(self): |
| 117 |
# [Aptible](https://aptible.com) should produce holder "Aptible". |
| 118 |
holders = parse_holders( |
| 119 |
"Copyright (c) 2019 [Aptible](https://aptible.com). All rights reserved." |
| 120 |
) |
| 121 |
self.assertEqual(len(holders), 1) |
| 122 |
self.assertEqual(holders[0].name, "Aptible") |
| 123 |
self.assertEqual(str(holders[0].years), "2019") |
| 124 |
|
| 125 |
def test_code_fragment_with_punctuation_not_a_holder(self): |
| 126 |
# ruff flake8_copyright/settings.rs: a Rust statement mentioning the word |
| 127 |
# COPYRIGHT must not yield a code-fragment holder like "LazyLock<Regex> =". |
| 128 |
holders = parse_holders("pub static COPYRIGHT: LazyLock<Regex> =") |
| 129 |
self.assertEqual([h.name for h in holders], []) |
| 130 |
|
| 131 |
def test_assignment_fragment_not_a_holder(self): |
| 132 |
# ruff A001 snapshot fixture line "copyright: 'annotation' = 2". |
| 133 |
holders = parse_holders("copyright: 'annotation' = 2") |
| 134 |
self.assertFalse([h.name for h in holders if "=" in h.name]) |
| 135 |
|
| 136 |
def test_format_string_fragment_not_a_holder(self): |
| 137 |
# ruff F504 snapshot fixture; code punctuation must disqualify it. |
| 138 |
holders = parse_holders( |
| 139 |
'"%(a)s %(c)s" % {a: "?", "b": "!"} # Copyright F504 ("b" not used)' |
| 140 |
) |
| 141 |
self.assertFalse([h.name for h in holders if set('{}"#') & set(h.name)]) |
| 142 |
|
| 143 |
def test_lambda_with_copyright_param_not_a_holder(self): |
| 144 |
# ruff A006 fixture: "lambda print, copyright: print" is code; the |
| 145 |
# lambda-with-copyright-parameter line is ignored, not parsed as a holder. |
| 146 |
holders = parse_holders("lambda print, copyright: print") |
| 147 |
self.assertEqual(holders, []) |
| 148 |
|
| 149 |
def test_same_name_holders_merge_years(self): |
| 150 |
# The two typeshed PSF notices (one with a trailing ", and were" clause |
| 151 |
# that F3 trims) collapse to one holder with a merged year range. |
| 152 |
text = ( |
| 153 |
"Copyright 2003 Python Software Foundation\n" |
| 154 |
"so portions are Copyright (C) 2001 Python Software Foundation, and were" |
| 155 |
) |
| 156 |
holders = CopyrightHolders() |
| 157 |
holders.extend(parse_holders(text)) |
| 158 |
self.assertEqual( |
| 159 |
list(holders.sorted_members()), |
| 160 |
["2001-2003, Python Software Foundation"], |
| 161 |
) |
| 162 |
|
| 163 |
def test_all_rights_reserved_ends_holder(self): |
| 164 |
# ruff typeshed .pyi: "(c) Copyright CNRI, All Rights Reserved. NO |
| 165 |
# WARRANTY." - "All Rights Reserved" ends the holder; the trailing |
| 166 |
# boilerplate ("NO WARRANTY") is not part of the name. |
| 167 |
holders = parse_holders("(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.") |
| 168 |
self.assertEqual([h.name for h in holders], ["CNRI"]) |
| 169 |
|
| 170 |
def test_lowercase_nickname_holder_is_kept(self): |
| 171 |
# Case is not a signal: a lowercase nickname is a valid holder, with or |
| 172 |
# without a year. |
| 173 |
self.assertEqual( |
| 174 |
[h.name for h in parse_holders("Copyright 2020 redis")], ["redis"] |
| 175 |
) |
| 176 |
self.assertEqual([h.name for h in parse_holders("Copyright dhh")], ["dhh"]) |
| 177 |
|
| 178 |
def test_present_in_comma_year_range_dropped(self): |
| 179 |
# ruff jemalloc COPYING: "2009, present, Facebook, Inc" - "present" is |
| 180 |
# not a year and must not enter the holder name. |
| 181 |
holders = parse_holders("Copyright 2009, present, Facebook, Inc.") |
| 182 |
self.assertEqual( |
| 183 |
[(h.name, str(h.years)) for h in holders], [("Facebook, Inc", "2009")] |
| 184 |
) |
| 185 |
|
| 186 |
def test_present_in_dash_year_range_dropped(self): |
| 187 |
# ruff jemalloc COPYING: "2002-present Jason Evans". |
| 188 |
holders = parse_holders( |
| 189 |
"Copyright (C) 2002-present Jason Evans <[email protected]>" |
| 190 |
) |
| 191 |
self.assertEqual( |
| 192 |
[(h.name, str(h.years)) for h in holders], [("Jason Evans", "2002")] |
| 193 |
) |
| 194 |
|
| 195 |
def test_normal_year_range_unchanged(self): |
| 196 |
# Guard: a real numeric range must be untouched by the present/current rule. |
| 197 |
holders = parse_holders("Copyright 2009-2014 Florent Xicluna") |
| 198 |
self.assertEqual( |
| 199 |
[(h.name, str(h.years)) for h in holders], |
| 200 |
[("Florent Xicluna", "2009-2014")], |
| 201 |
) |
| 202 |
|
| 203 |
def test_trailing_prose_clause_trimmed(self): |
| 204 |
# ruff typeshed wsgiref/headers.pyi: the copyright line runs into prose |
| 205 |
# "..., and were [contributed by ...]"; the dangling clause must be cut. |
| 206 |
holders = parse_holders( |
| 207 |
"so portions are Copyright (C) 2001 Python Software Foundation, and were" |
| 208 |
) |
| 209 |
self.assertEqual( |
| 210 |
[(h.name, str(h.years)) for h in holders], |
| 211 |
[("Python Software Foundation", "2001")], |
| 212 |
) |
| 213 |
|
| 214 |
def test_and_affiliates_holder_is_kept(self): |
| 215 |
# Guard: "and affiliates" is a legitimate org tail (no verb), keep it. |
| 216 |
holders = parse_holders("Copyright 2024 Meta Platforms, Inc. and affiliates") |
| 217 |
self.assertEqual( |
| 218 |
[h.name for h in holders], ["Meta Platforms, Inc. and affiliates"] |
| 219 |
) |
| 220 |
|
| 221 |
def test_coholders_joined_by_comma_and_are_split(self): |
| 222 |
# "X, and Y Corp" is two holders sharing the year, not one combined name. |
| 223 |
holders = parse_holders("Copyright (c) 2019 Foo, and Bar Corp") |
| 224 |
self.assertEqual( |
| 225 |
sorted((h.name, str(h.years)) for h in holders), |
| 226 |
[("Bar Corp", "2019"), ("Foo", "2019")], |
| 227 |
) |
| 228 |
|
| 229 |
def test_no_comma_and_is_not_split(self): |
| 230 |
# Guard: " and " without a comma must not over-split into a lone |
| 231 |
# trailing name; only a comma-led "X, and Y" is split. |
| 232 |
holders = parse_holders( |
| 233 |
"Copyright 2006 Mutsuo Saito, Makoto Matsumoto and Hiroshima" |
| 234 |
) |
| 235 |
self.assertNotIn("Hiroshima", [h.name for h in holders]) |
| 236 |
|
| 237 |
def test_parse_holders(self): |
| 238 |
text = " /* Copyright Foo Bar\n * Baz */\n // Copyright (c) Lorem, (c) Ipsum" |
| 239 |
holders = parse_holders(text) |
| 240 |
self.assertEqual( |
| 241 |
[holder.person for holder in holders], |
| 242 |
["Foo Bar", "Baz", "Lorem", "Ipsum"], |
| 243 |
) |
| 244 |
|
| 245 |
def test_parse_holders_multiline(self): |
| 246 |
# Positive |
| 247 |
text = ( |
| 248 |
" /* This software is Copyright: *\n" |
| 249 |
" * 2018, Testy McTestface <[email protected]> *\n" |
| 250 |
" * 2017, Boaty McBoatface <[email protected]> */" |
| 251 |
) |
| 252 |
holders = parse_holders(text) |
| 253 |
self.assertEqual( |
| 254 |
[(str(h.years), h.name, h.email) for h in holders], |
| 255 |
[ |
| 256 |
("2018", "Testy McTestface", "[email protected]"), |
| 257 |
("2017", "Boaty McBoatface", "[email protected]"), |
| 258 |
], |
| 259 |
) |
| 260 |
# Negative |
| 261 |
text = ( |
| 262 |
" /* This software is free software: *\n" |
| 263 |
" * 2018, Testy McTestface <[email protected]> *\n" |
| 264 |
" * 2017, Boaty McBoatface <[email protected]> */" |
| 265 |
) |
| 266 |
holders = parse_holders(text) |
| 267 |
self.assertEqual([(str(h.years), h.name, h.email) for h in holders], []) |
| 268 |
|
| 269 |
def test_parse_holders_multiline_years(self): |
| 270 |
# Positive |
| 271 |
text = ( |
| 272 |
" /* The software and docs is Copyright 1984, 1985, 1986 *\n" |
| 273 |
" * 1987 Testy McTestface <[email protected]> *\n" |
| 274 |
" * 1988 Boaty McBoatface <[email protected]> */" |
| 275 |
) |
| 276 |
holders = parse_holders(text) |
| 277 |
self.assertEqual( |
| 278 |
[(str(h.years), h.name, h.email) for h in holders], |
| 279 |
[ |
| 280 |
("1984-1987", "Testy McTestface", "[email protected]"), |
| 281 |
("1988", "Boaty McBoatface", "[email protected]"), |
| 282 |
], |
| 283 |
) |
| 284 |
|
| 285 |
# Negative |
| 286 |
text = ( |
| 287 |
" /* The software and docs is Copyright 1984, 1985, 1986 *\n" |
| 288 |
" * *\n" |
| 289 |
" * 1987 Testy McTestface <[email protected]> *\n" |
| 290 |
" * 1988 Boaty McBoatface <[email protected]> */" |
| 291 |
) |
| 292 |
holders = parse_holders(text) |
| 293 |
self.assertEqual( |
| 294 |
[(str(h.years), h.name, h.email) for h in holders], |
| 295 |
[ |
| 296 |
("1987", "Testy McTestface", "[email protected]"), |
| 297 |
("1988", "Boaty McBoatface", "[email protected]"), |
| 298 |
], |
| 299 |
) |
| 300 |
|
| 301 |
def _check_license_match(self, license_, matcher, expected, ignore=None): |
| 302 |
for key in ("licenseText", "standardLicenseHeader", "licenseExceptionText"): |
| 303 |
if key not in license_ or not license_[key]: |
| 304 |
continue |
| 305 |
if ignore and key in ignore: |
| 306 |
continue |
| 307 |
text = license_[key] |
| 308 |
result = matcher(text) |
| 309 |
self.assertEqual(result, expected, msg=f"with key={key}") |
| 310 |
|
| 311 |
def _check_license_match_re(self, license_, matcher, expected): |
| 312 |
for key in ("licenseText", "standardLicenseHeader", "licenseExceptionText"): |
| 313 |
if key not in license_ or not license_[key]: |
| 314 |
continue |
| 315 |
text = license_[key] |
| 316 |
result = matcher(text) |
| 317 |
matches = rex.match(expected, result) |
| 318 |
self.assertTrue( |
| 319 |
matches, |
| 320 |
msg=f"with key={key}, result ({result}) doesn't match with " |
| 321 |
f"the expected value ({expected})\n{text}", |
| 322 |
) |
| 323 |
|
| 324 |
@staticmethod |
| 325 |
def _find_licenses_matcher(text): |
| 326 |
found = licenses.find_licenses(licenses.clean_comments(text)) |
| 327 |
return " or ".join(sorted(found)) |
| 328 |
|
| 329 |
def _open_license_and_check(self, filename, matcher, expected, ignore=None): |
| 330 |
with (Path("tests/testdata/licenses") / filename).open() as fp: |
| 331 |
license_ = json.load(fp) |
| 332 |
return self._check_license_match(license_, matcher, expected, ignore) |
| 333 |
|
| 334 |
def _open_exception_and_check(self, filename, matcher, expected, ignore=None): |
| 335 |
with (Path("tests/testdata/exceptions") / filename).open() as fp: |
| 336 |
license_ = json.load(fp) |
| 337 |
return self._check_license_match(license_, matcher, expected, ignore) |
| 338 |
|
| 339 |
def _open_license_and_check_re(self, filename, matcher, expected): |
| 340 |
with (Path("tests/testdata/licenses") / filename).open() as fp: |
| 341 |
license_ = json.load(fp) |
| 342 |
return self._check_license_match_re(license_, matcher, expected) |
| 343 |
|
| 344 |
def test_spdx_a(self): |
| 345 |
"""find_licenses() on every reviewed section-A licence (coverage table).""" |
| 346 |
self._open_license_and_check( |
| 347 |
"AAL.json", |
| 348 |
self._find_licenses_matcher, |
| 349 |
"AAL", |
| 350 |
) |
| 351 |
self._open_license_and_check( |
| 352 |
"ADSL.json", |
| 353 |
self._find_licenses_matcher, |
| 354 |
"ADSL", |
| 355 |
) |
| 356 |
self._open_license_and_check( |
| 357 |
"AFL-1.1.json", |
| 358 |
self._find_licenses_matcher, |
| 359 |
"Academic-1.1", |
| 360 |
) |
| 361 |
self._open_license_and_check( |
| 362 |
"AFL-1.2.json", |
| 363 |
self._find_licenses_matcher, |
| 364 |
"Academic-1.2", |
| 365 |
) |
| 366 |
self._open_license_and_check( |
| 367 |
"AFL-2.0.json", |
| 368 |
self._find_licenses_matcher, |
| 369 |
"Academic-2", |
| 370 |
) |
| 371 |
self._open_license_and_check( |
| 372 |
"AFL-2.1.json", |
| 373 |
self._find_licenses_matcher, |
| 374 |
"Academic-2.1", |
| 375 |
) |
| 376 |
self._open_license_and_check( |
| 377 |
"AFL-3.0.json", |
| 378 |
self._find_licenses_matcher, |
| 379 |
"Academic-3", |
| 380 |
) |
| 381 |
self._open_license_and_check( |
| 382 |
"AGPL-1.0-only.json", |
| 383 |
self._find_licenses_matcher, |
| 384 |
"AGPL-1", |
| 385 |
) |
| 386 |
self._open_license_and_check( |
| 387 |
"AGPL-1.0-or-later.json", |
| 388 |
self._find_licenses_matcher, |
| 389 |
"AGPL-1", |
| 390 |
) |
| 391 |
self._open_license_and_check( |
| 392 |
"AGPL-1.0.json", |
| 393 |
self._find_licenses_matcher, |
| 394 |
"AGPL-1", |
| 395 |
) |
| 396 |
self._open_license_and_check( |
| 397 |
"AGPL-3.0-only.json", |
| 398 |
self._find_licenses_matcher, |
| 399 |
"AGPL-3", |
| 400 |
ignore={"licenseText"}, |
| 401 |
) |
| 402 |
self._open_license_and_check( |
| 403 |
"AGPL-3.0-or-later.json", |
| 404 |
self._find_licenses_matcher, |
| 405 |
"AGPL-3+", |
| 406 |
) |
| 407 |
self._open_license_and_check( |
| 408 |
"AGPL-3.0.json", |
| 409 |
self._find_licenses_matcher, |
| 410 |
"AGPL-3", |
| 411 |
ignore={"licenseText"}, |
| 412 |
) |
| 413 |
self._open_license_and_check( |
| 414 |
"AMDPLPA.json", |
| 415 |
self._find_licenses_matcher, |
| 416 |
"AMDPLPA", |
| 417 |
) |
| 418 |
self._open_license_and_check( |
| 419 |
"AML.json", |
| 420 |
self._find_licenses_matcher, |
| 421 |
"AML", |
| 422 |
) |
| 423 |
self._open_license_and_check( |
| 424 |
"AMPAS.json", |
| 425 |
self._find_licenses_matcher, |
| 426 |
"BSD-2-clause-AMPAS", |
| 427 |
) |
| 428 |
self._open_license_and_check( |
| 429 |
"ANTLR-PD-fallback.json", |
| 430 |
self._find_licenses_matcher, |
| 431 |
"ANTLR-PD", |
| 432 |
) |
| 433 |
self._open_license_and_check( |
| 434 |
"ANTLR-PD.json", |
| 435 |
self._find_licenses_matcher, |
| 436 |
"ANTLR-PD", |
| 437 |
) |
| 438 |
self._open_license_and_check( |
| 439 |
"APAFML.json", |
| 440 |
self._find_licenses_matcher, |
| 441 |
"APAFML", |
| 442 |
) |
| 443 |
self._open_license_and_check( |
| 444 |
"APL-1.0.json", |
| 445 |
self._find_licenses_matcher, |
| 446 |
"APL-1", |
| 447 |
) |
| 448 |
self._open_license_and_check( |
| 449 |
"APSL-1.0.json", |
| 450 |
self._find_licenses_matcher, |
| 451 |
"APSL-1", |
| 452 |
) |
| 453 |
self._open_license_and_check( |
| 454 |
"APSL-1.1.json", |
| 455 |
self._find_licenses_matcher, |
| 456 |
"APSL-1.1", |
| 457 |
) |
| 458 |
self._open_license_and_check( |
| 459 |
"APSL-1.2.json", |
| 460 |
self._find_licenses_matcher, |
| 461 |
"APSL-1.2", |
| 462 |
) |
| 463 |
self._open_license_and_check( |
| 464 |
"APSL-2.0.json", |
| 465 |
self._find_licenses_matcher, |
| 466 |
"APSL-2", |
| 467 |
) |
| 468 |
self._open_license_and_check( |
| 469 |
"Abstyles.json", |
| 470 |
self._find_licenses_matcher, |
| 471 |
"Abstyles", |
| 472 |
) |
| 473 |
self._open_license_and_check( |
| 474 |
"Adobe-2006.json", |
| 475 |
self._find_licenses_matcher, |
| 476 |
"Adobe-2006", |
| 477 |
) |
| 478 |
self._open_license_and_check( |
| 479 |
"Adobe-Glyph.json", |
| 480 |
self._find_licenses_matcher, |
| 481 |
"Adobe-Glyph", |
| 482 |
) |
| 483 |
self._open_license_and_check( |
| 484 |
"Afmparse.json", |
| 485 |
self._find_licenses_matcher, |
| 486 |
"Afmparse", |
| 487 |
) |
| 488 |
self._open_license_and_check( |
| 489 |
"Aladdin.json", |
| 490 |
self._find_licenses_matcher, |
| 491 |
"Aladdin", |
| 492 |
) |
| 493 |
self._open_license_and_check( |
| 494 |
"Apache-1.0.json", |
| 495 |
self._find_licenses_matcher, |
| 496 |
"Apache-1", |
| 497 |
) |
| 498 |
self._open_license_and_check( |
| 499 |
"Apache-1.1.json", |
| 500 |
self._find_licenses_matcher, |
| 501 |
"Apache-1.1", |
| 502 |
) |
| 503 |
self._open_license_and_check( |
| 504 |
"Apache-2.0.json", |
| 505 |
self._find_licenses_matcher, |
| 506 |
"Apache-2", |
| 507 |
) |
| 508 |
self._open_license_and_check( |
| 509 |
"Artistic-1.0-Perl.json", |
| 510 |
self._find_licenses_matcher, |
| 511 |
"Artistic-1-Perl", |
| 512 |
) |
| 513 |
self._open_license_and_check( |
| 514 |
"Artistic-1.0-cl8.json", |
| 515 |
self._find_licenses_matcher, |
| 516 |
"Artistic-1-cl8", |
| 517 |
) |
| 518 |
self._open_license_and_check( |
| 519 |
"Artistic-1.0.json", |
| 520 |
self._find_licenses_matcher, |
| 521 |
"Artistic-1", |
| 522 |
) |
| 523 |
self._open_license_and_check( |
| 524 |
"Artistic-2.0.json", |
| 525 |
self._find_licenses_matcher, |
| 526 |
"Artistic-2", |
| 527 |
) |
| 528 |
self._open_license_and_check( |
| 529 |
"Artistic-dist.json", |
| 530 |
self._find_licenses_matcher, |
| 531 |
"Artistic-dist", |
| 532 |
) |
| 533 |
|
| 534 |
def test_spdx_b(self): |
| 535 |
"""find_licenses() on every reviewed section-B licence (coverage table).""" |
| 536 |
self._open_license_and_check( |
| 537 |
"BSD-1-Clause.json", |
| 538 |
self._find_licenses_matcher, |
| 539 |
"BSD-1-clause", |
| 540 |
) |
| 541 |
self._open_license_and_check( |
| 542 |
"BSD-2-Clause-Darwin.json", |
| 543 |
self._find_licenses_matcher, |
| 544 |
"BSD-2-clause-Darwin", |
| 545 |
) |
| 546 |
self._open_license_and_check( |
| 547 |
"BSD-2-Clause-FreeBSD.json", |
| 548 |
self._find_licenses_matcher, |
| 549 |
"BSD-2-clause-FreeBSD", |
| 550 |
) |
| 551 |
self._open_license_and_check( |
| 552 |
"BSD-2-Clause-NetBSD.json", |
| 553 |
self._find_licenses_matcher, |
| 554 |
"BSD-2-clause-NetBSD", |
| 555 |
) |
| 556 |
self._open_license_and_check( |
| 557 |
"BSD-2-Clause-Patent.json", |
| 558 |
self._find_licenses_matcher, |
| 559 |
"BSD-2-clause-patent", |
| 560 |
) |
| 561 |
self._open_license_and_check( |
| 562 |
"BSD-2-Clause-Views.json", |
| 563 |
self._find_licenses_matcher, |
| 564 |
"BSD-2-clause-views", |
| 565 |
) |
| 566 |
self._open_license_and_check( |
| 567 |
"BSD-2-Clause-first-lines.json", |
| 568 |
self._find_licenses_matcher, |
| 569 |
"BSD-2-clause-first-lines", |
| 570 |
) |
| 571 |
self._open_license_and_check( |
| 572 |
"BSD-2-Clause.json", |
| 573 |
self._find_licenses_matcher, |
| 574 |
"BSD-2-clause", |
| 575 |
) |
| 576 |
self._open_license_and_check( |
| 577 |
"BSD-3-Clause-Attribution.json", |
| 578 |
self._find_licenses_matcher, |
| 579 |
"BSD-3-clause-attribution", |
| 580 |
) |
| 581 |
self._open_license_and_check( |
| 582 |
"BSD-3-Clause-Clear.json", |
| 583 |
self._find_licenses_matcher, |
| 584 |
"BSD-3-clause-clear", |
| 585 |
) |
| 586 |
self._open_license_and_check( |
| 587 |
"BSD-3-Clause-HP.json", |
| 588 |
self._find_licenses_matcher, |
| 589 |
"BSD-3-clause-HP", |
| 590 |
) |
| 591 |
self._open_license_and_check( |
| 592 |
"BSD-3-Clause-LBNL.json", |
| 593 |
self._find_licenses_matcher, |
| 594 |
"BSD-3-clause-LBNL", |
| 595 |
) |
| 596 |
self._open_license_and_check( |
| 597 |
"BSD-3-Clause-No-Military-License.json", |
| 598 |
self._find_licenses_matcher, |
| 599 |
"BSD-3-clause-no-military", |
| 600 |
) |
| 601 |
self._open_license_and_check( |
| 602 |
"BSD-3-Clause-No-Nuclear-License-2014.json", |
| 603 |
self._find_licenses_matcher, |
| 604 |
"BSD-3-clause-no-nuclear", |
| 605 |
) |
| 606 |
self._open_license_and_check( |
| 607 |
"BSD-3-Clause-Open-MPI.json", |
| 608 |
self._find_licenses_matcher, |
| 609 |
"BSD-3-clause-Open-MPI", |
| 610 |
) |
| 611 |
self._open_license_and_check( |
| 612 |
"BSD-3-Clause-Tso.json", |
| 613 |
self._find_licenses_matcher, |
| 614 |
"BSD-3-clause-Tso", |
| 615 |
) |
| 616 |
self._open_license_and_check( |
| 617 |
"BSD-3-Clause-acpica.json", |
| 618 |
self._find_licenses_matcher, |
| 619 |
"BSD-3-clause-acpica", |
| 620 |
) |
| 621 |
self._open_license_and_check( |
| 622 |
"BSD-3-Clause-flex.json", |
| 623 |
self._find_licenses_matcher, |
| 624 |
"BSD-3-clause-flex", |
| 625 |
) |
| 626 |
self._open_license_and_check( |
| 627 |
"BSD-3-Clause.json", |
| 628 |
self._find_licenses_matcher, |
| 629 |
"BSD-3-clause", |
| 630 |
) |
| 631 |
self._open_license_and_check( |
| 632 |
"BSD-4-Clause-Shortened.json", |
| 633 |
self._find_licenses_matcher, |
| 634 |
"BSD-4-clause-shortened", |
| 635 |
) |
| 636 |
self._open_license_and_check( |
| 637 |
"BSD-4-Clause-UC.json", |
| 638 |
self._find_licenses_matcher, |
| 639 |
"BSD-4-clause-UC", |
| 640 |
) |
| 641 |
self._open_license_and_check( |
| 642 |
"BSD-4-Clause.json", |
| 643 |
self._find_licenses_matcher, |
| 644 |
"BSD-4-clause", |
| 645 |
) |
| 646 |
self._open_license_and_check( |
| 647 |
"BSD-Attribution-HPND-disclaimer.json", |
| 648 |
self._find_licenses_matcher, |
| 649 |
"BSD-Attribution-HPND-disclaimer", |
| 650 |
) |
| 651 |
self._open_license_and_check( |
| 652 |
"BSD-Inferno-Nettverk.json", |
| 653 |
self._find_licenses_matcher, |
| 654 |
"BSD-Inferno-Nettverk", |
| 655 |
) |
| 656 |
self._open_license_and_check( |
| 657 |
"BSD-Mark-Modifications.json", |
| 658 |
self._find_licenses_matcher, |
| 659 |
"BSD-Mark-Modifications", |
| 660 |
) |
| 661 |
self._open_license_and_check( |
| 662 |
"BSD-Protection.json", |
| 663 |
self._find_licenses_matcher, |
| 664 |
"BSD-protection", |
| 665 |
) |
| 666 |
self._open_license_and_check( |
| 667 |
"BSD-Source-Code.json", |
| 668 |
self._find_licenses_matcher, |
| 669 |
"BSD-source-code", |
| 670 |
) |
| 671 |
self._open_license_and_check( |
| 672 |
"BSD-Source-beginning-file.json", |
| 673 |
self._find_licenses_matcher, |
| 674 |
"BSD-source-beginning-file", |
| 675 |
) |
| 676 |
self._open_license_and_check( |
| 677 |
"BSD-Systemics-W3Works.json", |
| 678 |
self._find_licenses_matcher, |
| 679 |
"BSD-Systemics", |
| 680 |
) |
| 681 |
self._open_license_and_check( |
| 682 |
"BSD-Systemics.json", |
| 683 |
self._find_licenses_matcher, |
| 684 |
"BSD-Systemics", |
| 685 |
) |
| 686 |
self._open_license_and_check( |
| 687 |
"BSL-1.0.json", |
| 688 |
self._find_licenses_matcher, |
| 689 |
"BSL-1", |
| 690 |
) |
| 691 |
self._open_license_and_check( |
| 692 |
"Bahyph.json", |
| 693 |
self._find_licenses_matcher, |
| 694 |
"Bahyph", |
| 695 |
) |
| 696 |
self._open_license_and_check( |
| 697 |
"Barr.json", |
| 698 |
self._find_licenses_matcher, |
| 699 |
"Barr", |
| 700 |
) |
| 701 |
self._open_license_and_check( |
| 702 |
"Beerware.json", |
| 703 |
self._find_licenses_matcher, |
| 704 |
"Beerware", |
| 705 |
) |
| 706 |
self._open_license_and_check( |
| 707 |
"BitTorrent-1.0.json", |
| 708 |
self._find_licenses_matcher, |
| 709 |
"BitTorrent-1", |
| 710 |
) |
| 711 |
self._open_license_and_check( |
| 712 |
"BitTorrent-1.1.json", |
| 713 |
self._find_licenses_matcher, |
| 714 |
"BitTorrent-1.1", |
| 715 |
ignore={"licenseText"}, |
| 716 |
) |
| 717 |
self._open_license_and_check( |
| 718 |
"Borceux.json", |
| 719 |
self._find_licenses_matcher, |
| 720 |
"Borceux", |
| 721 |
) |
| 722 |
|
| 723 |
def test_spdx_c(self): |
| 724 |
"""find_licenses() on every reviewed section-C licence (coverage table).""" |
| 725 |
self._open_license_and_check( |
| 726 |
"CAL-1.0-Combined-Work-Exception.json", |
| 727 |
self._find_licenses_matcher, |
| 728 |
"CAL-1", |
| 729 |
) |
| 730 |
self._open_license_and_check( |
| 731 |
"CAL-1.0.json", |
| 732 |
self._find_licenses_matcher, |
| 733 |
"CAL-1", |
| 734 |
) |
| 735 |
self._open_license_and_check( |
| 736 |
"CATOSL-1.1.json", |
| 737 |
self._find_licenses_matcher, |
| 738 |
"CATOSL-1.1", |
| 739 |
) |
| 740 |
self._open_license_and_check( |
| 741 |
"CC-BY-2.0.json", |
| 742 |
self._find_licenses_matcher, |
| 743 |
"CC-BY-2", |
| 744 |
) |
| 745 |
self._open_license_and_check( |
| 746 |
"CC-BY-2.5.json", |
| 747 |
self._find_licenses_matcher, |
| 748 |
"CC-BY-2.5", |
| 749 |
) |
| 750 |
self._open_license_and_check( |
| 751 |
"CC-BY-3.0-US.json", |
| 752 |
self._find_licenses_matcher, |
| 753 |
"CC-BY-3-US", |
| 754 |
) |
| 755 |
self._open_license_and_check( |
| 756 |
"CC-BY-3.0.json", |
| 757 |
self._find_licenses_matcher, |
| 758 |
"CC-BY-3", |
| 759 |
) |
| 760 |
self._open_license_and_check( |
| 761 |
"CC-BY-NC-2.0.json", |
| 762 |
self._find_licenses_matcher, |
| 763 |
"CC-BY-NC-2", |
| 764 |
) |
| 765 |
self._open_license_and_check( |
| 766 |
"CC-BY-NC-2.5.json", |
| 767 |
self._find_licenses_matcher, |
| 768 |
"CC-BY-NC-2.5", |
| 769 |
) |
| 770 |
self._open_license_and_check( |
| 771 |
"CC-BY-NC-3.0.json", |
| 772 |
self._find_licenses_matcher, |
| 773 |
"CC-BY-NC-3", |
| 774 |
) |
| 775 |
self._open_license_and_check( |
| 776 |
"CC-BY-NC-ND-2.0.json", |
| 777 |
self._find_licenses_matcher, |
| 778 |
"CC-BY-NC-ND-2", |
| 779 |
) |
| 780 |
self._open_license_and_check( |
| 781 |
"CC-BY-NC-ND-2.5.json", |
| 782 |
self._find_licenses_matcher, |
| 783 |
"CC-BY-NC-ND-2.5", |
| 784 |
) |
| 785 |
self._open_license_and_check( |
| 786 |
"CC-BY-NC-ND-3.0.json", |
| 787 |
self._find_licenses_matcher, |
| 788 |
"CC-BY-NC-ND-3", |
| 789 |
) |
| 790 |
self._open_license_and_check( |
| 791 |
"CC-BY-NC-SA-2.0.json", |
| 792 |
self._find_licenses_matcher, |
| 793 |
"CC-BY-NC-SA-2", |
| 794 |
) |
| 795 |
self._open_license_and_check( |
| 796 |
"CC-BY-NC-SA-2.5.json", |
| 797 |
self._find_licenses_matcher, |
| 798 |
"CC-BY-NC-SA-2.5", |
| 799 |
) |
| 800 |
self._open_license_and_check( |
| 801 |
"CC-BY-NC-SA-3.0.json", |
| 802 |
self._find_licenses_matcher, |
| 803 |
"CC-BY-NC-SA-3", |
| 804 |
) |
| 805 |
self._open_license_and_check( |
| 806 |
"CC-BY-ND-2.0.json", |
| 807 |
self._find_licenses_matcher, |
| 808 |
"CC-BY-ND-2", |
| 809 |
) |
| 810 |
self._open_license_and_check( |
| 811 |
"CC-BY-ND-2.5.json", |
| 812 |
self._find_licenses_matcher, |
| 813 |
"CC-BY-ND-2.5", |
| 814 |
) |
| 815 |
self._open_license_and_check( |
| 816 |
"CC-BY-ND-3.0.json", |
| 817 |
self._find_licenses_matcher, |
| 818 |
"CC-BY-ND-3", |
| 819 |
) |
| 820 |
self._open_license_and_check( |
| 821 |
"CC-BY-SA-2.0.json", |
| 822 |
self._find_licenses_matcher, |
| 823 |
"CC-BY-SA-2", |
| 824 |
) |
| 825 |
self._open_license_and_check( |
| 826 |
"CC-BY-SA-2.5.json", |
| 827 |
self._find_licenses_matcher, |
| 828 |
"CC-BY-SA-2.5", |
| 829 |
) |
| 830 |
self._open_license_and_check( |
| 831 |
"CC-BY-SA-3.0.json", |
| 832 |
self._find_licenses_matcher, |
| 833 |
"CC-BY-SA-3", |
| 834 |
) |
| 835 |
self._open_license_and_check( |
| 836 |
"CC0-1.0.json", |
| 837 |
self._find_licenses_matcher, |
| 838 |
"CC0", |
| 839 |
) |
| 840 |
self._open_license_and_check( |
| 841 |
"CDDL-1.0.json", |
| 842 |
self._find_licenses_matcher, |
| 843 |
"CDDL-1", |
| 844 |
) |
| 845 |
self._open_license_and_check( |
| 846 |
"CDDL-1.1.json", |
| 847 |
self._find_licenses_matcher, |
| 848 |
"CDDL-1.1", |
| 849 |
) |
| 850 |
self._open_license_and_check( |
| 851 |
"CECILL-1.0.json", |
| 852 |
self._find_licenses_matcher, |
| 853 |
"CeCILL-1", |
| 854 |
) |
| 855 |
self._open_license_and_check( |
| 856 |
"CECILL-1.1.json", |
| 857 |
self._find_licenses_matcher, |
| 858 |
"CeCILL-1.1", |
| 859 |
) |
| 860 |
self._open_license_and_check( |
| 861 |
"CECILL-2.0.json", |
| 862 |
self._find_licenses_matcher, |
| 863 |
"CeCILL-2", |
| 864 |
) |
| 865 |
self._open_license_and_check( |
| 866 |
"CECILL-2.1.json", |
| 867 |
self._find_licenses_matcher, |
| 868 |
"CeCILL-2.1", |
| 869 |
) |
| 870 |
self._open_license_and_check( |
| 871 |
"CECILL-B.json", |
| 872 |
self._find_licenses_matcher, |
| 873 |
"CeCILL-B", |
| 874 |
) |
| 875 |
self._open_license_and_check( |
| 876 |
"CECILL-C.json", |
| 877 |
self._find_licenses_matcher, |
| 878 |
"CeCILL-C", |
| 879 |
) |
| 880 |
self._open_license_and_check( |
| 881 |
"CNRI-Jython.json", |
| 882 |
self._find_licenses_matcher, |
| 883 |
"CNRI-Jython", |
| 884 |
) |
| 885 |
self._open_license_and_check( |
| 886 |
"CNRI-Python-GPL-Compatible.json", |
| 887 |
self._find_licenses_matcher, |
| 888 |
"CNRI-Python-GPL-Compatible", |
| 889 |
) |
| 890 |
self._open_license_and_check( |
| 891 |
"CNRI-Python.json", |
| 892 |
self._find_licenses_matcher, |
| 893 |
"CNRI-Python", |
| 894 |
) |
| 895 |
self._open_license_and_check( |
| 896 |
"CPAL-1.0.json", |
| 897 |
self._find_licenses_matcher, |
| 898 |
"CPAL-1", |
| 899 |
) |
| 900 |
self._open_license_and_check( |
| 901 |
"CPL-1.0.json", |
| 902 |
self._find_licenses_matcher, |
| 903 |
"CPL-1", |
| 904 |
) |
| 905 |
self._open_license_and_check( |
| 906 |
"CPOL-1.02.json", |
| 907 |
self._find_licenses_matcher, |
| 908 |
"CPOL-1.02", |
| 909 |
) |
| 910 |
self._open_license_and_check( |
| 911 |
"CUA-OPL-1.0.json", |
| 912 |
self._find_licenses_matcher, |
| 913 |
"CUA-OPL-1", |
| 914 |
) |
| 915 |
self._open_license_and_check( |
| 916 |
"Caldera.json", |
| 917 |
self._find_licenses_matcher, |
| 918 |
"Caldera", |
| 919 |
) |
| 920 |
self._open_license_and_check( |
| 921 |
"ClArtistic.json", |
| 922 |
self._find_licenses_matcher, |
| 923 |
"ClArtistic", |
| 924 |
) |
| 925 |
self._open_license_and_check( |
| 926 |
"Clips.json", |
| 927 |
self._find_licenses_matcher, |
| 928 |
"MIT-like-clips", |
| 929 |
) |
| 930 |
self._open_license_and_check( |
| 931 |
"Community-Spec-1.0.json", |
| 932 |
self._find_licenses_matcher, |
| 933 |
# Self-published under CC-BY-4.0, so the CC-BY matcher and the |
| 934 |
# embedded SPDX tag both fire CC-BY-4; find_licenses dedups it. |
| 935 |
"CC-BY-4 or Community-Spec-1", |
| 936 |
) |
| 937 |
self._open_license_and_check( |
| 938 |
"Condor-1.1.json", |
| 939 |
self._find_licenses_matcher, |
| 940 |
"Condor-1.1", |
| 941 |
) |
| 942 |
self._open_license_and_check( |
| 943 |
"Crossword.json", |
| 944 |
self._find_licenses_matcher, |
| 945 |
"Crossword", |
| 946 |
) |
| 947 |
self._open_license_and_check( |
| 948 |
"CrystalStacker.json", |
| 949 |
self._find_licenses_matcher, |
| 950 |
"CrystalStacker", |
| 951 |
) |
| 952 |
self._open_license_and_check( |
| 953 |
"Cube.json", |
| 954 |
self._find_licenses_matcher, |
| 955 |
"Cube", |
| 956 |
) |
| 957 |
|
| 958 |
def test_spdx_d(self): |
| 959 |
"""find_licenses() on every reviewed section-D licence (coverage table).""" |
| 960 |
self._open_license_and_check( |
| 961 |
"D-FSL-1.0.json", |
| 962 |
self._find_licenses_matcher, |
| 963 |
"D-FSL", |
| 964 |
) |
| 965 |
self._open_license_and_check( |
| 966 |
"DOC.json", |
| 967 |
self._find_licenses_matcher, |
| 968 |
"DOC", |
| 969 |
) |
| 970 |
self._open_license_and_check( |
| 971 |
"DSDP.json", |
| 972 |
self._find_licenses_matcher, |
| 973 |
"DSDP", |
| 974 |
) |
| 975 |
self._open_license_and_check( |
| 976 |
"DocBook-Stylesheet.json", |
| 977 |
self._find_licenses_matcher, |
| 978 |
"MIT-like-Docbook-Stylesheet", |
| 979 |
) |
| 980 |
self._open_license_and_check( |
| 981 |
"Dotseqn.json", |
| 982 |
self._find_licenses_matcher, |
| 983 |
"Dotseqn", |
| 984 |
) |
| 985 |
|
| 986 |
def test_spdx_f(self): |
| 987 |
"""find_licenses() on every reviewed section-F licence (coverage table).""" |
| 988 |
self._open_license_and_check( |
| 989 |
"FSFAP-no-warranty-disclaimer.json", |
| 990 |
self._find_licenses_matcher, |
| 991 |
"FSFAP-no-warranty-disclaimer", |
| 992 |
) |
| 993 |
self._open_license_and_check( |
| 994 |
"FSFAP.json", |
| 995 |
self._find_licenses_matcher, |
| 996 |
"FSFAP", |
| 997 |
) |
| 998 |
self._open_license_and_check( |
| 999 |
"FSFUL.json", |
| 1000 |
self._find_licenses_matcher, |
| 1001 |
"FSFUL", |
| 1002 |
) |
| 1003 |
self._open_license_and_check( |
| 1004 |
"FSFULLR.json", |
| 1005 |
self._find_licenses_matcher, |
| 1006 |
"FSFULLR", |
| 1007 |
) |
| 1008 |
self._open_license_and_check( |
| 1009 |
"FSFULLRSD.json", |
| 1010 |
self._find_licenses_matcher, |
| 1011 |
"FSFULLR", |
| 1012 |
) |
| 1013 |
self._open_license_and_check( |
| 1014 |
"FSFULLRWD.json", |
| 1015 |
self._find_licenses_matcher, |
| 1016 |
"FSFULLR", |
| 1017 |
) |
| 1018 |
self._open_license_and_check( |
| 1019 |
"FSL-1.1-ALv2.json", |
| 1020 |
self._find_licenses_matcher, |
| 1021 |
"Apache-2 or FSL-1.1-ALv2", |
| 1022 |
) |
| 1023 |
self._open_license_and_check( |
| 1024 |
"FSL-1.1-MIT.json", |
| 1025 |
self._find_licenses_matcher, |
| 1026 |
"Expat or FSL-1.1-MIT", |
| 1027 |
) |
| 1028 |
self._open_license_and_check( |
| 1029 |
"FTL.json", |
| 1030 |
self._find_licenses_matcher, |
| 1031 |
"FTL", |
| 1032 |
) |
| 1033 |
self._open_license_and_check( |
| 1034 |
"Fair.json", |
| 1035 |
self._find_licenses_matcher, |
| 1036 |
"Fair", |
| 1037 |
) |
| 1038 |
self._open_license_and_check( |
| 1039 |
"Frameworx-1.0.json", |
| 1040 |
self._find_licenses_matcher, |
| 1041 |
"Frameworx-1", |
| 1042 |
) |
| 1043 |
self._open_license_and_check( |
| 1044 |
"FreeImage.json", |
| 1045 |
self._find_licenses_matcher, |
| 1046 |
"FreeImage-1", |
| 1047 |
) |
| 1048 |
|
| 1049 |
def test_spdx_g(self): |
| 1050 |
"""find_licenses() on every reviewed section-G licence (coverage table).""" |
| 1051 |
self._open_license_and_check( |
| 1052 |
"GFDL-1.1-invariants-only.json", |
| 1053 |
self._find_licenses_matcher, |
| 1054 |
"GFDL-1.1", |
| 1055 |
ignore={"licenseText"}, |
| 1056 |
) |
| 1057 |
self._open_license_and_check( |
| 1058 |
"GFDL-1.1-invariants-or-later.json", |
| 1059 |
self._find_licenses_matcher, |
| 1060 |
"GFDL-1.1+", |
| 1061 |
ignore={"licenseText"}, |
| 1062 |
) |
| 1063 |
self._open_license_and_check( |
| 1064 |
"GFDL-1.1-no-invariants-only.json", |
| 1065 |
self._find_licenses_matcher, |
| 1066 |
"GFDL-NIV-1.1", |
| 1067 |
ignore={"licenseText"}, |
| 1068 |
) |
| 1069 |
self._open_license_and_check( |
| 1070 |
"GFDL-1.1-no-invariants-or-later.json", |
| 1071 |
self._find_licenses_matcher, |
| 1072 |
"GFDL-NIV-1.1+", |
| 1073 |
ignore={"licenseText"}, |
| 1074 |
) |
| 1075 |
self._open_license_and_check( |
| 1076 |
"GFDL-1.1-only.json", |
| 1077 |
self._find_licenses_matcher, |
| 1078 |
"GFDL-1.1", |
| 1079 |
ignore={"licenseText"}, |
| 1080 |
) |
| 1081 |
self._open_license_and_check( |
| 1082 |
"GFDL-1.1-or-later.json", |
| 1083 |
self._find_licenses_matcher, |
| 1084 |
"GFDL-1.1+", |
| 1085 |
ignore={"licenseText"}, |
| 1086 |
) |
| 1087 |
self._open_license_and_check( |
| 1088 |
"GFDL-1.1.json", |
| 1089 |
self._find_licenses_matcher, |
| 1090 |
"GFDL-1.1+", |
| 1091 |
ignore={"licenseText"}, |
| 1092 |
) |
| 1093 |
self._open_license_and_check( |
| 1094 |
"GFDL-1.2-invariants-only.json", |
| 1095 |
self._find_licenses_matcher, |
| 1096 |
"GFDL-1.2", |
| 1097 |
ignore={"licenseText"}, |
| 1098 |
) |
| 1099 |
self._open_license_and_check( |
| 1100 |
"GFDL-1.2-invariants-or-later.json", |
| 1101 |
self._find_licenses_matcher, |
| 1102 |
"GFDL-1.2+", |
| 1103 |
ignore={"licenseText"}, |
| 1104 |
) |
| 1105 |
self._open_license_and_check( |
| 1106 |
"GFDL-1.2-no-invariants-only.json", |
| 1107 |
self._find_licenses_matcher, |
| 1108 |
"GFDL-NIV-1.2", |
| 1109 |
ignore={"licenseText"}, |
| 1110 |
) |
| 1111 |
self._open_license_and_check( |
| 1112 |
"GFDL-1.2-no-invariants-or-later.json", |
| 1113 |
self._find_licenses_matcher, |
| 1114 |
"GFDL-NIV-1.2+", |
| 1115 |
ignore={"licenseText"}, |
| 1116 |
) |
| 1117 |
self._open_license_and_check( |
| 1118 |
"GFDL-1.2-only.json", |
| 1119 |
self._find_licenses_matcher, |
| 1120 |
"GFDL-1.2", |
| 1121 |
ignore={"licenseText"}, |
| 1122 |
) |
| 1123 |
self._open_license_and_check( |
| 1124 |
"GFDL-1.2-or-later.json", |
| 1125 |
self._find_licenses_matcher, |
| 1126 |
"GFDL-1.2+", |
| 1127 |
ignore={"licenseText"}, |
| 1128 |
) |
| 1129 |
self._open_license_and_check( |
| 1130 |
"GFDL-1.2.json", |
| 1131 |
self._find_licenses_matcher, |
| 1132 |
"GFDL-NIV-1.2+", |
| 1133 |
ignore={"licenseText"}, |
| 1134 |
) |
| 1135 |
self._open_license_and_check( |
| 1136 |
"GFDL-1.3-invariants-only.json", |
| 1137 |
self._find_licenses_matcher, |
| 1138 |
"GFDL-1.3", |
| 1139 |
ignore={"licenseText"}, |
| 1140 |
) |
| 1141 |
self._open_license_and_check( |
| 1142 |
"GFDL-1.3-invariants-or-later.json", |
| 1143 |
self._find_licenses_matcher, |
| 1144 |
"GFDL-1.3+", |
| 1145 |
ignore={"licenseText"}, |
| 1146 |
) |
| 1147 |
self._open_license_and_check( |
| 1148 |
"GFDL-1.3-no-invariants-only.json", |
| 1149 |
self._find_licenses_matcher, |
| 1150 |
"GFDL-NIV-1.3", |
| 1151 |
ignore={"licenseText"}, |
| 1152 |
) |
| 1153 |
self._open_license_and_check( |
| 1154 |
"GFDL-1.3-no-invariants-or-later.json", |
| 1155 |
self._find_licenses_matcher, |
| 1156 |
"GFDL-NIV-1.3+", |
| 1157 |
ignore={"licenseText"}, |
| 1158 |
) |
| 1159 |
self._open_license_and_check( |
| 1160 |
"GFDL-1.3-only.json", |
| 1161 |
self._find_licenses_matcher, |
| 1162 |
"GFDL-1.3", |
| 1163 |
ignore={"licenseText"}, |
| 1164 |
) |
| 1165 |
self._open_license_and_check( |
| 1166 |
"GFDL-1.3-or-later.json", |
| 1167 |
self._find_licenses_matcher, |
| 1168 |
"GFDL-1.3+", |
| 1169 |
ignore={"licenseText"}, |
| 1170 |
) |
| 1171 |
self._open_license_and_check( |
| 1172 |
"GFDL-1.3.json", |
| 1173 |
self._find_licenses_matcher, |
| 1174 |
"GFDL-NIV-1.3+", |
| 1175 |
ignore={"licenseText"}, |
| 1176 |
) |
| 1177 |
self._open_license_and_check( |
| 1178 |
"GPL-1.0+.json", |
| 1179 |
self._find_licenses_matcher, |
| 1180 |
"GPL-1+", |
| 1181 |
) |
| 1182 |
self._open_license_and_check( |
| 1183 |
"GPL-1.0-only.json", |
| 1184 |
self._find_licenses_matcher, |
| 1185 |
"GPL-1", |
| 1186 |
ignore={"licenseText"}, |
| 1187 |
) |
| 1188 |
self._open_license_and_check( |
| 1189 |
"GPL-1.0-or-later.json", |
| 1190 |
self._find_licenses_matcher, |
| 1191 |
"GPL-1+", |
| 1192 |
) |
| 1193 |
self._open_license_and_check( |
| 1194 |
"GPL-1.0.json", |
| 1195 |
self._find_licenses_matcher, |
| 1196 |
"GPL-1+", |
| 1197 |
ignore={"standardLicenseHeader"}, |
| 1198 |
) |
| 1199 |
self._open_license_and_check( |
| 1200 |
"GPL-2.0+.json", |
| 1201 |
self._find_licenses_matcher, |
| 1202 |
"GPL-2+", |
| 1203 |
) |
| 1204 |
self._open_license_and_check( |
| 1205 |
"GPL-2.0-only.json", |
| 1206 |
self._find_licenses_matcher, |
| 1207 |
"GPL-2", |
| 1208 |
ignore={"licenseText"}, |
| 1209 |
) |
| 1210 |
self._open_license_and_check( |
| 1211 |
"GPL-2.0-or-later.json", |
| 1212 |
self._find_licenses_matcher, |
| 1213 |
"GPL-2+", |
| 1214 |
) |
| 1215 |
self._open_license_and_check( |
| 1216 |
"GPL-2.0.json", |
| 1217 |
self._find_licenses_matcher, |
| 1218 |
"GPL-2+", |
| 1219 |
ignore={"standardLicenseHeader"}, |
| 1220 |
) |
| 1221 |
self._open_license_and_check( |
| 1222 |
"GPL-3.0+.json", |
| 1223 |
self._find_licenses_matcher, |
| 1224 |
"GPL-3+", |
| 1225 |
) |
| 1226 |
self._open_license_and_check( |
| 1227 |
"GPL-3.0-only.json", |
| 1228 |
self._find_licenses_matcher, |
| 1229 |
"GPL-3", |
| 1230 |
ignore={"licenseText"}, |
| 1231 |
) |
| 1232 |
self._open_license_and_check( |
| 1233 |
"GPL-3.0-or-later.json", |
| 1234 |
self._find_licenses_matcher, |
| 1235 |
"GPL-3+", |
| 1236 |
) |
| 1237 |
self._open_license_and_check( |
| 1238 |
"GPL-3.0.json", |
| 1239 |
self._find_licenses_matcher, |
| 1240 |
"GPL-3+", |
| 1241 |
ignore={"standardLicenseHeader"}, |
| 1242 |
) |
| 1243 |
|
| 1244 |
def test_spdx_h(self): |
| 1245 |
"""find_licenses() on every reviewed section-H licence (coverage table).""" |
| 1246 |
self._open_license_and_check( |
| 1247 |
"HPND-DEC.json", |
| 1248 |
self._find_licenses_matcher, |
| 1249 |
"MIT-like-HPND-DEC", |
| 1250 |
) |
| 1251 |
self._open_license_and_check( |
| 1252 |
"HPND-Fenneberg-Livingston.json", |
| 1253 |
self._find_licenses_matcher, |
| 1254 |
"MIT-like-HPND-Fenneberg-Livingston", |
| 1255 |
) |
| 1256 |
self._open_license_and_check( |
| 1257 |
"HPND-MIT-disclaimer.json", |
| 1258 |
self._find_licenses_matcher, |
| 1259 |
"MIT-like-HPND-MIT-disclaimer", |
| 1260 |
) |
| 1261 |
self._open_license_and_check( |
| 1262 |
"HPND-Markus-Kuhn.json", |
| 1263 |
self._find_licenses_matcher, |
| 1264 |
"MIT-like-HPND-Markus-Kuhn", |
| 1265 |
) |
| 1266 |
self._open_license_and_check( |
| 1267 |
"HPND-Netrek.json", |
| 1268 |
self._find_licenses_matcher, |
| 1269 |
"MIT-like-HPND-Netrek", |
| 1270 |
) |
| 1271 |
self._open_license_and_check( |
| 1272 |
"HPND-Pbmplus.json", |
| 1273 |
self._find_licenses_matcher, |
| 1274 |
"MIT-like-HPND-Pbmplus", |
| 1275 |
) |
| 1276 |
self._open_license_and_check( |
| 1277 |
"HPND-UC-export-US.json", |
| 1278 |
self._find_licenses_matcher, |
| 1279 |
"MIT-like-HPND-UC-export-US", |
| 1280 |
) |
| 1281 |
self._open_license_and_check( |
| 1282 |
"HPND-UC.json", |
| 1283 |
self._find_licenses_matcher, |
| 1284 |
"MIT-like-HPND-UC", |
| 1285 |
) |
| 1286 |
self._open_license_and_check( |
| 1287 |
"HPND-doc.json", |
| 1288 |
self._find_licenses_matcher, |
| 1289 |
"MIT-like-HPND-doc", |
| 1290 |
) |
| 1291 |
self._open_license_and_check( |
| 1292 |
"HPND-export-US-modify.json", |
| 1293 |
self._find_licenses_matcher, |
| 1294 |
"MIT-like-HPND-export-US-modify", |
| 1295 |
) |
| 1296 |
self._open_license_and_check( |
| 1297 |
"HPND-export-US.json", |
| 1298 |
self._find_licenses_matcher, |
| 1299 |
"MIT-like-HPND-export-US", |
| 1300 |
) |
| 1301 |
self._open_license_and_check( |
| 1302 |
"HPND-export2-US.json", |
| 1303 |
self._find_licenses_matcher, |
| 1304 |
"MIT-like-HPND-export2-US", |
| 1305 |
) |
| 1306 |
self._open_license_and_check( |
| 1307 |
"HPND-sell-variant-MIT-disclaimer-rev.json", |
| 1308 |
self._find_licenses_matcher, |
| 1309 |
"MIT-like-HPND-sell-variant-MIT-disclaimer-rev", |
| 1310 |
) |
| 1311 |
self._open_license_and_check( |
| 1312 |
"HPND-sell-variant-MIT-disclaimer.json", |
| 1313 |
self._find_licenses_matcher, |
| 1314 |
"MIT-like-HPND-sell-variant-MIT-disclaimer", |
| 1315 |
) |
| 1316 |
self._open_license_and_check( |
| 1317 |
"HPND-sell-variant-critical-systems.json", |
| 1318 |
self._find_licenses_matcher, |
| 1319 |
"MIT-like-HPND-sell-variant-critical-systems", |
| 1320 |
) |
| 1321 |
self._open_license_and_check( |
| 1322 |
"HPND.json", |
| 1323 |
self._find_licenses_matcher, |
| 1324 |
"MIT-like-HPND", |
| 1325 |
) |
| 1326 |
self._open_license_and_check( |
| 1327 |
"HaskellReport.json", |
| 1328 |
self._find_licenses_matcher, |
| 1329 |
"HaskellReport", |
| 1330 |
) |
| 1331 |
|
| 1332 |
def test_spdx_m(self): |
| 1333 |
"""find_licenses() on the section-M licences fixed in review.""" |
| 1334 |
self._open_license_and_check( |
| 1335 |
"MIT-0.json", |
| 1336 |
self._find_licenses_matcher, |
| 1337 |
"MIT-0", |
| 1338 |
) |
| 1339 |
self._open_license_and_check( |
| 1340 |
"MIT-Click.json", |
| 1341 |
self._find_licenses_matcher, |
| 1342 |
"MIT-Click", |
| 1343 |
) |
| 1344 |
self._open_license_and_check( |
| 1345 |
"MIT-Khronos-old.json", |
| 1346 |
self._find_licenses_matcher, |
| 1347 |
"MIT-Khronos-old", |
| 1348 |
) |
| 1349 |
self._open_license_and_check( |
| 1350 |
"MIT-Modern-Variant.json", |
| 1351 |
self._find_licenses_matcher, |
| 1352 |
"MIT-Modern-Variant", |
| 1353 |
) |
| 1354 |
self._open_license_and_check( |
| 1355 |
"MIT-STK.json", |
| 1356 |
self._find_licenses_matcher, |
| 1357 |
"MIT-STK", |
| 1358 |
) |
| 1359 |
self._open_license_and_check( |
| 1360 |
"MIT-Wu.json", |
| 1361 |
self._find_licenses_matcher, |
| 1362 |
"MIT-Wu", |
| 1363 |
) |
| 1364 |
self._open_license_and_check( |
| 1365 |
"MIT-open-group.json", |
| 1366 |
self._find_licenses_matcher, |
| 1367 |
"MIT-open-group", |
| 1368 |
) |
| 1369 |
self._open_license_and_check( |
| 1370 |
"MPL-2.0-no-copyleft-exception.json", |
| 1371 |
self._find_licenses_matcher, |
| 1372 |
"MPL-2 with no-copyleft exception", |
| 1373 |
ignore={"licenseText"}, |
| 1374 |
) |
| 1375 |
|
| 1376 |
def test_parse_bsd(self): |
| 1377 |
def _bsd_matcher(text): |
| 1378 |
return license_parsers.parse_bsd(licenses.clean_comments(text), None, "BSD") |
| 1379 |
|
| 1380 |
self._open_license_and_check("BSD-2-Clause.json", _bsd_matcher, "BSD-2-clause") |
| 1381 |
self._open_license_and_check( |
| 1382 |
"BSD-2-Clause-FreeBSD.json", |
| 1383 |
_bsd_matcher, |
| 1384 |
"BSD-2-clause-FreeBSD", |
| 1385 |
) |
| 1386 |
self._open_license_and_check( |
| 1387 |
"BSD-2-Clause-NetBSD.json", |
| 1388 |
_bsd_matcher, |
| 1389 |
"BSD-2-clause-NetBSD", |
| 1390 |
) |
| 1391 |
self._open_license_and_check("BSD-3-Clause.json", _bsd_matcher, "BSD-3-clause") |
| 1392 |
self._open_license_and_check( |
| 1393 |
"BSD-3-Clause-LBNL.json", |
| 1394 |
_bsd_matcher, |
| 1395 |
"BSD-3-clause-LBNL", |
| 1396 |
) |
| 1397 |
self._open_license_and_check( |
| 1398 |
"BSD-3-Clause-Clear.json", |
| 1399 |
_bsd_matcher, |
| 1400 |
"BSD-3-clause-clear", |
| 1401 |
) |
| 1402 |
# The Sun "... ARE HEREBY EXCLUDED" disclaimer separates the License and |
| 1403 |
# Warranty forms; the 2014 form carries the standard BSD disclaimer and |
| 1404 |
# so stays on the generic no-nuclear name. |
| 1405 |
self._open_license_and_check( |
| 1406 |
"BSD-3-Clause-No-Nuclear-License.json", |
| 1407 |
_bsd_matcher, |
| 1408 |
"BSD-3-clause-no-nuclear-license", |
| 1409 |
) |
| 1410 |
self._open_license_and_check( |
| 1411 |
"BSD-3-Clause-No-Nuclear-License-2014.json", |
| 1412 |
_bsd_matcher, |
| 1413 |
"BSD-3-clause-no-nuclear", |
| 1414 |
) |
| 1415 |
self._open_license_and_check( |
| 1416 |
"BSD-3-Clause-No-Nuclear-Warranty.json", |
| 1417 |
_bsd_matcher, |
| 1418 |
"BSD-3-clause-no-nuclear-warranty", |
| 1419 |
) |
| 1420 |
self._open_license_and_check("BSD-4-Clause.json", _bsd_matcher, "BSD-4-clause") |
| 1421 |
self._open_license_and_check( |
| 1422 |
"BSD-4-Clause-UC.json", |
| 1423 |
_bsd_matcher, |
| 1424 |
"BSD-4-clause-UC", |
| 1425 |
) |
| 1426 |
self._open_license_and_check( |
| 1427 |
"BSD-Protection.json", |
| 1428 |
_bsd_matcher, |
| 1429 |
"BSD-protection", |
| 1430 |
) |
| 1431 |
self._open_license_and_check( |
| 1432 |
"BSD-Source-Code.json", |
| 1433 |
_bsd_matcher, |
| 1434 |
"BSD-source-code", |
| 1435 |
) |
| 1436 |
self._open_license_and_check( |
| 1437 |
"BSD-3-Clause-Attribution.json", |
| 1438 |
_bsd_matcher, |
| 1439 |
"BSD-3-clause-attribution", |
| 1440 |
) |
| 1441 |
self._open_license_and_check("0BSD.json", _bsd_matcher, "0BSD") |
| 1442 |
# A recognised BSD-family variant with a non-standard redistribution |
| 1443 |
# clause still classifies via its own BSD_SUBS rule. |
| 1444 |
self._open_license_and_check("Inner-Net-2.0.json", _bsd_matcher, "Inner-Net-2") |
| 1445 |
# A bare BSD warranty disclaimer borrowed by a non-BSD licence must not |
| 1446 |
# be reported as BSD (parse_bsd returns "" so find_licenses drops it). |
| 1447 |
self._open_license_and_check("ISC-Veillard.json", _bsd_matcher, "") |
| 1448 |
self._open_license_and_check("MIT-testregex.json", _bsd_matcher, "") |
| 1449 |
# End to end, the ISC-style licence resolves to its own name, not BSD. |
| 1450 |
self._open_license_and_check( |
| 1451 |
"ISC-Veillard.json", |
| 1452 |
self._find_licenses_matcher, |
| 1453 |
"ISC-Veillard", |
| 1454 |
) |
| 1455 |
|
| 1456 |
def test_parse_ccby(self): |
| 1457 |
def _cc_by_matcher(text): |
| 1458 |
return license_parsers.parse_cc_by( |
| 1459 |
licenses.clean_comments(text), None, "CC-BY" |
| 1460 |
) |
| 1461 |
|
| 1462 |
self._open_license_and_check("CC-BY-1.0.json", _cc_by_matcher, "CC-BY-1") |
| 1463 |
self._open_license_and_check("CC-BY-2.0.json", _cc_by_matcher, "CC-BY-2") |
| 1464 |
self._open_license_and_check("CC-BY-2.5.json", _cc_by_matcher, "CC-BY-2.5") |
| 1465 |
self._open_license_and_check("CC-BY-3.0.json", _cc_by_matcher, "CC-BY-3") |
| 1466 |
self._open_license_and_check("CC-BY-4.0.json", _cc_by_matcher, "CC-BY-4") |
| 1467 |
self._open_license_and_check("CC-BY-NC-1.0.json", _cc_by_matcher, "CC-BY-NC-1") |
| 1468 |
self._open_license_and_check("CC-BY-NC-2.0.json", _cc_by_matcher, "CC-BY-NC-2") |
| 1469 |
self._open_license_and_check( |
| 1470 |
"CC-BY-NC-2.5.json", |
| 1471 |
_cc_by_matcher, |
| 1472 |
"CC-BY-NC-2.5", |
| 1473 |
) |
| 1474 |
self._open_license_and_check("CC-BY-NC-3.0.json", _cc_by_matcher, "CC-BY-NC-3") |
| 1475 |
self._open_license_and_check("CC-BY-NC-4.0.json", _cc_by_matcher, "CC-BY-NC-4") |
| 1476 |
self._open_license_and_check( |
| 1477 |
"CC-BY-NC-ND-1.0.json", |
| 1478 |
_cc_by_matcher, |
| 1479 |
"CC-BY-NC-ND-1", |
| 1480 |
) |
| 1481 |
self._open_license_and_check( |
| 1482 |
"CC-BY-NC-ND-2.0.json", |
| 1483 |
_cc_by_matcher, |
| 1484 |
"CC-BY-NC-ND-2", |
| 1485 |
) |
| 1486 |
self._open_license_and_check( |
| 1487 |
"CC-BY-NC-ND-2.5.json", |
| 1488 |
_cc_by_matcher, |
| 1489 |
"CC-BY-NC-ND-2.5", |
| 1490 |
) |
| 1491 |
self._open_license_and_check( |
| 1492 |
"CC-BY-NC-ND-3.0.json", |
| 1493 |
_cc_by_matcher, |
| 1494 |
"CC-BY-NC-ND-3", |
| 1495 |
) |
| 1496 |
self._open_license_and_check( |
| 1497 |
"CC-BY-NC-ND-4.0.json", |
| 1498 |
_cc_by_matcher, |
| 1499 |
"CC-BY-NC-ND-4", |
| 1500 |
) |
| 1501 |
self._open_license_and_check( |
| 1502 |
"CC-BY-NC-SA-1.0.json", |
| 1503 |
_cc_by_matcher, |
| 1504 |
"CC-BY-NC-SA-1", |
| 1505 |
) |
| 1506 |
self._open_license_and_check( |
| 1507 |
"CC-BY-NC-SA-2.0.json", |
| 1508 |
_cc_by_matcher, |
| 1509 |
"CC-BY-NC-SA-2", |
| 1510 |
) |
| 1511 |
self._open_license_and_check( |
| 1512 |
"CC-BY-NC-SA-2.5.json", |
| 1513 |
_cc_by_matcher, |
| 1514 |
"CC-BY-NC-SA-2.5", |
| 1515 |
) |
| 1516 |
self._open_license_and_check( |
| 1517 |
"CC-BY-NC-SA-3.0.json", |
| 1518 |
_cc_by_matcher, |
| 1519 |
"CC-BY-NC-SA-3", |
| 1520 |
) |
| 1521 |
self._open_license_and_check( |
| 1522 |
"CC-BY-NC-SA-4.0.json", |
| 1523 |
_cc_by_matcher, |
| 1524 |
"CC-BY-NC-SA-4", |
| 1525 |
) |
| 1526 |
self._open_license_and_check("CC-BY-ND-1.0.json", _cc_by_matcher, "CC-BY-ND-1") |
| 1527 |
self._open_license_and_check("CC-BY-ND-2.0.json", _cc_by_matcher, "CC-BY-ND-2") |
| 1528 |
self._open_license_and_check( |
| 1529 |
"CC-BY-ND-2.5.json", |
| 1530 |
_cc_by_matcher, |
| 1531 |
"CC-BY-ND-2.5", |
| 1532 |
) |
| 1533 |
self._open_license_and_check("CC-BY-ND-3.0.json", _cc_by_matcher, "CC-BY-ND-3") |
| 1534 |
self._open_license_and_check("CC-BY-ND-4.0.json", _cc_by_matcher, "CC-BY-ND-4") |
| 1535 |
self._open_license_and_check("CC-BY-SA-1.0.json", _cc_by_matcher, "CC-BY-SA-1") |
| 1536 |
self._open_license_and_check("CC-BY-SA-2.0.json", _cc_by_matcher, "CC-BY-SA-2") |
| 1537 |
self._open_license_and_check( |
| 1538 |
"CC-BY-SA-2.5.json", |
| 1539 |
_cc_by_matcher, |
| 1540 |
"CC-BY-SA-2.5", |
| 1541 |
) |
| 1542 |
self._open_license_and_check("CC-BY-SA-3.0.json", _cc_by_matcher, "CC-BY-SA-3") |
| 1543 |
self._open_license_and_check("CC-BY-SA-4.0.json", _cc_by_matcher, "CC-BY-SA-4") |
| 1544 |
|
| 1545 |
self._open_license_and_check("CC0-1.0.json", self._find_licenses_matcher, "CC0") |
| 1546 |
|
| 1547 |
def test_cc_family_detection(self): |
| 1548 |
"""End-to-end: the Creative Commons legal-code family is detected. |
| 1549 |
|
| 1550 |
Covers the long English legal codes (which lack the short license-URL / |
| 1551 |
CCPL preamble that the v2/v3 deeds carry), the localized non-English |
| 1552 |
jurisdiction ports, and the non-Attribution CC ids. A jurisdiction port |
| 1553 |
keeps its version (trailing ``.0`` stripped) plus a ``-<JURISDICTION>`` |
| 1554 |
suffix, e.g. ``CC-BY-3.0-IGO`` -> ``CC-BY-3-IGO``. |
| 1555 |
""" |
| 1556 |
# Base English versions that previously went undetected. |
| 1557 |
self._open_license_and_check( |
| 1558 |
"CC-BY-4.0.json", self._find_licenses_matcher, "CC-BY-4" |
| 1559 |
) |
| 1560 |
self._open_license_and_check( |
| 1561 |
"CC-BY-NC-SA-4.0.json", self._find_licenses_matcher, "CC-BY-NC-SA-4" |
| 1562 |
) |
| 1563 |
# English jurisdiction ports: collapsed version + jurisdiction suffix. |
| 1564 |
self._open_license_and_check( |
| 1565 |
"CC-BY-3.0-IGO.json", self._find_licenses_matcher, "CC-BY-3-IGO" |
| 1566 |
) |
| 1567 |
self._open_license_and_check( |
| 1568 |
"CC-BY-SA-2.0-UK.json", self._find_licenses_matcher, "CC-BY-SA-2-UK" |
| 1569 |
) |
| 1570 |
# Localized (non-English) ports read their translated title for the |
| 1571 |
# version and NC/SA/ND modifiers; the jurisdiction comes from a country / |
| 1572 |
# language marker (German "Deutschland", Dutch/French language word, |
| 1573 |
# Japanese "ジャパン"). |
| 1574 |
self._open_license_and_check( |
| 1575 |
"CC-BY-NC-SA-2.0-DE.json", |
| 1576 |
self._find_licenses_matcher, |
| 1577 |
"CC-BY-NC-SA-2-DE", |
| 1578 |
) |
| 1579 |
self._open_license_and_check( |
| 1580 |
"CC-BY-3.0-NL.json", self._find_licenses_matcher, "CC-BY-3-NL" |
| 1581 |
) |
| 1582 |
self._open_license_and_check( |
| 1583 |
"CC-BY-NC-SA-2.0-FR.json", |
| 1584 |
self._find_licenses_matcher, |
| 1585 |
"CC-BY-NC-SA-2-FR", |
| 1586 |
) |
| 1587 |
self._open_license_and_check( |
| 1588 |
"CC-BY-SA-2.1-JP.json", self._find_licenses_matcher, "CC-BY-SA-2.1-JP" |
| 1589 |
) |
| 1590 |
# The two Austrian 3.0 ports have no deed title (CC-BY-3.0-AT carries no |
| 1591 |
# version string at all), so a dedicated rule emits their full id. |
| 1592 |
self._open_license_and_check( |
| 1593 |
"CC-BY-3.0-AT.json", self._find_licenses_matcher, "CC-BY-3-AT" |
| 1594 |
) |
| 1595 |
self._open_license_and_check( |
| 1596 |
"CC-BY-SA-3.0-AT.json", self._find_licenses_matcher, "CC-BY-SA-3-AT" |
| 1597 |
) |
| 1598 |
# Non-Attribution CC ids. |
| 1599 |
self._open_license_and_check( |
| 1600 |
"CC-SA-1.0.json", self._find_licenses_matcher, "CC-SA-1" |
| 1601 |
) |
| 1602 |
self._open_license_and_check( |
| 1603 |
"CC-PDDC.json", self._find_licenses_matcher, "CC-PDDC" |
| 1604 |
) |
| 1605 |
self._open_license_and_check( |
| 1606 |
"CC-PDM-1.0.json", self._find_licenses_matcher, "CC-PDM-1.0" |
| 1607 |
) |
| 1608 |
|
| 1609 |
def test_bsd_permissive_cluster(self): |
| 1610 |
"""End-to-end detection for the BSD / permissive notice cluster. |
| 1611 |
|
| 1612 |
These licences carry non-standard warranty disclaimers, so most are not |
| 1613 |
reached by the generic BSD/ISC family rules and instead anchor on a |
| 1614 |
distinctive clause. The three Sun/Oracle 3-clause forms share one |
| 1615 |
disclaimer and are told apart inside the BSD sub-rules. |
| 1616 |
""" |
| 1617 |
cases = { |
| 1618 |
"0BSD.json": "0BSD", |
| 1619 |
"BSD-2-Clause-pkgconf-disclaimer.json": "BSD-2-clause-pkgconf-disclaimer", |
| 1620 |
"BSD-3-Clause-Modification.json": "BSD-3-clause-modification", |
| 1621 |
"BSD-3-Clause-No-Nuclear-License.json": "BSD-3-clause-no-nuclear-license", |
| 1622 |
"BSD-3-Clause-No-Nuclear-Warranty.json": "BSD-3-clause-no-nuclear-warranty", |
| 1623 |
"BSD-3-Clause-Sun.json": "BSD-3-clause-Sun", |
| 1624 |
"BSD-4.3RENO.json": "BSD-4.3RENO", |
| 1625 |
"BSD-4.3TAHOE.json": "BSD-4.3TAHOE", |
| 1626 |
"BSD-Advertising-Acknowledgement.json": "BSD-advertising-acknowledgement", |
| 1627 |
"Brian-Gladman-2-Clause.json": "Brian-Gladman-2-clause", |
| 1628 |
"Brian-Gladman-3-Clause.json": "Brian-Gladman-3-clause", |
| 1629 |
"Brian-Gladman-3-Clause-no-conversion.json": ( |
| 1630 |
"Brian-Gladman-3-clause-no-conversion" |
| 1631 |
), |
| 1632 |
"Cronyx.json": "Cronyx", |
| 1633 |
"FreeBSD-DOC.json": "FreeBSD-DOC", |
| 1634 |
"NTP-0.json": "NTP-0", |
| 1635 |
"Sun-PPP.json": "Sun-PPP", |
| 1636 |
"Sun-PPP-2000.json": "Sun-PPP-2000", |
| 1637 |
"SunPro.json": "SunPro", |
| 1638 |
"UCAR.json": "UCAR", |
| 1639 |
"Vixie-Cron.json": "Vixie-Cron", |
| 1640 |
"checkmk.json": "checkmk", |
| 1641 |
} |
| 1642 |
for filename, expected in cases.items(): |
| 1643 |
self._open_license_and_check( |
| 1644 |
filename, self._find_licenses_matcher, expected |
| 1645 |
) |
| 1646 |
|
| 1647 |
def test_hpnd_mit_cluster(self): |
| 1648 |
"""End-to-end detection for the HPND / MIT-like permissive cluster. |
| 1649 |
|
| 1650 |
These are "historical permission notice" grants close to MIT/X11. Most |
| 1651 |
differ from the already-covered ones only in fee wording or verb list, |
| 1652 |
so a broadened family grant routes them to parse_mit, which names the |
| 1653 |
specific variant via MIT_SUBS. The base "sell" form is told apart from |
| 1654 |
the plain X11 licence by its advertising clause. |
| 1655 |
""" |
| 1656 |
cases = { |
| 1657 |
"HP-1986.json": "MIT-like-HP-1986", |
| 1658 |
"HP-1989.json": "MIT-like-HP-1989", |
| 1659 |
"HPND-INRIA-IMAG.json": "MIT-like-HPND-INRIA-IMAG", |
| 1660 |
"HPND-Intel.json": "MIT-like-HPND-Intel", |
| 1661 |
"HPND-Kevlin-Henney.json": "MIT-like-HPND-Kevlin-Henney", |
| 1662 |
"HPND-SMC.json": "MIT-like-HPND-SMC", |
| 1663 |
"HPND-doc-sell.json": "MIT-like-HPND-doc-sell", |
| 1664 |
"HPND-export-US-acknowledgement.json": ( |
| 1665 |
"MIT-like-HPND-export-US-acknowledgement" |
| 1666 |
), |
| 1667 |
"HPND-merchantability-variant.json": ( |
| 1668 |
"MIT-like-HPND-merchantability-variant" |
| 1669 |
), |
| 1670 |
"HPND-sell-MIT-disclaimer-xserver.json": ( |
| 1671 |
"MIT-like-HPND-sell-MIT-disclaimer-xserver" |
| 1672 |
), |
| 1673 |
"HPND-sell-regexpr.json": "MIT-like-HPND-sell-regexpr", |
| 1674 |
"HPND-sell-variant.json": "MIT-like-HPND-sell-variant", |
| 1675 |
} |
| 1676 |
for filename, expected in cases.items(): |
| 1677 |
self._open_license_and_check( |
| 1678 |
filename, self._find_licenses_matcher, expected |
| 1679 |
) |
| 1680 |
|
| 1681 |
def test_doc_data_gov_cluster(self): |
| 1682 |
"""End-to-end detection for documentation / open-government / data licences. |
| 1683 |
|
| 1684 |
These are standalone notices identified by their distinctive title line |
| 1685 |
(the DocBook DTD/XML forms reuse the MIT-like family naming). |
| 1686 |
""" |
| 1687 |
cases = { |
| 1688 |
"OGL-UK-1.0.json": "OGL-UK-1", |
| 1689 |
"OGL-UK-2.0.json": "OGL-UK-2", |
| 1690 |
"OGL-UK-3.0.json": "OGL-UK-3", |
| 1691 |
"OGL-Canada-2.0.json": "OGL-Canada-2", |
| 1692 |
"OPL-UK-3.0.json": "OPL-UK-3", |
| 1693 |
"NLOD-2.0.json": "NLOD-2", |
| 1694 |
"NCGL-UK-2.0.json": "NCGL-UK-2", |
| 1695 |
"etalab-2.0.json": "etalab-2", |
| 1696 |
"CDL-1.0.json": "CDL-1", |
| 1697 |
"CDLA-Permissive-1.0.json": "CDLA-Permissive-1", |
| 1698 |
"CDLA-Permissive-2.0.json": "CDLA-Permissive-2", |
| 1699 |
"CDLA-Sharing-1.0.json": "CDLA-Sharing-1", |
| 1700 |
"ODC-By-1.0.json": "ODC-By-1", |
| 1701 |
"DL-DE-BY-2.0.json": "DL-DE-BY-2", |
| 1702 |
"DL-DE-ZERO-2.0.json": "DL-DE-Zero-2", |
| 1703 |
"OPUBL-1.0.json": "OPUBL-1", |
| 1704 |
"DocBook-DTD.json": "MIT-like-DocBook-DTD", |
| 1705 |
"DocBook-XML.json": "MIT-like-DocBook-XML", |
| 1706 |
} |
| 1707 |
for filename, expected in cases.items(): |
| 1708 |
self._open_license_and_check( |
| 1709 |
filename, self._find_licenses_matcher, expected |
| 1710 |
) |
| 1711 |
|
| 1712 |
def test_font_cluster(self): |
| 1713 |
"""End-to-end detection for the font licences (the FontLicense group). |
| 1714 |
|
| 1715 |
Each anchors on a substantive grant clause in the licence body, not just |
| 1716 |
the foundry/font name; OFL is detected separately and is unaffected. |
| 1717 |
""" |
| 1718 |
cases = { |
| 1719 |
"Arphic-1999.json": "Arphic-1999", |
| 1720 |
"Baekmuk.json": "Baekmuk", |
| 1721 |
"Bitstream-Charter.json": "Bitstream-Charter", |
| 1722 |
"Bitstream-Vera.json": "Bitstream-Vera", |
| 1723 |
"Kastrup.json": "Kastrup", |
| 1724 |
"Lucida-Bitmap-Fonts.json": "Lucida-Bitmap-Fonts", |
| 1725 |
"ParaType-Free-Font-1.3.json": "ParaType-Free-Font-1.3", |
| 1726 |
"mplus.json": "mplus", |
| 1727 |
"Ubuntu-font-1.0.json": "Ubuntu-font-1", |
| 1728 |
"OFL-1.1.json": "OFL-1.1", |
| 1729 |
} |
| 1730 |
for filename, expected in cases.items(): |
| 1731 |
self._open_license_and_check( |
| 1732 |
filename, self._find_licenses_matcher, expected |
| 1733 |
) |
| 1734 |
|
| 1735 |
def test_gpl_exception_only_notices(self): |
| 1736 |
"""Deprecated `GPL-N.0-with-X-exception` ids ship only the exception |
| 1737 |
notice (the GPL body is a "insert GPL ... here" placeholder), so they are |
| 1738 |
not standalone licences. ``find_licenses`` must NOT report them as a |
| 1739 |
licence; but ``parse_gpl`` must still recognise the exception clause - |
| 1740 |
that is what fires when the notice accompanies the real GPL text. |
| 1741 |
""" |
| 1742 |
|
| 1743 |
def _exception_matcher(text): |
| 1744 |
return license_parsers.parse_gpl(licenses.clean_comments(text), None, "GPL") |
| 1745 |
|
| 1746 |
exceptions = { |
| 1747 |
"GPL-2.0-with-autoconf-exception.json": "GPL with AutoConf exception", |
| 1748 |
"GPL-2.0-with-bison-exception.json": "GPL with Bison exception", |
| 1749 |
"GPL-2.0-with-classpath-exception.json": "GPL with ClassPath exception", |
| 1750 |
"GPL-2.0-with-font-exception.json": "GPL with Font exception", |
| 1751 |
"GPL-2.0-with-GCC-exception.json": "GPL with GCC exception", |
| 1752 |
"GPL-3.0-with-autoconf-exception.json": "GPL-3 with AutoConf-3 exception", |
| 1753 |
"GPL-3.0-with-GCC-exception.json": "GPL-3 with GCC-3.1 exception", |
| 1754 |
} |
| 1755 |
for filename, exception in exceptions.items(): |
| 1756 |
# The exception clause is recognised by the GPL exception parser ... |
| 1757 |
self._open_license_and_check(filename, _exception_matcher, exception) |
| 1758 |
# ... but the placeholder notice is not reported as a licence alone. |
| 1759 |
self._open_license_and_check(filename, self._find_licenses_matcher, "") |
| 1760 |
|
| 1761 |
def test_hardware_cluster(self): |
| 1762 |
"""End-to-end detection for the open-hardware licences (HardwareLicense |
| 1763 |
group). The CERN v2 Permissive/Strongly/Weakly variants share a preamble |
| 1764 |
and are told apart by the variant word in their title. |
| 1765 |
""" |
| 1766 |
cases = { |
| 1767 |
"CERN-OHL-1.1.json": "CERN-OHL-1.1", |
| 1768 |
"CERN-OHL-1.2.json": "CERN-OHL-1.2", |
| 1769 |
"CERN-OHL-P-2.0.json": "CERN-OHL-P-2", |
| 1770 |
"CERN-OHL-S-2.0.json": "CERN-OHL-S-2", |
| 1771 |
"CERN-OHL-W-2.0.json": "CERN-OHL-W-2", |
| 1772 |
"SHL-0.5.json": "SHL-0.5", |
| 1773 |
"SHL-0.51.json": "SHL-0.51", |
| 1774 |
"TAPR-OHL-1.0.json": "TAPR-OHL-1", |
| 1775 |
} |
| 1776 |
for filename, expected in cases.items(): |
| 1777 |
# Checks every present key, incl. the SHL standardLicenseHeader, |
| 1778 |
# which is also detected (its version-specific licence header). |
| 1779 |
self._open_license_and_check( |
| 1780 |
filename, self._find_licenses_matcher, expected |
| 1781 |
) |
| 1782 |
|
| 1783 |
def test_usgov_public_domain_cluster(self): |
| 1784 |
"""End-to-end detection for the US-Gov / agency public-domain notices |
| 1785 |
(USGovPD group). NIST-PD and NTIA-PD share the Section-105 clause and are |
| 1786 |
told apart by the naming agency. |
| 1787 |
""" |
| 1788 |
cases = { |
| 1789 |
"NIST-PD.json": "NIST-PD", |
| 1790 |
"NIST-PD-fallback.json": "NIST-PD-fallback", |
| 1791 |
"NIST-PD-TNT.json": "NIST-PD-TNT", |
| 1792 |
"NIST-Software.json": "NIST-Software", |
| 1793 |
"NTIA-PD.json": "NTIA-PD", |
| 1794 |
"NCBI-PD.json": "NCBI-PD", |
| 1795 |
"libselinux-1.0.json": "libselinux-1", |
| 1796 |
} |
| 1797 |
for filename, expected in cases.items(): |
| 1798 |
self._open_license_and_check( |
| 1799 |
filename, self._find_licenses_matcher, expected |
| 1800 |
) |
| 1801 |
|
| 1802 |
def test_pd_misc_cluster(self): |
| 1803 |
"""End-to-end detection for unrelated public-domain notices (PdMisc |
| 1804 |
group). The SAX v2 form must not collide with the v1 SAX-PD, which |
| 1805 |
embeds the same "abandon ... SAX 2.0" sentence. |
| 1806 |
""" |
| 1807 |
cases = { |
| 1808 |
"blessing.json": "blessing", |
| 1809 |
"bcrypt-Solar-Designer.json": "bcrypt-Solar-Designer", |
| 1810 |
"SAX-PD-2.0.json": "SAX-PD-2", |
| 1811 |
"SGP4.json": "SGP4", |
| 1812 |
"Symlinks.json": "Symlinks", |
| 1813 |
"WTFNMFPL.json": "WTFNMFPL", |
| 1814 |
"Unlicense-libtelnet.json": "Unlicense-libtelnet", |
| 1815 |
"LZMA-SDK-9.11-to-9.20.json": "LZMA-SDK-9.11-to-9.20", |
| 1816 |
"LZMA-SDK-9.22.json": "LZMA-SDK-9.22", |
| 1817 |
"SAX-PD.json": "SAX-PD", # v1 unaffected |
| 1818 |
} |
| 1819 |
for filename, expected in cases.items(): |
| 1820 |
self._open_license_and_check( |
| 1821 |
filename, self._find_licenses_matcher, expected |
| 1822 |
) |
| 1823 |
|
| 1824 |
def test_manpage_cluster(self): |
| 1825 |
"""End-to-end detection for the Linux man-pages licences (ManPage group) |
| 1826 |
plus the standalone man2html / hyphen-bulgarian notices. The bare |
| 1827 |
two-paragraph form must not capture the Latex2e family, which appends a |
| 1828 |
"translations of this manual" paragraph to the same two paragraphs. |
| 1829 |
""" |
| 1830 |
cases = { |
| 1831 |
"Linux-man-pages-1-para.json": "Linux-man-pages-1-para", |
| 1832 |
"Linux-man-pages-copyleft.json": "Linux-man-pages-copyleft", |
| 1833 |
"Linux-man-pages-copyleft-2-para.json": "Linux-man-pages-copyleft-2-para", |
| 1834 |
"Linux-man-pages-copyleft-var.json": "Linux-man-pages-copyleft-var", |
| 1835 |
"man2html.json": "man2html", |
| 1836 |
"hyphen-bulgarian.json": "hyphen-bulgarian", |
| 1837 |
"Latex2e.json": "Latex2e", # unaffected (has the translations clause) |
| 1838 |
} |
| 1839 |
for filename, expected in cases.items(): |
| 1840 |
self._open_license_and_check( |
| 1841 |
filename, self._find_licenses_matcher, expected |
| 1842 |
) |
| 1843 |
|
| 1844 |
def test_ctan_tex_cluster(self): |
| 1845 |
"""End-to-end detection for the CTAN / TeX licences (CtanTex group). |
| 1846 |
Latex2e-translated-notice is the Latex2e text with an extra "approved by |
| 1847 |
the Foundation" translation clause; plain Latex2e is unaffected. |
| 1848 |
""" |
| 1849 |
cases = { |
| 1850 |
"Knuth-CTAN.json": "Knuth-CTAN", |
| 1851 |
"MMIXware.json": "MMIXware", |
| 1852 |
"Latex2e-translated-notice.json": "Latex2e-translated-notice", |
| 1853 |
"magaz.json": "magaz", |
| 1854 |
"swrule.json": "swrule", |
| 1855 |
"threeparttable.json": "threeparttable", |
| 1856 |
"ulem.json": "ulem", |
| 1857 |
"TTYP0.json": "TTYP0", |
| 1858 |
"Latex2e.json": "Latex2e", # unaffected |
| 1859 |
} |
| 1860 |
for filename, expected in cases.items(): |
| 1861 |
self._open_license_and_check( |
| 1862 |
filename, self._find_licenses_matcher, expected |
| 1863 |
) |
| 1864 |
|
| 1865 |
def test_standards_body_cluster(self): |
| 1866 |
"""End-to-end detection for the standards-body licences (StandardsBody |
| 1867 |
group): Unicode + the W3C-derived family. W3C-20150513 is told apart by |
| 1868 |
its "obtaining and/or copying" opener; the older W3C / W3C-19980720 (with |
| 1869 |
"obtaining, using and/or copying") are unaffected. |
| 1870 |
""" |
| 1871 |
cases = { |
| 1872 |
"Unicode-3.0.json": "Unicode-3", |
| 1873 |
"Unicode-DFS-2015.json": "Unicode-DFS-2015", |
| 1874 |
"Unicode-DFS-2016.json": "Unicode-DFS-2016", |
| 1875 |
"W3C-20150513.json": "W3C-20150513", |
| 1876 |
"WordNet.json": "WordNet", |
| 1877 |
"OGC-1.0.json": "OGC-1", |
| 1878 |
"W3C.json": "W3C", # unaffected |
| 1879 |
"W3C-19980720.json": "W3C-19980720", # unaffected |
| 1880 |
} |
| 1881 |
for filename, expected in cases.items(): |
| 1882 |
# Match on licenseText (as the coverage harness does); the W3C forms |
| 1883 |
# carry a separate short-notice standardLicenseHeader that the |
| 1884 |
# existing W3C rules also do not cover. |
| 1885 |
self._open_license_and_check( |
| 1886 |
filename, |
| 1887 |
self._find_licenses_matcher, |
| 1888 |
expected, |
| 1889 |
ignore=("standardLicenseHeader",), |
| 1890 |
) |
| 1891 |
|
| 1892 |
def test_source_available_cluster(self): |
| 1893 |
"""End-to-end detection for the source-available / business copyleft |
| 1894 |
licences (SrcAvailable group). Each is anchored on its title-and-version |
| 1895 |
line plus a substantive body clause, so a bare reference to the name does |
| 1896 |
not match. Trailing zero version components are dropped from the reported |
| 1897 |
name (SSPL-1.0 -> SSPL-1, Parity-6.0.0 -> Parity-6, |
| 1898 |
PolyForm-Noncommercial-1.0.0 -> PolyForm-Noncommercial-1); the two |
| 1899 |
copyleft-next releases differ only by their release date and the two |
| 1900 |
Parity versions by their one-line summary. |
| 1901 |
""" |
| 1902 |
cases = { |
| 1903 |
"copyleft-next-0.3.0.json": "copyleft-next-0.3", |
| 1904 |
"copyleft-next-0.3.1.json": "copyleft-next-0.3.1", |
| 1905 |
"Parity-6.0.0.json": "Parity-6", |
| 1906 |
"Parity-7.0.0.json": "Parity-7", |
| 1907 |
"PolyForm-Noncommercial-1.0.0.json": "PolyForm-Noncommercial-1", |
| 1908 |
"PolyForm-Small-Business-1.0.0.json": "PolyForm-Small-Business-1", |
| 1909 |
"SSPL-1.0.json": "SSPL-1", |
| 1910 |
"BUSL-1.1.json": "BUSL-1.1", |
| 1911 |
"Elastic-2.0.json": "Elastic-2", |
| 1912 |
"SUL-1.0.json": "SUL-1", |
| 1913 |
} |
| 1914 |
for filename, expected in cases.items(): |
| 1915 |
# SSPL/BUSL also ship a standardLicenseHeader application notice that |
| 1916 |
# grants/governs by reference to the licence; those are covered too, |
| 1917 |
# so every present field must detect. |
| 1918 |
self._open_license_and_check( |
| 1919 |
filename, self._find_licenses_matcher, expected |
| 1920 |
) |
| 1921 |
|
| 1922 |
def test_european_copyleft_cluster(self): |
| 1923 |
"""End-to-end detection for the European / formal-language copyleft |
| 1924 |
licences. The ESA-PL family (EsaPl group) splits by copyleft strength |
| 1925 |
(permissive / weak / strong, all v2.4); TU-Berlin (TuBerlin group) tells |
| 1926 |
v2.0 from v1.0 by the appended permissive grant (trailing ".0" stripped: |
| 1927 |
TU-Berlin-1.0 -> TU-Berlin-1). EUPL-1.2 dropped the version from its |
| 1928 |
appendix notice, so it is matched by the licence header instead, while |
| 1929 |
EUPL-1.0/1.1 (already detected via the appendix) are unaffected. OLFL-1.3 |
| 1930 |
is a standalone rule. Each anchor pairs the title with substantive body |
| 1931 |
text so a bare reference to the name does not match. |
| 1932 |
""" |
| 1933 |
cases = { |
| 1934 |
"ESA-PL-permissive-2.4.json": "ESA-PL-permissive-2.4", |
| 1935 |
"ESA-PL-weak-copyleft-2.4.json": "ESA-PL-weak-copyleft-2.4", |
| 1936 |
"ESA-PL-strong-copyleft-2.4.json": "ESA-PL-strong-copyleft-2.4", |
| 1937 |
"EUPL-1.0.json": "EUPL-1", # unaffected |
| 1938 |
"EUPL-1.1.json": "EUPL-1.1", # unaffected |
| 1939 |
"EUPL-1.2.json": "EUPL-1.2", |
| 1940 |
"OLFL-1.3.json": "OLFL-1.3", |
| 1941 |
"TU-Berlin-1.0.json": "TU-Berlin-1", |
| 1942 |
"TU-Berlin-2.0.json": "TU-Berlin-2", |
| 1943 |
} |
| 1944 |
for filename, expected in cases.items(): |
| 1945 |
self._open_license_and_check( |
| 1946 |
filename, self._find_licenses_matcher, expected |
| 1947 |
) |
| 1948 |
|
| 1949 |
def test_apache_mpl_derived_cluster(self): |
| 1950 |
"""End-to-end detection for the Apache/MPL-derived + Mulan + small |
| 1951 |
copyleft licences. Two share an origin and get a family gate: MulanPSL |
| 1952 |
(MulanPsl group, v1/v2 by the Chinese "第1版"/"第2版" marker) and the |
| 1953 |
OSL-template derivatives TGPPL/UCL (OslDerived group, matched on their own |
| 1954 |
titles so OSL/AFL/NPOSL stay untouched). The rest are standalone rules |
| 1955 |
anchored on a distinctive title plus body: Pixar (modified Apache 2.0), |
| 1956 |
OSC (German Expat translation), MVT-1.1 / TPL (MPL-derived), MMPL-1.0.1 |
| 1957 |
(Minecraft) and SMAIL-GPL (clarified GPL). Trailing ".0" is stripped |
| 1958 |
(MulanPSL-1.0 -> MulanPSL-1, TGPPL-1.0 -> TGPPL-1, TPL-1.0 -> TPL-1, |
| 1959 |
OSC-1.0 -> OSC-1); the derivatives do not trigger the generic |
| 1960 |
Apache/Mozilla/GPL rules. The MulanPSL / TGPPL / UCL / MVT / TPL |
| 1961 |
application-notice standardLicenseHeaders are also covered. Pixar belongs |
| 1962 |
to the Apache family: it is Apache-2.0 with Section 6 (Trademarks) deleted |
| 1963 |
and replaced, and that replaced clause appears in both its full text and |
| 1964 |
its header, so both fields resolve to "Pixar". (The deprecated wxWindows |
| 1965 |
id is only an exception notice, not a standalone licence; it stays |
| 1966 |
undetected and is covered as WxWindows-3.1 by test_lgpl_wxwindows_exception.) |
| 1967 |
""" |
| 1968 |
cases = { |
| 1969 |
"MulanPSL-1.0.json": "MulanPSL-1", |
| 1970 |
"MulanPSL-2.0.json": "MulanPSL-2", |
| 1971 |
"TGPPL-1.0.json": "TGPPL-1", |
| 1972 |
"UCL-1.0.json": "UCL-1", |
| 1973 |
"Pixar.json": "Pixar", |
| 1974 |
"OSC-1.0.json": "OSC-1", |
| 1975 |
"MVT-1.1.json": "MVT-1.1", |
| 1976 |
"TPL-1.0.json": "TPL-1", |
| 1977 |
"MMPL-1.0.1.json": "MMPL-1.0.1", |
| 1978 |
"SMAIL-GPL.json": "SMAIL-GPL", |
| 1979 |
} |
| 1980 |
for filename, expected in cases.items(): |
| 1981 |
self._open_license_and_check( |
| 1982 |
filename, self._find_licenses_matcher, expected |
| 1983 |
) |
| 1984 |
|
| 1985 |
def test_data_use_agreements_cluster(self): |
| 1986 |
"""End-to-end detection for the data-use agreement licences. Three share |
| 1987 |
an origin and get a family gate: the Microsoft Use of Data Agreements |
| 1988 |
(UdaData group, Computational/Open by title), the ASWF Digital Assets |
| 1989 |
License (AswfAssets group, by version) and the MITRE terms-of-use grants |
| 1990 |
(MitreTou group, CAPEC/CVE by dataset). The rest are standalone rules: |
| 1991 |
OGDL-Taiwan (Chinese title + date), the UK Advanced Cryptics Dictionary |
| 1992 |
restriction, and NCL (a BSD-3-style notice whose reordered |
| 1993 |
endorsement-first opener keeps it off the generic BSD rules). Trailing |
| 1994 |
".0" is stripped (C-UDA-1.0 -> C-UDA-1, ASWF-Digital-Assets-1.0 -> |
| 1995 |
ASWF-Digital-Assets-1, OGDL-Taiwan-1.0 -> OGDL-Taiwan-1). |
| 1996 |
""" |
| 1997 |
cases = { |
| 1998 |
"C-UDA-1.0.json": "C-UDA-1", |
| 1999 |
"O-UDA-1.0.json": "O-UDA-1", |
| 2000 |
"ASWF-Digital-Assets-1.0.json": "ASWF-Digital-Assets-1", |
| 2001 |
"ASWF-Digital-Assets-1.1.json": "ASWF-Digital-Assets-1.1", |
| 2002 |
"CAPEC-tou.json": "CAPEC-tou", |
| 2003 |
"cve-tou.json": "cve-tou", |
| 2004 |
"OGDL-Taiwan-1.0.json": "OGDL-Taiwan-1", |
| 2005 |
"Advanced-Cryptics-Dictionary.json": "Advanced-Cryptics-Dictionary", |
| 2006 |
"NCL.json": "NCL", |
| 2007 |
} |
| 2008 |
for filename, expected in cases.items(): |
| 2009 |
self._open_license_and_check( |
| 2010 |
filename, self._find_licenses_matcher, expected |
| 2011 |
) |
| 2012 |
|
| 2013 |
def test_small_permissive_families_cluster(self): |
| 2014 |
"""End-to-end detection for the Sun/CMU/Adobe/SSH small permissive |
| 2015 |
notices. Three share an origin and get a family gate: the CMU/Mach |
| 2016 |
notice (CmuMach group, documentation vs no-doc variant), Tatu Ylonen's |
| 2017 |
SSH notice (Ssh group, full OpenSSH vs short form) and the Boehm GC |
| 2018 |
notice (BoehmGc group, without-fee vs base). The rest are standalone |
| 2019 |
rules anchored on a substantive clause: Adobe Display PostScript (its |
| 2020 |
trademark-licence clause), Adobe Utopia (the typeface grant), ssh-keyscan |
| 2021 |
(the OpenBSD due-credit clause) and OpenVision (its free-use grant). |
| 2022 |
""" |
| 2023 |
cases = { |
| 2024 |
"CMU-Mach.json": "CMU-Mach", |
| 2025 |
"CMU-Mach-nodoc.json": "CMU-Mach-nodoc", |
| 2026 |
"Adobe-Display-PostScript.json": "Adobe-Display-PostScript", |
| 2027 |
"Adobe-Utopia.json": "Adobe-Utopia", |
| 2028 |
"SSH-OpenSSH.json": "SSH-OpenSSH", |
| 2029 |
"SSH-short.json": "SSH-short", |
| 2030 |
"ssh-keyscan.json": "ssh-keyscan", |
| 2031 |
"OpenVision.json": "OpenVision", |
| 2032 |
"Boehm-GC.json": "Boehm-GC", |
| 2033 |
"Boehm-GC-without-fee.json": "Boehm-GC-without-fee", |
| 2034 |
} |
| 2035 |
for filename, expected in cases.items(): |
| 2036 |
self._open_license_and_check( |
| 2037 |
filename, self._find_licenses_matcher, expected |
| 2038 |
) |
| 2039 |
|
| 2040 |
def test_documentation_book_code_cluster(self): |
| 2041 |
"""End-to-end detection for the documentation / book-code permission |
| 2042 |
notices. These have no shared structure, so each is a standalone |
| 2043 |
``LICENSES_RES`` rule anchored on a substantive, mostly name-free clause. |
| 2044 |
ALGLIB anchors on its "first (or last) lines of this file" retention |
| 2045 |
clause rather than the bare "Redistribution and use of this document" |
| 2046 |
opener, which collides with the Enthought docs licence. |
| 2047 |
""" |
| 2048 |
cases = { |
| 2049 |
"AdaCore-doc.json": "AdaCore-doc", |
| 2050 |
"GCR-docs.json": "GCR-docs", |
| 2051 |
"LPD-document.json": "LPD-document", |
| 2052 |
"SchemeReport.json": "SchemeReport", |
| 2053 |
"ALGLIB-Documentation.json": "ALGLIB-Documentation", |
| 2054 |
"Graphics-Gems.json": "Graphics-Gems", |
| 2055 |
"Game-Programming-Gems.json": "Game-Programming-Gems", |
| 2056 |
"gtkbook.json": "gtkbook", |
| 2057 |
"McPhee-slideshow.json": "McPhee-slideshow", |
| 2058 |
"ISO-permission.json": "ISO-permission", |
| 2059 |
} |
| 2060 |
for filename, expected in cases.items(): |
| 2061 |
self._open_license_and_check( |
| 2062 |
filename, self._find_licenses_matcher, expected |
| 2063 |
) |
| 2064 |
|
| 2065 |
def test_eula_proprietary_cluster(self): |
| 2066 |
"""End-to-end detection for the EULA / proprietary / restricted + |
| 2067 |
permissive-oddball licences. No shared structure, so each is a standalone |
| 2068 |
``LICENSES_RES`` rule anchored on its distinctive title or grant clause. |
| 2069 |
Several are non-free EULAs, detected for non-free/contrib analysis. |
| 2070 |
BlueOak anchors on the versioned title ("Blue Oak Model License Version |
| 2071 |
1.0.0") because the bare name is also referenced by Parity-7. Trailing |
| 2072 |
".0"/".0.0" components are dropped from the names. |
| 2073 |
""" |
| 2074 |
cases = { |
| 2075 |
"3D-Slicer-1.0.json": "3D-Slicer-1", |
| 2076 |
"FDK-AAC.json": "FDK-AAC", |
| 2077 |
"IEC-Code-Components-EULA.json": "IEC-Code-Components-EULA", |
| 2078 |
"JPL-image.json": "JPL-image", |
| 2079 |
"UnRAR.json": "UnRAR", |
| 2080 |
"Hippocratic-2.1.json": "Hippocratic-2.1", |
| 2081 |
"OpenMDW-1.0.json": "OpenMDW-1", |
| 2082 |
"MS-LPL.json": "MS-LPL", |
| 2083 |
"GLWTPL.json": "GLWTPL", |
| 2084 |
"SL.json": "SL", |
| 2085 |
"BOLA-1.1.json": "BOLA-1.1", |
| 2086 |
"COIL-1.0.json": "COIL-1", |
| 2087 |
"BlueOak-1.0.0.json": "BlueOak-1", |
| 2088 |
} |
| 2089 |
for filename, expected in cases.items(): |
| 2090 |
self._open_license_and_check( |
| 2091 |
filename, self._find_licenses_matcher, expected |
| 2092 |
) |
| 2093 |
|
| 2094 |
def test_singletons_chunk1_cluster(self): |
| 2095 |
"""End-to-end detection for a set of assorted single-file permissive |
| 2096 |
notices, each a standalone rule on a distinctive grant/title clause. |
| 2097 |
Caldera-no-preamble shares its BSD-4-clause body with the full Caldera |
| 2098 |
licence; the Caldera-family rule returns "Caldera" when the "fee free |
| 2099 |
license" preamble is present, else "Caldera-no-preamble" (verified by the |
| 2100 |
Caldera regression below). |
| 2101 |
""" |
| 2102 |
cases = { |
| 2103 |
"AMD-newlib.json": "AMD-newlib", |
| 2104 |
"AML-glslang.json": "AML-glslang", |
| 2105 |
"any-OSI.json": "any-OSI", |
| 2106 |
"any-OSI-perl-modules.json": "any-OSI-perl-modules", |
| 2107 |
"App-s2p.json": "App-s2p", |
| 2108 |
"Aspell-RU.json": "Aspell-RU", |
| 2109 |
"Buddy.json": "Buddy", |
| 2110 |
"Caldera-no-preamble.json": "Caldera-no-preamble", |
| 2111 |
"Catharon.json": "Catharon", |
| 2112 |
"CFITSIO.json": "CFITSIO", |
| 2113 |
# regression: the full Caldera licence (preamble + same body) must |
| 2114 |
# still resolve to Caldera, not Caldera-no-preamble. |
| 2115 |
"Caldera.json": "Caldera", |
| 2116 |
} |
| 2117 |
for filename, expected in cases.items(): |
| 2118 |
self._open_license_and_check( |
| 2119 |
filename, self._find_licenses_matcher, expected |
| 2120 |
) |
| 2121 |
|
| 2122 |
def test_singletons_chunk2_cluster(self): |
| 2123 |
"""End-to-end detection for a further set of assorted single-file |
| 2124 |
permissive notices, each a standalone rule on a distinctive grant/title |
| 2125 |
clause. The two Detection Rule License versions share one family rule that |
| 2126 |
reads the version (1.0 -> DRL-1, 1.1 -> DRL-1.1); CryptoSwift is a zlib |
| 2127 |
variant told apart by its "or binary" + acknowledgment clause. |
| 2128 |
""" |
| 2129 |
cases = { |
| 2130 |
"check-cvs.json": "check-cvs", |
| 2131 |
"Cornell-Lossless-JPEG.json": "Cornell-Lossless-JPEG", |
| 2132 |
"CryptoSwift.json": "CryptoSwift", |
| 2133 |
"DEC-3-Clause.json": "DEC-3-Clause", |
| 2134 |
"DRL-1.0.json": "DRL-1", |
| 2135 |
"DRL-1.1.json": "DRL-1.1", |
| 2136 |
"EPICS.json": "EPICS", |
| 2137 |
"FBM.json": "FBM", |
| 2138 |
"Ferguson-Twofish.json": "Ferguson-Twofish", |
| 2139 |
"Furuseth.json": "Furuseth", |
| 2140 |
} |
| 2141 |
for filename, expected in cases.items(): |
| 2142 |
self._open_license_and_check( |
| 2143 |
filename, self._find_licenses_matcher, expected |
| 2144 |
) |
| 2145 |
|
| 2146 |
def test_singletons_chunk3_cluster(self): |
| 2147 |
"""End-to-end detection for a further set of assorted single-file |
| 2148 |
permissive notices. IJG and IJG-short share one family rule on their |
| 2149 |
README/no-warranty clause; it returns IJG for the full licence (carries |
| 2150 |
the "derived from or based on the IJG code" condition) and IJG-short for |
| 2151 |
the brief form (regression on the full IJG below). |
| 2152 |
""" |
| 2153 |
cases = { |
| 2154 |
"fwlw.json": "fwlw", |
| 2155 |
"GD.json": "GD", |
| 2156 |
"generic-xts.json": "generic-xts", |
| 2157 |
"Gutmann.json": "Gutmann", |
| 2158 |
"HDF5.json": "HDF5", |
| 2159 |
"hdparm.json": "hdparm", |
| 2160 |
"HIDAPI.json": "HIDAPI", |
| 2161 |
"HTMLTIDY.json": "HTMLTIDY", |
| 2162 |
"IJG-short.json": "IJG-short", |
| 2163 |
"IJG.json": "IJG", |
| 2164 |
"InnoSetup.json": "InnoSetup", |
| 2165 |
} |
| 2166 |
for filename, expected in cases.items(): |
| 2167 |
self._open_license_and_check( |
| 2168 |
filename, self._find_licenses_matcher, expected |
| 2169 |
) |
| 2170 |
|
| 2171 |
def test_singletons_chunk4_cluster(self): |
| 2172 |
"""End-to-end detection for a further set of assorted single-file |
| 2173 |
permissive notices. Two pairs share a family rule: the PNG Reference |
| 2174 |
Library License (v1 -> libpng-1.6.35, v2 -> libpng-2) and the Mackerras |
| 2175 |
BSD-3-clause (plain vs the "developed by Paul Mackerras" acknowledgment |
| 2176 |
variant). |
| 2177 |
""" |
| 2178 |
cases = { |
| 2179 |
"Jam.json": "Jam", |
| 2180 |
"jove.json": "jove", |
| 2181 |
"Kazlib.json": "Kazlib", |
| 2182 |
"libpng-1.6.35.json": "libpng-1.6.35", |
| 2183 |
"libpng-2.0.json": "libpng-2", |
| 2184 |
"libutil-David-Nugent.json": "libutil-David-Nugent", |
| 2185 |
"Linux-OpenIB.json": "Linux-OpenIB", |
| 2186 |
"lsof.json": "lsof", |
| 2187 |
"Mackerras-3-Clause.json": "Mackerras-3-Clause", |
| 2188 |
"Mackerras-3-Clause-acknowledgment.json": ( |
| 2189 |
"Mackerras-3-Clause-acknowledgment" |
| 2190 |
), |
| 2191 |
} |
| 2192 |
for filename, expected in cases.items(): |
| 2193 |
self._open_license_and_check( |
| 2194 |
filename, self._find_licenses_matcher, expected |
| 2195 |
) |
| 2196 |
|
| 2197 |
def test_singletons_chunk5_cluster(self): |
| 2198 |
"""End-to-end detection for a further set of assorted single-file |
| 2199 |
permissive notices. MIPS and mpi-permissive anchor on their |
| 2200 |
organisation-specific clause (MIPS Computer Systems / Etnus) because the |
| 2201 |
bare grant template is shared with ThirdEye and DSDP/mpich respectively. |
| 2202 |
""" |
| 2203 |
cases = { |
| 2204 |
"mailprio.json": "mailprio", |
| 2205 |
"Martin-Birgmeier.json": "Martin-Birgmeier", |
| 2206 |
"Minpack.json": "Minpack", |
| 2207 |
"MIPS.json": "MIPS", |
| 2208 |
"MIT-Festival.json": "MIT-Festival", |
| 2209 |
"MIT-testregex.json": "MIT-testregex", |
| 2210 |
"MPEG-SSG.json": "MPEG-SSG", |
| 2211 |
"mpi-permissive.json": "mpi-permissive", |
| 2212 |
"NAIST-2003.json": "NAIST-2003", |
| 2213 |
"NICTA-1.0.json": "NICTA-1", |
| 2214 |
} |
| 2215 |
for filename, expected in cases.items(): |
| 2216 |
self._open_license_and_check( |
| 2217 |
filename, self._find_licenses_matcher, expected |
| 2218 |
) |
| 2219 |
|
| 2220 |
def test_singletons_chunk6_cluster(self): |
| 2221 |
"""End-to-end detection for a further set of assorted single-file |
| 2222 |
permissive notices. OAR anchors on its organisation name (the grant |
| 2223 |
clause is shared with dtoa); Sendmail-Open-Source is the distinct |
| 2224 |
"SENDMAIL OPEN SOURCE LICENSE", separate from the BSD-ish Sendmail. |
| 2225 |
""" |
| 2226 |
cases = { |
| 2227 |
"OAR.json": "OAR", |
| 2228 |
"OFFIS.json": "OFFIS", |
| 2229 |
"OpenPBS-2.3.json": "OpenPBS-2.3", |
| 2230 |
"PADL.json": "PADL", |
| 2231 |
"pnmstitch.json": "pnmstitch", |
| 2232 |
"python-ldap.json": "python-ldap", |
| 2233 |
"Ruby-pty.json": "Ruby-pty", |
| 2234 |
"Sendmail-Open-Source-1.1.json": "Sendmail-Open-Source-1.1", |
| 2235 |
"SGMLUG-PM.json": "SGMLUG-PM", |
| 2236 |
"snprintf.json": "snprintf", |
| 2237 |
} |
| 2238 |
for filename, expected in cases.items(): |
| 2239 |
self._open_license_and_check( |
| 2240 |
filename, self._find_licenses_matcher, expected |
| 2241 |
) |
| 2242 |
|
| 2243 |
def test_singletons_chunk7_cluster(self): |
| 2244 |
"""End-to-end detection for a further set of assorted single-file |
| 2245 |
permissive notices. ThirdEye anchors on its organisation name because the |
| 2246 |
bare grant template is shared with MIPS. |
| 2247 |
""" |
| 2248 |
cases = { |
| 2249 |
"SOFA.json": "SOFA", |
| 2250 |
"softSurfer.json": "softSurfer", |
| 2251 |
"Soundex.json": "Soundex", |
| 2252 |
"TCP-wrappers.json": "TCP-wrappers", |
| 2253 |
"TekHVC.json": "TekHVC", |
| 2254 |
"TermReadKey.json": "TermReadKey", |
| 2255 |
"ThirdEye.json": "ThirdEye", |
| 2256 |
"TPDL.json": "TPDL", |
| 2257 |
"TrustedQSL.json": "TrustedQSL", |
| 2258 |
"TTWL.json": "TTWL", |
| 2259 |
} |
| 2260 |
for filename, expected in cases.items(): |
| 2261 |
self._open_license_and_check( |
| 2262 |
filename, self._find_licenses_matcher, expected |
| 2263 |
) |
| 2264 |
|
| 2265 |
def test_singletons_chunk8_cluster(self): |
| 2266 |
"""End-to-end detection for the final set of assorted single-file |
| 2267 |
permissive notices, each a standalone rule on a distinctive grant/title |
| 2268 |
clause. |
| 2269 |
""" |
| 2270 |
cases = { |
| 2271 |
"UnixCrypt.json": "UnixCrypt", |
| 2272 |
"URT-RLE.json": "URT-RLE", |
| 2273 |
"w3m.json": "w3m", |
| 2274 |
"Widget-Workshop.json": "Widget-Workshop", |
| 2275 |
"wwl.json": "wwl", |
| 2276 |
"Xdebug-1.03.json": "Xdebug-1.03", |
| 2277 |
"Xfig.json": "Xfig", |
| 2278 |
"xkeyboard-config-Zinoviev.json": "xkeyboard-config-Zinoviev", |
| 2279 |
"xzoom.json": "xzoom", |
| 2280 |
"Zeeff.json": "Zeeff", |
| 2281 |
} |
| 2282 |
for filename, expected in cases.items(): |
| 2283 |
self._open_license_and_check( |
| 2284 |
filename, self._find_licenses_matcher, expected |
| 2285 |
) |
| 2286 |
|
| 2287 |
def test_parse_gpl(self): |
| 2288 |
def _gpl_matcher(text): |
| 2289 |
return license_parsers.parse_gpl(licenses.clean_comments(text), None, "GPL") |
| 2290 |
|
| 2291 |
self._open_license_and_check( |
| 2292 |
"AGPL-1.0.json", |
| 2293 |
self._find_licenses_matcher, |
| 2294 |
"AGPL-1", |
| 2295 |
) |
| 2296 |
self._open_license_and_check_re( |
| 2297 |
"AGPL-3.0.json", |
| 2298 |
self._find_licenses_matcher, |
| 2299 |
r"AGPL-3\+?$", |
| 2300 |
) |
| 2301 |
self._open_license_and_check_re( |
| 2302 |
"GPL-1.0.json", |
| 2303 |
self._find_licenses_matcher, |
| 2304 |
r"GPL-1\+?$", |
| 2305 |
) |
| 2306 |
self._open_license_and_check( |
| 2307 |
"GPL-1.0+.json", |
| 2308 |
self._find_licenses_matcher, |
| 2309 |
"GPL-1+", |
| 2310 |
) |
| 2311 |
self._open_license_and_check_re( |
| 2312 |
"GPL-2.0.json", |
| 2313 |
self._find_licenses_matcher, |
| 2314 |
r"GPL-2\+?$", |
| 2315 |
) |
| 2316 |
self._open_license_and_check( |
| 2317 |
"GPL-2.0+.json", |
| 2318 |
self._find_licenses_matcher, |
| 2319 |
"GPL-2+", |
| 2320 |
) |
| 2321 |
self._open_license_and_check_re( |
| 2322 |
"GPL-3.0.json", |
| 2323 |
self._find_licenses_matcher, |
| 2324 |
r"GPL(?:-3\+?)?$", |
| 2325 |
) |
| 2326 |
self._open_license_and_check( |
| 2327 |
"GPL-3.0+.json", |
| 2328 |
self._find_licenses_matcher, |
| 2329 |
"GPL-3+", |
| 2330 |
) |
| 2331 |
|
| 2332 |
self._open_license_and_check( |
| 2333 |
"GPL-2.0-with-autoconf-exception.json", |
| 2334 |
_gpl_matcher, |
| 2335 |
"GPL with AutoConf exception", |
| 2336 |
) |
| 2337 |
self._open_license_and_check( |
| 2338 |
"GPL-2.0-with-bison-exception.json", |
| 2339 |
_gpl_matcher, |
| 2340 |
"GPL with Bison exception", |
| 2341 |
) |
| 2342 |
self._open_license_and_check( |
| 2343 |
"GPL-2.0-with-classpath-exception.json", |
| 2344 |
_gpl_matcher, |
| 2345 |
"GPL with ClassPath exception", |
| 2346 |
) |
| 2347 |
self._open_license_and_check( |
| 2348 |
"GPL-2.0-with-GCC-exception.json", |
| 2349 |
_gpl_matcher, |
| 2350 |
"GPL with GCC exception", |
| 2351 |
) |
| 2352 |
|
| 2353 |
self._open_license_and_check( |
| 2354 |
"GPL-3.0-with-autoconf-exception.json", |
| 2355 |
_gpl_matcher, |
| 2356 |
"GPL-3 with AutoConf-3 exception", |
| 2357 |
) |
| 2358 |
self._open_license_and_check( |
| 2359 |
"GPL-3.0-with-GCC-exception.json", |
| 2360 |
_gpl_matcher, |
| 2361 |
"GPL-3 with GCC-3.1 exception", |
| 2362 |
) |
| 2363 |
|
| 2364 |
self._open_exception_and_check( |
| 2365 |
"389-exception.json", |
| 2366 |
_gpl_matcher, |
| 2367 |
"GPL-2 with 389 exception", |
| 2368 |
) |
| 2369 |
|
| 2370 |
self._open_exception_and_check( |
| 2371 |
"Autoconf-exception-2.0.json", |
| 2372 |
_gpl_matcher, |
| 2373 |
"GPL with AutoConf exception", |
| 2374 |
) |
| 2375 |
self._open_exception_and_check( |
| 2376 |
"Autoconf-exception-3.0.json", |
| 2377 |
_gpl_matcher, |
| 2378 |
"GPL-3 with AutoConf-3 exception", |
| 2379 |
) |
| 2380 |
self._open_exception_and_check( |
| 2381 |
"Bison-exception-2.2.json", |
| 2382 |
_gpl_matcher, |
| 2383 |
"GPL with Bison exception", |
| 2384 |
) |
| 2385 |
self._open_exception_and_check( |
| 2386 |
"Classpath-exception-2.0.json", |
| 2387 |
_gpl_matcher, |
| 2388 |
"GPL with ClassPath exception", |
| 2389 |
) |
| 2390 |
self._open_exception_and_check( |
| 2391 |
"CLISP-exception-2.0.json", |
| 2392 |
_gpl_matcher, |
| 2393 |
"GPL-2 with CLISP exception", |
| 2394 |
) |
| 2395 |
self._open_exception_and_check( |
| 2396 |
"DigiRule-FOSS-exception.json", |
| 2397 |
_gpl_matcher, |
| 2398 |
"GPL with DigiRule-FOSS exception", |
| 2399 |
) |
| 2400 |
self._open_exception_and_check( |
| 2401 |
"eCos-exception-2.0.json", |
| 2402 |
_gpl_matcher, |
| 2403 |
"GPL with eCos-2 exception", |
| 2404 |
) |
| 2405 |
self._open_exception_and_check( |
| 2406 |
"Fawkes-Runtime-exception.json", |
| 2407 |
_gpl_matcher, |
| 2408 |
"GPL with ClassPath_MIF exception", |
| 2409 |
) |
| 2410 |
self._open_exception_and_check( |
| 2411 |
"FLTK-exception.json", |
| 2412 |
_gpl_matcher, |
| 2413 |
"GPL with FLTK exception", |
| 2414 |
) |
| 2415 |
self._open_exception_and_check( |
| 2416 |
"Font-exception-2.0.json", |
| 2417 |
_gpl_matcher, |
| 2418 |
"GPL with Font exception", |
| 2419 |
) |
| 2420 |
self._open_exception_and_check( |
| 2421 |
"freertos-exception-2.0.json", |
| 2422 |
_gpl_matcher, |
| 2423 |
"GPL with FreeRTOS exception", |
| 2424 |
) |
| 2425 |
self._open_exception_and_check( |
| 2426 |
"GCC-exception-2.0.json", |
| 2427 |
_gpl_matcher, |
| 2428 |
"GPL with GCC exception", |
| 2429 |
) |
| 2430 |
self._open_exception_and_check( |
| 2431 |
"GCC-exception-3.1.json", |
| 2432 |
_gpl_matcher, |
| 2433 |
"GPL-3 with GCC-3.1 exception", |
| 2434 |
) |
| 2435 |
self._open_exception_and_check( |
| 2436 |
"gnu-javamail-exception.json", |
| 2437 |
_gpl_matcher, |
| 2438 |
"GPL with GNU-JavaMail exception", |
| 2439 |
) |
| 2440 |
self._open_exception_and_check( |
| 2441 |
"i2p-gpl-java-exception.json", |
| 2442 |
_gpl_matcher, |
| 2443 |
"GPL with i2p-Java exception", |
| 2444 |
) |
| 2445 |
self._open_exception_and_check( |
| 2446 |
"Libtool-exception.json", |
| 2447 |
_gpl_matcher, |
| 2448 |
"GPL with LibTool exception", |
| 2449 |
) |
| 2450 |
self._open_exception_and_check( |
| 2451 |
"LZMA-exception.json", |
| 2452 |
_gpl_matcher, |
| 2453 |
"GPL with LZMA exception", |
| 2454 |
) |
| 2455 |
self._open_exception_and_check( |
| 2456 |
"mif-exception.json", |
| 2457 |
_gpl_matcher, |
| 2458 |
"GPL with MIF exception", |
| 2459 |
) |
| 2460 |
self._open_exception_and_check( |
| 2461 |
"Nokia-Qt-exception-1.1.json", |
| 2462 |
_gpl_matcher, |
| 2463 |
"GPL-2.1 with Qt1.1 exception", |
| 2464 |
) |
| 2465 |
self._open_exception_and_check( |
| 2466 |
"OCCT-exception-1.0.json", |
| 2467 |
_gpl_matcher, |
| 2468 |
"GPL-2.1 with OCCT-1 exception", |
| 2469 |
) |
| 2470 |
self._open_exception_and_check( |
| 2471 |
"openvpn-openssl-exception.json", |
| 2472 |
_gpl_matcher, |
| 2473 |
"GPL with openvpn-openssl exception", |
| 2474 |
) |
| 2475 |
# handled in the find licenses part |
| 2476 |
# TODO (maxy): fix me? |
| 2477 |
self._open_exception_and_check( |
| 2478 |
"Qwt-exception-1.0.json", |
| 2479 |
self._find_licenses_matcher, |
| 2480 |
"LGPL-2.1 with Qwt-1 exception", |
| 2481 |
) |
| 2482 |
self._open_exception_and_check( |
| 2483 |
"u-boot-exception-2.0.json", |
| 2484 |
_gpl_matcher, |
| 2485 |
"GPL with u-boot exception", |
| 2486 |
) |
| 2487 |
self._open_exception_and_check( |
| 2488 |
"WxWindows-exception-3.1.json", |
| 2489 |
_gpl_matcher, |
| 2490 |
"GPL with WxWindows-3.1+ exception", |
| 2491 |
) |
| 2492 |
|
| 2493 |
def test_parse_lgpl(self): |
| 2494 |
self._open_license_and_check_re( |
| 2495 |
"LGPL-2.0.json", |
| 2496 |
self._find_licenses_matcher, |
| 2497 |
r"LGPL-2\+?", |
| 2498 |
) |
| 2499 |
self._open_license_and_check( |
| 2500 |
"LGPL-2.0+.json", |
| 2501 |
self._find_licenses_matcher, |
| 2502 |
"LGPL-2+", |
| 2503 |
) |
| 2504 |
self._open_license_and_check_re( |
| 2505 |
"LGPL-2.1.json", |
| 2506 |
self._find_licenses_matcher, |
| 2507 |
r"LGPL-2.1\+?", |
| 2508 |
) |
| 2509 |
self._open_license_and_check( |
| 2510 |
"LGPL-2.1+.json", |
| 2511 |
self._find_licenses_matcher, |
| 2512 |
"LGPL-2.1+", |
| 2513 |
) |
| 2514 |
self._open_license_and_check( |
| 2515 |
"LGPL-3.0.json", |
| 2516 |
self._find_licenses_matcher, |
| 2517 |
# LGPL-3 is formally GPL-3 + additional permissions; the SPDX |
| 2518 |
# licenseText embeds the full GPL-3 text, so both groups fire. |
| 2519 |
"GPL-3+ or LGPL-3+", |
| 2520 |
) |
| 2521 |
self._open_license_and_check( |
| 2522 |
"LGPL-3.0+.json", |
| 2523 |
self._find_licenses_matcher, |
| 2524 |
"GPL-3+ or LGPL-3+", |
| 2525 |
) |
| 2526 |
self._open_license_and_check( |
| 2527 |
"LGPLLR.json", |
| 2528 |
self._find_licenses_matcher, |
| 2529 |
"LGPLLR", |
| 2530 |
) |
| 2531 |
|
| 2532 |
def test_lgpl_wxwindows_exception(self): |
| 2533 |
# Regression: old WXwindows.json had combined LGPL+exception text. |
| 2534 |
# The new SPDX data splits them; reconstruct the combination here. |
| 2535 |
import json |
| 2536 |
|
| 2537 |
lgpl_text = json.loads( |
| 2538 |
(Path("tests/testdata/licenses/LGPL-2.1.json")).read_text() |
| 2539 |
)["licenseText"] |
| 2540 |
wx_text = json.loads( |
| 2541 |
(Path("tests/testdata/exceptions/WxWindows-exception-3.1.json")).read_text() |
| 2542 |
)["licenseExceptionText"] |
| 2543 |
combined = lgpl_text + "\n\n" + wx_text |
| 2544 |
result = self._find_licenses_matcher(combined) |
| 2545 |
self.assertEqual(result, "LGPL-2.1+ with WxWindows-3.1+ exception") |
| 2546 |
|
| 2547 |
def test_parse_gfdl(self): |
| 2548 |
self._open_license_and_check( |
| 2549 |
"GFDL-1.1.json", |
| 2550 |
self._find_licenses_matcher, |
| 2551 |
"GFDL-1.1+", |
| 2552 |
ignore={"licenseText"}, |
| 2553 |
) |
| 2554 |
self._open_license_and_check( |
| 2555 |
"GFDL-1.2.json", |
| 2556 |
self._find_licenses_matcher, |
| 2557 |
"GFDL-NIV-1.2+", |
| 2558 |
) |
| 2559 |
self._open_license_and_check( |
| 2560 |
"GFDL-1.3.json", |
| 2561 |
self._find_licenses_matcher, |
| 2562 |
"GFDL-NIV-1.3+", |
| 2563 |
) |
| 2564 |
|
| 2565 |
def test_parse_lppl(self): |
| 2566 |
self._open_license_and_check( |
| 2567 |
"LPPL-1.0.json", |
| 2568 |
self._find_licenses_matcher, |
| 2569 |
"LPPL-1+", |
| 2570 |
) |
| 2571 |
self._open_license_and_check( |
| 2572 |
"LPPL-1.1.json", |
| 2573 |
self._find_licenses_matcher, |
| 2574 |
"LPPL-1.1+", |
| 2575 |
) |
| 2576 |
self._open_license_and_check( |
| 2577 |
"LPPL-1.2.json", |
| 2578 |
self._find_licenses_matcher, |
| 2579 |
"LPPL-1.2+", |
| 2580 |
) |
| 2581 |
# The titled licenseText carries the version letter (1.3a/1.3c); the |
| 2582 |
# standardLicenseHeader only references "version 1.3", so it is ignored. |
| 2583 |
self._open_license_and_check( |
| 2584 |
"LPPL-1.3a.json", |
| 2585 |
self._find_licenses_matcher, |
| 2586 |
"LPPL-1.3a+", |
| 2587 |
ignore={"standardLicenseHeader"}, |
| 2588 |
) |
| 2589 |
self._open_license_and_check( |
| 2590 |
"LPPL-1.3c.json", |
| 2591 |
self._find_licenses_matcher, |
| 2592 |
"LPPL-1.3c+", |
| 2593 |
ignore={"standardLicenseHeader"}, |
| 2594 |
) |
| 2595 |
|
| 2596 |
def test_parse_mit(self): |
| 2597 |
self._open_license_and_check("MIT.json", self._find_licenses_matcher, "Expat") |
| 2598 |
self._open_license_and_check( |
| 2599 |
"MIT-advertising.json", |
| 2600 |
self._find_licenses_matcher, |
| 2601 |
"MIT-advertising", |
| 2602 |
) |
| 2603 |
self._open_license_and_check( |
| 2604 |
"MIT-CMU.json", |
| 2605 |
self._find_licenses_matcher, |
| 2606 |
"MIT-CMU", |
| 2607 |
) |
| 2608 |
self._open_license_and_check( |
| 2609 |
"MIT-enna.json", |
| 2610 |
self._find_licenses_matcher, |
| 2611 |
"MIT-enna", |
| 2612 |
) |
| 2613 |
self._open_license_and_check( |
| 2614 |
"MIT-feh.json", |
| 2615 |
self._find_licenses_matcher, |
| 2616 |
"MIT-feh", |
| 2617 |
) |
| 2618 |
self._open_license_and_check( |
| 2619 |
"MITNFA.json", |
| 2620 |
self._find_licenses_matcher, |
| 2621 |
"MITNFA", |
| 2622 |
) |
| 2623 |
|
| 2624 |
def test_parse_zpl(self): |
| 2625 |
self._open_license_and_check( |
| 2626 |
"ZPL-1.1.json", |
| 2627 |
self._find_licenses_matcher, |
| 2628 |
"ZPL-1.1", |
| 2629 |
) |
| 2630 |
self._open_license_and_check( |
| 2631 |
"ZPL-2.0.json", |
| 2632 |
self._find_licenses_matcher, |
| 2633 |
"ZPL-2", |
| 2634 |
) |
| 2635 |
self._open_license_and_check( |
| 2636 |
"ZPL-2.1.json", |
| 2637 |
self._find_licenses_matcher, |
| 2638 |
"ZPL-2.1", |
| 2639 |
) |
| 2640 |
|
| 2641 |
|
| 2642 |
class TestDualLicenseHeader(unittest.TestCase): |
| 2643 |
"""Regression tests for dual-license header detection (e.g. cronexpr style). |
| 2644 |
|
| 2645 |
Files that list multiple licenses with a preamble like: |
| 2646 |
License: pick the one which suits you : |
| 2647 |
GPL v3 see <https://www.gnu.org/licenses/gpl.html> |
| 2648 |
APL v2 see <http://www.apache.org/licenses/LICENSE-2.0> |
| 2649 |
were not detected because the "License:? GPL" pattern requires GPL to |
| 2650 |
follow "License:" immediately, which fails when preamble text intervenes. |
| 2651 |
""" |
| 2652 |
|
| 2653 |
@staticmethod |
| 2654 |
def _find(text: str) -> set[str]: |
| 2655 |
return set(licenses.find_licenses(licenses.clean_comments(text))) |
| 2656 |
|
| 2657 |
def test_gpl_url_with_version_in_text(self): |
| 2658 |
# "GPL v3 see <gnu.org URL>" should detect GPL-3 |
| 2659 |
text = "/* License: GPL v3 see <https://www.gnu.org/licenses/gpl.html> */" |
| 2660 |
self.assertIn("GPL-3", self._find(text)) |
| 2661 |
|
| 2662 |
def test_apache_url_detects_version(self): |
| 2663 |
# Apache URL with License: prefix should detect Apache-2 |
| 2664 |
text = "/* License: APL v2 see <http://www.apache.org/licenses/LICENSE-2.0> */" |
| 2665 |
self.assertIn("Apache-2", self._find(text)) |
| 2666 |
|
| 2667 |
def test_dual_license_preamble_detects_both(self): |
| 2668 |
# Full dual-license header (cronexpr style) should detect both licenses |
| 2669 |
text = ( |
| 2670 |
"/*!\n" |
| 2671 |
" * License: pick the one which suits you :\n" |
| 2672 |
" * GPL v3 see <https://www.gnu.org/licenses/gpl.html>\n" |
| 2673 |
" * APL v2 see <http://www.apache.org/licenses/LICENSE-2.0>\n" |
| 2674 |
" */" |
| 2675 |
) |
| 2676 |
found = self._find(text) |
| 2677 |
self.assertIn("GPL-3", found) |
| 2678 |
self.assertIn("Apache-2", found) |
| 2679 |
|
| 2680 |
def test_dual_license_best_variant(self): |
| 2681 |
# "pick the one which suits you best:" variant (cronexpr_test.go) |
| 2682 |
text = ( |
| 2683 |
"/*!\n" |
| 2684 |
" * License: pick the one which suits you best:\n" |
| 2685 |
" * GPL v3 see <https://www.gnu.org/licenses/gpl.html>\n" |
| 2686 |
" * APL v2 see <http://www.apache.org/licenses/LICENSE-2.0>\n" |
| 2687 |
" */" |
| 2688 |
) |
| 2689 |
found = self._find(text) |
| 2690 |
self.assertIn("GPL-3", found) |
| 2691 |
self.assertIn("Apache-2", found) |
| 2692 |
|
| 2693 |
def test_gpl_v2_url_variant(self): |
| 2694 |
# GPL v2 referenced by versioned URL |
| 2695 |
text = "/* License: GPL v2 see <https://www.gnu.org/licenses/gpl-2.0.html> */" |
| 2696 |
self.assertIn("GPL-2", self._find(text)) |
| 2697 |
|
| 2698 |
def test_apache_url_https(self): |
| 2699 |
# HTTPS variant of Apache URL with License: prefix |
| 2700 |
text = "/* License: see <https://www.apache.org/licenses/LICENSE-2.0> */" |
| 2701 |
self.assertIn("Apache-2", self._find(text)) |
| 2702 |
|
| 2703 |
|
| 2704 |
if __name__ == "__main__": |
| 2705 |
unittest.main() |