Browse Source

Merge pull request #114 from fsfe/explicit-license-unsupported

Fix `addheader --explicit-license` to not break on unsupported files
tags/v0.6.0
carmenbianca 3 weeks ago
parent
commit
02842b9adb
No account linked to committer's email address
3 changed files with 42 additions and 1 deletions
  1. 2
    0
      CHANGELOG.md
  2. 1
    1
      src/reuse/header.py
  3. 39
    0
      tests/test_main.py

+ 2
- 0
CHANGELOG.md View File

@@ -43,6 +43,8 @@ The versions follow [semantic versioning](https://semver.org).

- Git submodules are now ignored by default.

- `addheader --explicit-license` now no longer breaks on unsupported filetypes.

## 0.5.2 - 2019-10-27

### Added

+ 1
- 1
src/reuse/header.py View File

@@ -424,7 +424,7 @@ def run(args, out=sys.stdout) -> int:
paths = [_determine_license_path(path) for path in args.path]

# First loop to verify before proceeding
if args.style is None:
if args.style is None and not args.explicit_license:
_verify_paths_supported(paths, args.parser)

project = create_project()

+ 39
- 0
tests/test_main.py View File

@@ -679,6 +679,45 @@ def test_addheader_explicit_license(
assert simple_file.read_text() == "pass"


def test_addheader_explicit_license_unsupported_filetype(
fake_repository, stringio, mock_date_today
):
"""Add a header to a .license file if --explicit-license is given, with the
base file being an otherwise unsupported filetype.
"""
# pylint: disable=unused-argument
simple_file = fake_repository / "foo.txt"
simple_file.write_text("Preserve this")

result = main(
[
"addheader",
"--license",
"GPL-3.0-or-later",
"--copyright",
"Mary Sue",
"--explicit-license",
"foo.txt",
],
out=stringio,
)

assert result == 0
assert (
simple_file.with_name(f"{simple_file.name}.license")
.read_text()
.strip()
== cleandoc(
"""
spdx-FileCopyrightText: 2018 Mary Sue

spdx-License-Identifier: GPL-3.0-or-later
"""
).replace("spdx", "SPDX")
)
assert simple_file.read_text() == "Preserve this"


def test_addheader_license_file(fake_repository, stringio, mock_date_today):
"""Add a header to a .license file if it exists."""
# pylint: disable=unused-argument

Loading…
Cancel
Save