Skip to content

Commit

Permalink
--style should work with unrecognised files
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <carmenbianca@fsfe.org>
  • Loading branch information
carmenbianca committed Apr 8, 2024
1 parent 2f31927 commit 8b2282e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/reuse/_annotate.py
Expand Up @@ -342,11 +342,13 @@ def verify_write_access(


def verify_paths_comment_style(args: Namespace, paths: Iterable[Path]) -> None:
"""Exit if --fallback-dot-license or --skip-unrecognised is not enabled and
one of the paths has an unrecognised style.
"""Exit if --style, --force-dot-license, --fallback-dot-license,
or --skip-unrecognised is not enabled and one of the paths has an
unrecognised style.
"""
if (
not args.fallback_dot_license
not args.style
and not args.fallback_dot_license
and not args.skip_unrecognised
and not args.force_dot_license
):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_main_annotate.py
Expand Up @@ -452,6 +452,31 @@ def test_annotate_specify_style(fake_repository, stringio, mock_date_today):
assert simple_file.read_text() == expected


def test_annotate_specify_style_unrecognised(
fake_repository, stringio, mock_date_today
):
"""Add a header to a file that is unrecognised."""

simple_file = fake_repository / "hello.foo"
simple_file.touch()
expected = "# SPDX-FileCopyrightText: 2018 Jane Doe"

result = main(
[
"annotate",
"--copyright",
"Jane Doe",
"--style",
"python",
"hello.foo",
],
out=stringio,
)

assert result == 0
assert simple_file.read_text().strip() == expected


def test_annotate_implicit_style(fake_repository, stringio, mock_date_today):
"""Add a header to a file that has a recognised extension."""
simple_file = fake_repository / "foo.js"
Expand Down

0 comments on commit 8b2282e

Please sign in to comment.