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}
def test_extract_copyright(): """Given a file with copyright information, have it return that copyright information. """ copyright = "2019 Jane Doe" result = _util.extract_spdx_info("SPDX-Copyright: {}".format(copyright)) assert result.copyright_lines == {copyright}
def test_extract_copyright(): """Given a file with copyright information, have it return that copyright information. """ copyright_line = "SPDX" + "-FileCopyrightText: 2019 Jane Doe" result = _util.extract_spdx_info(copyright_line) assert result.copyright_lines == {copyright_line}
def test_extract_expression(): """Parse various expressions.""" expressions = ["GPL-3.0+", "GPL-3.0 AND CC0-1.0", "nonsense"] for expression in expressions: result = _util.extract_spdx_info("SPDX" + f"-License-Identifier: {expression}") assert result.spdx_expressions == {_LICENSING.parse(expression)}
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_extract_copyright_variations(): """There are multiple ways to declare copyright. All should be detected.""" text = cleandoc(""" SPDX-FileCopyrightText: 2019 Jane Doe SPDX-FileCopyrightText: © 2019 Jane Doe © 2019 Jane Doe Copyright © 2019 Jane Doe Copyright 2019 Jane Doe Copyright (C) 2019 Jane Doe """) result = _util.extract_spdx_info(text) lines = text.splitlines() for line in lines: assert line in result.copyright_lines assert len(lines) == len(result.copyright_lines)
def test_extract_copyright_duplicate(): """When a copyright line is duplicated, only yield one.""" copyright = "2019 Jane Doe" result = _util.extract_spdx_info("SPDX-Copyright: {}\n".format(copyright) * 2) assert result.copyright_lines == {copyright}
def test_extract_no_info(): """Given a file without SPDX information, return an empty SpdxInfo object. """ result = _util.extract_spdx_info("") assert result == _util.SpdxInfo(set(), set())
def test_extract_erroneous_expression(): """Parse an incorrect expression.""" expression = "SPDX" "-License-Identifier: GPL-3.0-or-later AND (MIT OR)" with pytest.raises(ParseError): _util.extract_spdx_info(expression)
def test_extract_copyright_tab(): """A tag followed by a tab is also valid.""" copyright = "SPDX" "-FileCopyrightText:\t2019 Jane Doe" result = _util.extract_spdx_info(copyright) assert result.copyright_lines == {copyright}
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}
def test_extract_bibtex_comment(): """A special case for BibTex comments.""" 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"
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") assert result.spdx_expressions == {_LICENSING.parse("MIT")}
def test_extract_tab(): """A tag followed by a tab is also valid.""" result = _util.extract_spdx_info("SPDX" "-License-Identifier:\tMIT") assert result.spdx_expressions == {_LICENSING.parse("MIT")}