Skip to content

Commit

Permalink
Add merge test against all copyright prefixes
Browse files Browse the repository at this point in the history
Co-Authored-By: sudorook
Signed-off-by: Carmen Bianca BAKKER <carmenbianca@fsfe.org>
  • Loading branch information
carmenbianca committed Jul 23, 2024
1 parent 4dd63e6 commit 2538a66
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/reuse/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@
_COPYRIGHT_PATTERNS = [
re.compile(
r"(?P<copyright>(?P<prefix>SPDX-(File|Snippet)CopyrightText:"
r"(\s(\(C\)|Copyright\s(©|\(C\))?|©)?)?)\s+"
r"(\s(\([Cc]\)|©|Copyright(\s(©|\([Cc]\)))?))?)\s+"
r"((?P<year>\d{4} ?- ?\d{4}|\d{4}),?\s+)?"
r"(?P<statement>.*?))" + _END_PATTERN
),
re.compile(
r"(?P<copyright>(?P<prefix>Copyright(\s?\([cC]\))?)\s+"
r"(?P<copyright>(?P<prefix>Copyright(\s(\([Cc]\)|©))?)\s+"
r"((?P<year>\d{4} ?- ?\d{4}|\d{4}),?\s+)?"
r"(?P<statement>.*?))" + _END_PATTERN
),
Expand Down
66 changes: 66 additions & 0 deletions tests/test_main_annotate_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from inspect import cleandoc

from reuse._main import main
from reuse._util import _COPYRIGHT_PREFIXES

# pylint: disable=unused-argument

Expand Down Expand Up @@ -191,4 +192,69 @@ def test_annotate_merge_copyrights_no_year_in_existing(
)


def test_annotate_merge_copyrights_all_prefixes(
fake_repository, stringio, mock_date_today
):
"""Test that merging works for all copyright prefixes."""
# TODO: there should probably also be a test for mixing copyright prefixes,
# but this behaviour is really unpredictable to me at the moment, and the
# whole copyright-line-as-string thing needs overhauling.
simple_file = fake_repository / "foo.py"
for copyright_prefix, copyright_string in _COPYRIGHT_PREFIXES.items():
simple_file.write_text("pass")
result = main(
[
"annotate",
"--year",
"2016",
"--license",
"GPL-3.0-or-later",
"--copyright",
"Jane Doe",
"--copyright-style",
copyright_prefix,
"--merge-copyrights",
"foo.py",
],
out=stringio,
)
assert result == 0
assert simple_file.read_text(encoding="utf-8") == cleandoc(
f"""
# {copyright_string} 2016 Jane Doe
#
# SPDX-License-Identifier: GPL-3.0-or-later
pass
"""
)

result = main(
[
"annotate",
"--year",
"2018",
"--license",
"GPL-3.0-or-later",
"--copyright",
"Jane Doe",
"--copyright-style",
copyright_prefix,
"--merge-copyrights",
"foo.py",
],
out=stringio,
)
assert result == 0
assert simple_file.read_text(encoding="utf-8") == cleandoc(
f"""
# {copyright_string} 2016 - 2018 Jane Doe
#
# SPDX-License-Identifier: GPL-3.0-or-later
pass
"""
)


# REUSE-IgnoreEnd

0 comments on commit 2538a66

Please sign in to comment.