1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
# SPDX-FileCopyrightText: 2017 Free Software Foundation Europe e.V. <https://fsfe.org>
# SPDX-FileCopyrightText: 2022 Carmen Bianca Bakker <carmenbianca@fsfe.org>
# SPDX-FileCopyrightText: 2022 Florian Snow <florian@familysnow.net>
# SPDX-FileCopyrightText: 2022 Nico Rikken <nico.rikken@fsfe.org>
# SPDX-FileCopyrightText: 2022 Pietro Albini <pietro.albini@ferrous-systems.com>
# SPDX-FileCopyrightText: 2024 Rivos Inc.
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Tests for reuse.copyright"""
import pytest
from reuse.copyright import make_copyright_line
# REUSE-IgnoreStart
def test_make_copyright_line_simple():
"""Given a simple statement, make it a copyright line."""
assert 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 (
make_copyright_line("hello", year="2019")
== "SPDX-FileCopyrightText: 2019 hello"
)
def test_make_copyright_line_prefix_spdx():
"""Given a simple statement and prefix, make it a copyright line."""
statement = make_copyright_line("hello", copyright_prefix="spdx")
assert statement == "SPDX-FileCopyrightText: hello"
def test_make_copyright_line_prefix_spdx_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line("hello", year=2019, copyright_prefix="spdx")
assert statement == "SPDX-FileCopyrightText: 2019 hello"
def test_make_copyright_line_prefix_spdx_c_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="spdx-c"
)
assert statement == "SPDX-FileCopyrightText: (C) 2019 hello"
def test_make_copyright_line_prefix_spdx_symbol_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="spdx-symbol"
)
assert statement == "SPDX-FileCopyrightText: © 2019 hello"
def test_make_copyright_line_prefix_string_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="string"
)
assert statement == "Copyright 2019 hello"
def test_make_copyright_line_prefix_string_c_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="string-c"
)
assert statement == "Copyright (C) 2019 hello"
def test_make_copyright_line_prefix_spdx_string_c_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="spdx-string-c"
)
assert statement == "SPDX-FileCopyrightText: Copyright (C) 2019 hello"
def test_make_copyright_line_prefix_spdx_string_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="spdx-string"
)
assert statement == "SPDX-FileCopyrightText: Copyright 2019 hello"
def test_make_copyright_line_prefix_spdx_string_symbol_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="spdx-string-symbol"
)
assert statement == "SPDX-FileCopyrightText: Copyright © 2019 hello"
def test_make_copyright_line_prefix_string_symbol_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="string-symbol"
)
assert statement == "Copyright © 2019 hello"
def test_make_copyright_line_prefix_symbol_year():
"""Given a simple statement, prefix and a year, make it a copyright line."""
statement = make_copyright_line(
"hello", year=2019, copyright_prefix="symbol"
)
assert statement == "© 2019 hello"
def test_make_copyright_line_existing_spdx_copyright():
"""Given a copyright line, do nothing."""
value = "SPDX-FileCopyrightText: hello"
assert make_copyright_line(value) == value
def test_make_copyright_line_existing_other_copyright():
"""Given a non-SPDX copyright line, do nothing."""
value = "© hello"
assert make_copyright_line(value) == value
def test_make_copyright_line_multine_error():
"""Given a multiline argument, expect an error."""
with pytest.raises(RuntimeError):
make_copyright_line("hello\nworld")
# REUSE-IgnoreEnd
|