@@ -1,5 +1,8 @@
# SPDX-FileCopyrightText: 2017 Free Software Foundation Europe e.V. <https://fsfe.org>
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
# SPDX-FileCopyrightText: 2022 Nico Rikken <nico.rikken@fsfe.org>
# SPDX-FileCopyrightText: 2022 Florian Snow <florian@familysnow.net>
# SPDX-FileCopyrightText: 2022 Carmen Bianca Bakker <carmenbianca@fsfe.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
Expand Down
Expand Up
@@ -40,14 +43,14 @@ def test_extract_expression():
expressions = ["GPL-3.0+" , "GPL-3.0 AND CC0-1.0" , "nonsense" ]
for expression in expressions :
result = _util .extract_spdx_info (
"SPDX" "-License-Identifier: {}" . format ( expression )
"SPDX" + f "-License-Identifier: { expression } "
)
assert result .spdx_expressions == {_LICENSING .parse (expression )}
def test_extract_erroneous_expression ():
"""Parse an incorrect expression."""
expression = "SPDX" "-License-Identifier: GPL-3.0-or-later AND (MIT OR)"
expression = "SPDX" + "-License-Identifier: GPL-3.0-or-later AND (MIT OR)"
with pytest .raises (ParseError ):
_util .extract_spdx_info (expression )
Expand All
@@ -62,21 +65,21 @@ def test_extract_no_info():
def test_extract_tab ():
"""A tag followed by a tab is also valid."""
result = _util .extract_spdx_info ("SPDX" "-License-Identifier:\t MIT" )
result = _util .extract_spdx_info ("SPDX" + "-License-Identifier:\t MIT" )
assert result .spdx_expressions == {_LICENSING .parse ("MIT" )}
def test_extract_many_whitespace ():
"""When a tag is followed by a lot of whitespace, the whitespace should be
filtered out.
"""
result = _util .extract_spdx_info ("SPDX" "-License-Identifier: MIT" )
result = _util .extract_spdx_info ("SPDX" + "-License-Identifier: MIT" )
assert result .spdx_expressions == {_LICENSING .parse ("MIT" )}
def test_extract_bibtex_comment ():
"""A special case for BibTex comments."""
expression = "@Comment{SPDX" "-License-Identifier: GPL-3.0-or-later}"
expression = "@Comment{SPDX" + "-License-Identifier: GPL-3.0-or-later}"
result = _util .extract_spdx_info (expression )
assert str (list (result .spdx_expressions )[0 ]) == "GPL-3.0-or-later"
Expand All
@@ -85,32 +88,34 @@ def test_extract_copyright():
"""Given a file with copyright information, have it return that copyright
information.
"""
copyright = "SPDX" "-FileCopyrightText: 2019 Jane Doe"
result = _util .extract_spdx_info (copyright )
assert result .copyright_lines == {copyright }
copyright_line = "SPDX" + "-FileCopyrightText: 2019 Jane Doe"
result = _util .extract_spdx_info (copyright_line )
assert result .copyright_lines == {copyright_line }
def test_extract_copyright_duplicate ():
"""When a copyright line is duplicated, only yield one."""
copyright = "SPDX" "-FileCopyrightText: 2019 Jane Doe"
result = _util .extract_spdx_info ("\n " .join ((copyright , copyright )))
assert result .copyright_lines == {copyright }
copyright_line = "SPDX" + "-FileCopyrightText: 2019 Jane Doe"
result = _util .extract_spdx_info (
"\n " .join ((copyright_line , copyright_line ))
)
assert result .copyright_lines == {copyright_line }
def test_extract_copyright_tab ():
"""A tag followed by a tab is also valid."""
copyright = "SPDX" "-FileCopyrightText:\t 2019 Jane Doe"
result = _util .extract_spdx_info (copyright )
assert result .copyright_lines == {copyright }
copyright_line = "SPDX" + "-FileCopyrightText:\t 2019 Jane Doe"
result = _util .extract_spdx_info (copyright_line )
assert result .copyright_lines == {copyright_line }
def test_extract_copyright_many_whitespace ():
"""When a tag is followed by a lot of whitespace, that is also valid. The
whitespace is not filtered out.
"""
copyright = "SPDX" "-FileCopyrightText: 2019 Jane Doe"
result = _util .extract_spdx_info (copyright )
assert result .copyright_lines == {copyright }
copyright_line = "SPDX" + "-FileCopyrightText: 2019 Jane Doe"
result = _util .extract_spdx_info (copyright_line )
assert result .copyright_lines == {copyright_line }
def test_extract_copyright_variations ():
Expand All
@@ -133,26 +138,213 @@ def test_extract_copyright_variations():
assert len (lines ) == len (result .copyright_lines )
def test_copyright_from_dep5 (copyright ):
def test_extract_with_ignore_block ():
"""Ensure that the copyright and licensing information inside the ignore
block is actually ignored.
"""
text = cleandoc (
"""
SPDX-FileCopyrightText: 2019 Jane Doe
SPDX-License-Identifier: CC0-1.0
REUSE-IgnoreStart
SPDX-FileCopyrightText: 2019 John Doe
SPDX-License-Identifier: GPL-3.0-or-later
REUSE-IgnoreEnd
SPDX-FileCopyrightText: 2019 Eve
"""
)
result = _util .extract_spdx_info (text )
assert len (result .copyright_lines ) == 2
assert len (result .spdx_expressions ) == 1
def test_filter_ignore_block_with_comment_style ():
"""Test that the ignore block is properly removed if start and end markers
are in comment style.
"""
text = cleandoc (
"""
Relevant text
# REUSE-IgnoreStart
Ignored text
# REUSE-IgnoreEnd
Other relevant text
"""
)
expected = "Relevant text\n # \n Other relevant text"
result = _util .filter_ignore_block (text )
assert result == expected
def test_filter_ignore_block_non_comment_style ():
"""Test that the ignore block is properly removed if start and end markers
are not comment style.
"""
text = cleandoc (
"""
Relevant text
REUSE-IgnoreStart
Ignored text
REUSE-IgnoreEnd
Other relevant text
"""
)
expected = cleandoc (
"""
Relevant text
Other relevant text
"""
)
result = _util .filter_ignore_block (text )
assert result == expected
def test_filter_ignore_block_with_ignored_information_on_same_line ():
"""Test that the ignore block is properly removed if there is information to
be ignored on the same line.
"""
text = cleandoc (
"""
Relevant text
REUSE-IgnoreStart Copyright me
Ignored text
sdojfsdREUSE-IgnoreEnd
Other relevant text
"""
)
expected = cleandoc (
"""
Relevant text
Other relevant text
"""
)
result = _util .filter_ignore_block (text )
assert result == expected
def test_filter_ignore_block_with_relevant_information_on_same_line ():
"""Test that the ignore block is properly removed if it has relevant
information on the same line.
"""
text = cleandoc (
"""
Relevant textREUSE-IgnoreStart
Ignored text
REUSE-IgnoreEndOther relevant text
"""
)
expected = "Relevant textOther relevant text"
result = _util .filter_ignore_block (text )
assert result == expected
def test_filter_ignore_block_with_beginning_and_end_on_same_line_correct_order (): # pylint: disable=line-too-long
"""Test that the ignore block is properly removed if it has relevant
information on the same line.
"""
text = cleandoc (
"""
Relevant textREUSE-IgnoreStartIgnored textREUSE-IgnoreEndOther
relevant text
"""
)
expected = cleandoc (
"""
Relevant textOther
relevant text
"""
)
result = _util .filter_ignore_block (text )
assert result == expected
def test_filter_ignore_block_with_beginning_and_end_on_same_line_wrong_order ():
"""Test that the ignore block is properly removed if it has relevant
information on the same line.
"""
text = "Relevant textREUSE-IgnoreEndOther relevant textREUSE-IgnoreStartIgnored text" # pylint: disable=line-too-long
expected = "Relevant textREUSE-IgnoreEndOther relevant text"
result = _util .filter_ignore_block (text )
assert result == expected
def test_filter_ignore_block_without_end ():
"""Test that the ignore block is properly removed if it has relevant
information on the same line.
"""
text = cleandoc (
"""
Relevant text
REUSE-IgnoreStart
Ignored text
Other ignored text
"""
)
expected = "Relevant text\n "
result = _util .filter_ignore_block (text )
assert result == expected
def test_filter_ignore_block_with_multiple_ignore_blocks ():
"""Test that the ignore block is properly removed if it has relevant
information on the same line.
"""
text = cleandoc (
"""
Relevant text
REUSE-IgnoreStart
Ignored text
REUSE-IgnoreEnd
Other relevant text
REUSE-IgnoreStart
Other ignored text
REUSE-IgnoreEnd
Even more relevant text
"""
)
expected = cleandoc (
"""
Relevant text
Other relevant text
Even more relevant text
"""
)
result = _util .filter_ignore_block (text )
assert result == expected
def test_copyright_from_dep5 (dep5_copyright ):
"""Verify that the glob in the dep5 file is matched."""
result = _util ._copyright_from_dep5 ("doc/foo.rst" , copyright )
result = _util ._copyright_from_dep5 ("doc/foo.rst" , dep5_copyright )
assert LicenseSymbol ("CC0-1.0" ) in result .spdx_expressions
assert "2017 Mary Sue " in result .copyright_lines
assert "2017 Jane Doe " in result .copyright_lines
def test_make_copyright_line_simple ():
"""Given a simple statement, make it a copyright line."""
assert (
_util .make_copyright_line ("hello" ) == "SPDX"
"-FileCopyrightText: hello"
_util .make_copyright_line ("hello" )
== "SPDX" + "-FileCopyrightText: hello"
)
def test_make_copyright_line_year ():
"""Given a simple statement and a year, make it a copyright line."""
assert (
_util .make_copyright_line ("hello" , year = "2019" ) == "SPDX"
"-FileCopyrightText: 2019 hello"
_util .make_copyright_line ("hello" , year = "2019" )
== "SPDX" + "-FileCopyrightText: 2019 hello"
)
Expand Down
Expand Up
@@ -212,7 +404,7 @@ def test_make_copyright_line_style_symbol_year():
def test_make_copyright_line_existing_spdx_copyright ():
"""Given a copyright line, do nothing."""
value = "SPDX" "-FileCopyrightText: hello"
value = "SPDX" + "-FileCopyrightText: hello"
assert _util .make_copyright_line (value ) == value
Expand All
@@ -223,7 +415,7 @@ def test_make_copyright_line_existing_other_copyright():
def test_make_copyright_line_multine_error ():
"""Given a multiline arguement , expect an error."""
"""Given a multiline argument , expect an error."""
with pytest .raises (RuntimeError ):
_util .make_copyright_line ("hello\n world" )
Expand Down