|
3 | 3 | # SPDX-FileCopyrightText: 2023 Carmen Bianca BAKKER <[email protected]>
|
4 | 4 | # SPDX-FileCopyrightText: 2024 Skyler Grey <[email protected]>
|
5 | 5 | # SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
|
| 6 | +# SPDX-FileCopyrightText: 2024 Linnea Gräf |
6 | 7 | #
|
7 | 8 | # SPDX-License-Identifier: GPL-3.0-or-later
|
8 | 9 |
|
@@ -456,6 +457,91 @@ def test_reuse_info_of_copyright_xor_licensing(empty_directory):
|
456 | 457 | assert not bar_file_info.spdx_expressions
|
457 | 458 |
|
458 | 459 |
|
| 460 | +def test_reuse_info_of_reuse_toml_dot_license(empty_directory): |
| 461 | + """Test a corner case where there is REUSE information inside of a file, its |
| 462 | + .license file, and REUSE.toml. Only the REUSE information from the .license |
| 463 | + file and REUSE.toml should be applied to this file. |
| 464 | + """ |
| 465 | + (empty_directory / "REUSE.toml").write_text( |
| 466 | + cleandoc( |
| 467 | + """ |
| 468 | + version = 1 |
| 469 | +
|
| 470 | + [[annotations]] |
| 471 | + path = "*.py" |
| 472 | + precedence = "aggregate" |
| 473 | + SPDX-FileCopyrightText = "2017 Jane Doe" |
| 474 | + SPDX-License-Identifier = "CC0-1.0" |
| 475 | + """ |
| 476 | + ) |
| 477 | + ) |
| 478 | + (empty_directory / "foo.py").write_text( |
| 479 | + cleandoc( |
| 480 | + """ |
| 481 | + SPDX-FileCopyrightText: NONE |
| 482 | + """ |
| 483 | + ) |
| 484 | + ) |
| 485 | + (empty_directory / "foo.py.license").write_text( |
| 486 | + cleandoc( |
| 487 | + """ |
| 488 | + SPDX-FileCopyrightText: 2017 John Doe |
| 489 | + """ |
| 490 | + ) |
| 491 | + ) |
| 492 | + project = Project.from_directory(empty_directory) |
| 493 | + |
| 494 | + infos = project.reuse_info_of("foo.py") |
| 495 | + assert len(infos) == 2 |
| 496 | + toml_info = [info for info in infos if info.spdx_expressions][0] |
| 497 | + assert toml_info.source_type == SourceType.REUSE_TOML |
| 498 | + assert "2017 Jane Doe" in toml_info.copyright_lines |
| 499 | + assert "CC0-1.0" in str(toml_info.spdx_expressions) |
| 500 | + dot_license_info = [info for info in infos if not info.spdx_expressions][0] |
| 501 | + assert dot_license_info.source_type == SourceType.DOT_LICENSE |
| 502 | + assert ( |
| 503 | + "SPDX-FileCopyrightText: 2017 John Doe" |
| 504 | + in dot_license_info.copyright_lines |
| 505 | + ) |
| 506 | + assert not dot_license_info.spdx_expressions |
| 507 | + |
| 508 | + |
| 509 | +def test_reuse_info_of_dot_license_invalid_target(empty_directory): |
| 510 | + """file.license is an invalid target in REUSE.toml.""" |
| 511 | + (empty_directory / "REUSE.toml").write_text( |
| 512 | + cleandoc( |
| 513 | + """ |
| 514 | + version = 1 |
| 515 | +
|
| 516 | + [[annotations]] |
| 517 | + path = "foo.py.license" |
| 518 | + SPDX-FileCopyrightText = "2017 Jane Doe" |
| 519 | + SPDX-License-Identifier = "CC0-1.0" |
| 520 | + """ |
| 521 | + ) |
| 522 | + ) |
| 523 | + (empty_directory / "foo.py").write_text( |
| 524 | + cleandoc( |
| 525 | + """ |
| 526 | + SPDX-FileCopyrightText: 2017 John Doe |
| 527 | +
|
| 528 | + SPDX-License-Identifier: MIT |
| 529 | + """ |
| 530 | + ) |
| 531 | + ) |
| 532 | + (empty_directory / "foo.py.license").write_text( |
| 533 | + cleandoc( |
| 534 | + """ |
| 535 | + Empty |
| 536 | + """ |
| 537 | + ) |
| 538 | + ) |
| 539 | + project = Project.from_directory(empty_directory) |
| 540 | + |
| 541 | + infos = project.reuse_info_of("foo.py") |
| 542 | + assert len(infos) == 0 |
| 543 | + |
| 544 | + |
459 | 545 | def test_reuse_info_of_no_duplicates(empty_directory):
|
460 | 546 | """A file contains the same lines twice. The ReuseInfo only contains those
|
461 | 547 | lines once.
|
|
0 commit comments