From 6a4b4ceaa917f7bb2d298b460c5822c5a4866dd9 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 6 Oct 2026 14:08:32 -0400 Subject: [PATCH] Use `zip_expected_warnings()` where possible Remove some test code duplication by using this helper. Leave some areas of the code where using the helper would make the test code bigger. --- .../dependencies/test_use_cuda_wheels.py | 63 +- .../test_codeowners.py | 92 +-- .../rapids_pre_commit_hooks/test_copyright.py | 734 +++++++++--------- 3 files changed, 405 insertions(+), 484 deletions(-) diff --git a/tests/rapids_pre_commit_hooks/dependencies/test_use_cuda_wheels.py b/tests/rapids_pre_commit_hooks/dependencies/test_use_cuda_wheels.py index 28d7af8..ca4f114 100644 --- a/tests/rapids_pre_commit_hooks/dependencies/test_use_cuda_wheels.py +++ b/tests/rapids_pre_commit_hooks/dependencies/test_use_cuda_wheels.py @@ -17,6 +17,7 @@ from rapids_pre_commit_hooks_test_utils import ( find_yaml_node_for_span, parse_named_spans, + zip_expected_warnings, ) @@ -167,23 +168,9 @@ def test_handle_common( ) ) - assert linter.warnings == [ - lint.LintWarning( - warning_span["warning"], - warning["warning"], - notes=[ - lint.Note(note_span, note) - for note_span, note in zip( - warning_span.get("notes", []), - warning["notes"], - strict=True, - ) - ], - ) - for warning_span, warning in zip( - spans.get("warnings", []), expected_warnings, strict=True - ) - ] + assert linter.warnings == zip_expected_warnings( + spans.get("warnings", []), expected_warnings + ) @pytest.mark.parametrize( [ @@ -345,23 +332,9 @@ def test_handle_matrices_item( ) ) - assert linter.warnings == [ - lint.LintWarning( - warning_span["warning"], - warning["warning"], - notes=[ - lint.Note(note_span, note) - for note_span, note in zip( - warning_span.get("notes", []), - warning["notes"], - strict=True, - ) - ], - ) - for warning_span, warning in zip( - spans.get("warnings", []), expected_warnings, strict=True - ) - ] + assert linter.warnings == zip_expected_warnings( + spans.get("warnings", []), expected_warnings + ) def test_handle_matrix(self): content, spans = parse_named_spans( @@ -1028,25 +1001,9 @@ def test_check_use_cuda_wheels_integration(content, warnings): linter = lint.Linter("dependencies.yaml", content, "verify-dependencies") handler = UseCUDAWheelsHandler(linter, args) - expected_warnings = [ - lint.LintWarning( - warning_span["warning"], - warning["warning"], - notes=[ - lint.Note(note_span, note) - for note_span, note in zip( - warning_span.get("notes", []), - warning["notes"], - strict=True, - ) - ], - ) - for warning_span, warning in zip( - spans.get("warnings", []), warnings, strict=True - ) - ] - dependencies_yaml.traverse_root( handler, loader.document_anchors[0], set(), composed ) - assert linter.warnings == expected_warnings + assert linter.warnings == zip_expected_warnings( + spans.get("warnings", []), warnings + ) diff --git a/tests/rapids_pre_commit_hooks/test_codeowners.py b/tests/rapids_pre_commit_hooks/test_codeowners.py index bc73529..6161e9e 100644 --- a/tests/rapids_pre_commit_hooks/test_codeowners.py +++ b/tests/rapids_pre_commit_hooks/test_codeowners.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 from unittest.mock import Mock, patch @@ -6,8 +6,11 @@ import pytest from rapids_pre_commit_hooks import codeowners -from rapids_pre_commit_hooks.lint import Linter, LintWarning, Note, Replacement -from rapids_pre_commit_hooks_test_utils import parse_named_spans +from rapids_pre_commit_hooks.lint import Linter +from rapids_pre_commit_hooks_test_utils import ( + parse_named_spans, + zip_expected_warnings, +) MOCK_REQUIRED_CODEOWNERS_LINES = [ codeowners.RequiredCodeownersLine( @@ -143,13 +146,14 @@ def test_parse_codeowners_line(content, skip): """\ > CMakeLists.txt @someone-else # comment : ~~~~~~~~~~~~~~filename - : ~~~~~~~~~~~~~~warnings.0.span + : ~~~~~~~~~~~~~~warnings.0.warning : ~~~~~~~~~~~~~~warnings.0.replacements.0 : ^warnings.0.replacements.1 """, "rapidsai", [ { + "warning": "file 'CMakeLists.txt' has incorrect owners", "replacements": [ "", " @rapidsai/cudf-cmake-codeowners", @@ -162,12 +166,13 @@ def test_parse_codeowners_line(content, skip): """\ > CMakeLists.txt @someone-else @rapidsai/cudf-cmake-codeowners : ~~~~~~~~~~~~~~filename - : ~~~~~~~~~~~~~~warnings.0.span + : ~~~~~~~~~~~~~~warnings.0.warning : ~~~~~~~~~~~~~~warnings.0.replacements.0 """, "rapidsai", [ { + "warning": "file 'CMakeLists.txt' has incorrect owners", "replacements": [ "", ], @@ -197,13 +202,14 @@ def test_parse_codeowners_line(content, skip): """\ > CMakeLists.txt @rapidsai/cudf-cmake-codeowners : ~~~~~~~~~~~~~~filename - : ~~~~~~~~~~~~~~warnings.0.span + : ~~~~~~~~~~~~~~warnings.0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~warnings.0.replacements.0 : ^warnings.0.replacements.1 """, # noqa: E501 "NVIDIA", [ { + "warning": "file 'CMakeLists.txt' has incorrect owners", "replacements": [ "", " @NVIDIA/cudf-cmake-codeowners", @@ -225,12 +231,13 @@ def test_parse_codeowners_line(content, skip): """\ > pyproject.toml @rapidsai/ci-codeowners : ~~~~~~~~~~~~~~filename - : ~~~~~~~~~~~~~~warnings.0.span + : ~~~~~~~~~~~~~~warnings.0.warning : ^warnings.0.replacements.0 """, "NVIDIA", [ { + "warning": "file 'pyproject.toml' has incorrect owners", "replacements": [ " @NVIDIA/adi-ci-codeowners", ], @@ -243,25 +250,6 @@ def test_parse_codeowners_line(content, skip): @patch_required_codeowners_lines def test_check_codeowners_line(content, org, warnings): content, spans = parse_named_spans(content) - warnings = [ - LintWarning( - span=warning_spans["span"], - msg=f"file '{content[slice(*spans['filename'])]}'" - " has incorrect owners", - replacements=[ - Replacement(span=replacement_span, newtext=replacement) - for replacement, replacement_span in zip( - warning["replacements"], - warning_spans["replacements"], - strict=True, - ) - ], - ) - for warning, warning_spans in zip( - warnings, spans.get("warnings", []), strict=True - ) - ] - codeowners_line = codeowners.parse_codeowners_line(content, 0) linter = Linter(".github/CODEOWNERS", content, "verify-codeowners") found_files = [] @@ -271,7 +259,9 @@ def test_check_codeowners_line(content, org, warnings): codeowners_line, found_files, ) - assert linter.warnings == warnings + assert linter.warnings == zip_expected_warnings( + spans.get("warnings", []), warnings + ) assert found_files == [ (line, spans["filename"]) for line in MOCK_REQUIRED_CODEOWNERS_LINES @@ -295,14 +285,14 @@ def test_check_codeowners_line(content, org, warnings): """\ + + CMakeLists.txt @someone-else - : ~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~0.warning : ~~~~~~~~~~~~~~0.replacements.0 : ^0.replacements.1 + pyproject.toml @rapidsai/ci-codeowners """, [ { - "msg": "file 'CMakeLists.txt' has incorrect owners", + "warning": "file 'CMakeLists.txt' has incorrect owners", "notes": [], "replacements": [ "", @@ -315,13 +305,13 @@ def test_check_codeowners_line(content, org, warnings): pytest.param( """\ + - : ^0.span + : ^0.warning + pyproject.toml @rapidsai/ci-codeowners : ^0.replacements.0 """, [ { - "msg": "missing required codeowners", + "warning": "missing required codeowners", "notes": [], "replacements": [ "CMakeLists.txt @rapidsai/cudf-cmake-codeowners\n", @@ -333,13 +323,13 @@ def test_check_codeowners_line(content, org, warnings): pytest.param( """\ + - : ^0.span + : ^0.warning > pyproject.toml @rapidsai/ci-codeowners : ^0.replacements.0 """, [ { - "msg": "missing required codeowners", + "warning": "missing required codeowners", "notes": [], "replacements": [ "\nCMakeLists.txt @rapidsai/cudf-cmake-codeowners\n", @@ -352,13 +342,13 @@ def test_check_codeowners_line(content, org, warnings): """\ + + pyproject.toml @rapidsai/ci-codeowners - : ~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~0.warning + CMakeLists.txt @rapidsai/cudf-cmake-codeowners : ~~~~~~~~~~~~~~0.notes.0 """, [ { - "msg": "file 'pyproject.toml' should come after " + "warning": "file 'pyproject.toml' should come after " "'CMakeLists.txt'", "notes": [ "file 'CMakeLists.txt' is here", @@ -373,38 +363,8 @@ def test_check_codeowners_line(content, org, warnings): @patch_required_codeowners_lines def test_check_codeowners(content, warnings): content, spans = parse_named_spans(content, root_type=list) - warnings = [ - LintWarning( - span=warning_spans["span"], - msg=warning["msg"], - notes=[ - Note( - span=note_span, - msg=note, - ) - for note, note_span in zip( - warning["notes"], - warning_spans.get("notes", []), - strict=True, - ) - ], - replacements=[ - Replacement( - span=replacement_span, - newtext=replacement, - ) - for replacement, replacement_span in zip( - warning["replacements"], - warning_spans.get("replacements", []), - strict=True, - ) - ], - ) - for warning, warning_spans in zip(warnings, spans, strict=True) - ] - linter = Linter(".github/CODEOWNERS", content, "verify-codeowners") codeowners.check_codeowners( linter, Mock(org="rapidsai", project_prefix="cudf") ) - assert linter.warnings == warnings + assert linter.warnings == zip_expected_warnings(spans, warnings) diff --git a/tests/rapids_pre_commit_hooks/test_copyright.py b/tests/rapids_pre_commit_hooks/test_copyright.py index 149b111..15c85dd 100644 --- a/tests/rapids_pre_commit_hooks/test_copyright.py +++ b/tests/rapids_pre_commit_hooks/test_copyright.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # rapids-pre-commit-hooks: disable[verify-copyright] @@ -15,14 +15,11 @@ from freezegun import freeze_time from rapids_pre_commit_hooks import copyright -from rapids_pre_commit_hooks.lint import ( - Lines, - Linter, - LintWarning, - Note, - Replacement, +from rapids_pre_commit_hooks.lint import Lines, Linter +from rapids_pre_commit_hooks_test_utils import ( + parse_named_spans, + zip_expected_warnings, ) -from rapids_pre_commit_hooks_test_utils import parse_named_spans @pytest.mark.parametrize( @@ -995,7 +992,7 @@ def test_get_canonical_copyright_notice( "new_content", "spdx", "force_spdx", - "warning_messages_replacements_and_notes", + "expected_warnings", ], [ pytest.param( @@ -1005,20 +1002,20 @@ def test_get_canonical_copyright_notice( "file.txt", """\ > No copyright notice - : ^0.span + : ^0.warning : ^0.replacements.0 """, False, False, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ "# Copyright (c) 2024, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.\n\n", ], - [], - ), + "notes": [], + }, ], id="added-with-no-copyright-notice-plain-text", ), @@ -1040,20 +1037,20 @@ def test_get_canonical_copyright_notice( "file_with_history.txt", """\ > No copyright notice and changed - : ^0.span + : ^0.warning : ^0.replacements.0 """, False, False, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ "# Copyright (c) 2023-2024, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.\n\n", ], - [], - ), + "notes": [], + }, ], id="changed-with-history-and-no-copyright-notice", ), @@ -1109,21 +1106,21 @@ def test_get_canonical_copyright_notice( + + Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~0.span + : ~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 + This file has been changed """, # noqa: E501 False, False, [ - ( - "copyright is out of date", - [ + { + "warning": "copyright is out of date", + "replacements": [ "Copyright (c) 2023-2024, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [], - ), + "notes": [], + }, ], id="changed-with-no-copyright-update", ), @@ -1160,21 +1157,21 @@ def test_get_canonical_copyright_notice( + + Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~0.span + : ~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 + This file has been changed """, # noqa: E501 False, False, [ - ( - "copyright is out of date", - [ + { + "warning": "copyright is out of date", + "replacements": [ "Copyright (c) 2023-2024, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [], - ), + "notes": [], + }, ], id="added-with-out-of-date-copyright", ), @@ -1194,34 +1191,39 @@ def test_get_canonical_copyright_notice( """\ + + Copyright (c) 2021-2024 NVIDIA CORPORATION - : ~~~~~~~~~0.span + : ~~~~~~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 + Copyright (c) 2023 NVIDIA CORPORATION + Copyright (c) 2024 NVIDIA CORPORATION + Copyright (c) 2025 NVIDIA Corporation - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.replacements.0 + This file has not been changed """, False, False, [ - ( - "copyright is not out of date and should not be updated", - [ + { + "warning": ( + "copyright is not out of date and should " + "not be updated" + ), + "replacements": [ "Copyright (c) 2021-2023, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [], - ), - ( - "copyright notice does not match canonical notice", - [ + "notes": [], + }, + { + "warning": ( + "copyright notice does not match canonical notice" + ), + "replacements": [ "Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. " "All rights reserved.", ], - [], - ), + "notes": [], + }, ], id="unchanged-with-copyright-update", ), @@ -1260,21 +1262,21 @@ def test_get_canonical_copyright_notice( + + Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~0.span + : ~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 + This file has been changed """, # noqa: E501 False, False, [ - ( - "copyright is out of date", - [ + { + "warning": "copyright is out of date", + "replacements": [ "Copyright (c) 2023-2024, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [], - ), + "notes": [], + }, ], id="renamed-and-changed-with-no-copyright-update", ), @@ -1293,21 +1295,21 @@ def test_get_canonical_copyright_notice( + + Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~0.span + : ~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 + This file has been changed """, # noqa: E501 False, False, [ - ( - "copyright is out of date", - [ + { + "warning": "copyright is out of date", + "replacements": [ "Copyright (c) 2023-2024, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [], - ), + "notes": [], + }, ], id="copied-and-changed-with-no-copyright-update", ), @@ -1381,12 +1383,12 @@ def test_get_canonical_copyright_notice( : >0.notes.0 : >0.notes.1 + Copyright (c) 2021-2024 NVIDIA CORPORATION - : ~~~~~~~~~0.span + : ~~~~~~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 + Copyright (c) 2023 NVIDIA CORPORATION + Copyright (c) 2024 NVIDIA CORPORATION + Copyright (c) 2025 NVIDIA Corporation - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.replacements.0 + This file has not been changed : !0.notes.0 @@ -1395,28 +1397,33 @@ def test_get_canonical_copyright_notice( False, False, [ - ( - "copyright is not out of date and should not be updated", - [ + { + "warning": ( + "copyright is not out of date and should " + "not be updated" + ), + "replacements": [ "Copyright (c) 2021-2023, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [ + "notes": [ "file was renamed from 'file1.txt' and is assumed " "to share history with it", "change file contents if you want its copyright " "dates to only be determined by its own edit " "history", ], - ), - ( - "copyright notice does not match canonical notice", - [ + }, + { + "warning": ( + "copyright notice does not match canonical notice" + ), + "replacements": [ "Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. " "All rights reserved.", ], - [], - ), + "notes": [], + }, ], id="renamed-and-unchanged-with-copyright-update", ), @@ -1438,12 +1445,12 @@ def test_get_canonical_copyright_notice( : >0.notes.0 : >0.notes.1 + Copyright (c) 2021-2024 NVIDIA CORPORATION - : ~~~~~~~~~0.span + : ~~~~~~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 + Copyright (c) 2023 NVIDIA CORPORATION + Copyright (c) 2024 NVIDIA CORPORATION + Copyright (c) 2025 NVIDIA Corporation - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.replacements.0 + This file has not been changed : !0.notes.0 @@ -1452,28 +1459,33 @@ def test_get_canonical_copyright_notice( False, False, [ - ( - "copyright is not out of date and should not be updated", - [ + { + "warning": ( + "copyright is not out of date and should " + "not be updated" + ), + "replacements": [ "Copyright (c) 2021-2023, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [ + "notes": [ "file was copied from 'file1.txt' and is assumed " "to share history with it", "change file contents if you want its copyright " "dates to only be determined by its own edit " "history", ], - ), - ( - "copyright notice does not match canonical notice", - [ + }, + { + "warning": ( + "copyright notice does not match canonical notice" + ), + "replacements": [ "Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. " "All rights reserved.", ], - [], - ), + "notes": [], + }, ], id="copied-and-unchanged-with-copyright-update", ), @@ -1513,9 +1525,9 @@ def test_get_canonical_copyright_notice( """\ + + Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.warning : ^0.replacements.0 - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.warning : ^1.replacements.0 + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + This file has been changed @@ -1523,20 +1535,20 @@ def test_get_canonical_copyright_notice( True, False, [ - ( - "include SPDX-FileCopyrightText header", - [ + { + "warning": "include SPDX-FileCopyrightText header", + "replacements": [ "SPDX-FileCopyrightText: ", ], - [], - ), - ( - "no SPDX-License-Identifier header found", - [ + "notes": [], + }, + { + "warning": "no SPDX-License-Identifier header found", + "replacements": [ "\nSPDX-License-Identifier: Apache-2.0", ], - [], - ), + "notes": [], + }, ], id="spdx-changed-with-no-headers", ), @@ -1553,39 +1565,39 @@ def test_get_canonical_copyright_notice( """\ + + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~0.span + : ~~~~0.warning : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.replacements.0 - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.warning : ^1.replacements.0 - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~2.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~2.warning : ^2.replacements.0 + This file has been changed """, # noqa: E501 True, False, [ - ( - "copyright is out of date", - [ + { + "warning": "copyright is out of date", + "replacements": [ "Copyright (c) 2023-2024, NVIDIA CORPORATION & " "AFFILIATES. All rights reserved.", ], - [], - ), - ( - "include SPDX-FileCopyrightText header", - [ + "notes": [], + }, + { + "warning": "include SPDX-FileCopyrightText header", + "replacements": [ "SPDX-FileCopyrightText: ", ], - [], - ), - ( - "no SPDX-License-Identifier header found", - [ + "notes": [], + }, + { + "warning": "no SPDX-License-Identifier header found", + "replacements": [ "\nSPDX-License-Identifier: Apache-2.0", ], - [], - ), + "notes": [], + }, ], id="spdx-changed-with-no-headers-and-out-of-date-copyright", ), @@ -1604,20 +1616,20 @@ def test_get_canonical_copyright_notice( + + SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + SPDX-License-Identifier: BSD-3-Clause - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.warning : ~~~~~~~~~~~~0.replacements.0 + This file has been changed """, # noqa: E501 True, False, [ - ( - "SPDX-License-Identifier is incorrect", - [ + { + "warning": "SPDX-License-Identifier is incorrect", + "replacements": [ "Apache-2.0", ], - [], - ), + "notes": [], + }, ], id="spdx-changed-with-headers-and-incorrect-license-identifier", ), @@ -1655,9 +1667,9 @@ def test_get_canonical_copyright_notice( """\ + + // Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.warning : ^0.replacements.0 - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.warning : ^1.replacements.0 + // Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + // This file has not been changed @@ -1665,20 +1677,20 @@ def test_get_canonical_copyright_notice( False, True, [ - ( - "include SPDX-FileCopyrightText header", - [ + { + "warning": "include SPDX-FileCopyrightText header", + "replacements": [ "SPDX-FileCopyrightText: ", ], - [], - ), - ( - "no SPDX-License-Identifier header found", - [ + "notes": [], + }, + { + "warning": "no SPDX-License-Identifier header found", + "replacements": [ "\n// SPDX-License-Identifier: Apache-2.0", ], - [], - ), + "notes": [], + }, ], id="force-spdx-unchanged-with-comments-and-no-headers", ), @@ -1715,16 +1727,16 @@ def test_get_canonical_copyright_notice( "file1.txt", """\ + - : ^0.span + : ^0.warning : ^0.replacements.0 + This file has not been changed """, False, True, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ dedent( """\ # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. @@ -1732,8 +1744,8 @@ def test_get_canonical_copyright_notice( """ # noqa: E501 ), ], - [], - ), + "notes": [], + }, ], id="force-spdx-unchanged-with-no-copyright", ), @@ -1751,7 +1763,7 @@ def test_get_canonical_copyright_notice( """\ + + /* SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.warning : ^0.replacements.0 + */ + This file has been changed @@ -1759,13 +1771,13 @@ def test_get_canonical_copyright_notice( True, False, [ - ( - "no SPDX-License-Identifier header found", - [ + { + "warning": "no SPDX-License-Identifier header found", + "replacements": [ "\n * SPDX-License-Identifier: Apache-2.0", ], - [], - ), + "notes": [], + }, ], id="spdx-changed-with-c-style-comments-and-no-license-header", ), @@ -1819,7 +1831,7 @@ def test_get_canonical_copyright_notice( + # SPDX-License-Identifier: Apache-2.0 : >0.replacements.0 + # - : >0.span + : >0.warning + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at @@ -1832,19 +1844,19 @@ def test_get_canonical_copyright_notice( + # See the License for the specific language governing permissions and + # limitations under the License. : !0.replacements.0 - : !0.span + : !0.warning + This file has not been changed """, # noqa: E501 False, True, [ - ( - "remove long-form copyright text", - [ + { + "warning": "remove long-form copyright text", + "replacements": [ "", ], - [], - ), + "notes": [], + }, ], id="force-spdx-with-headers-and-long-form-text", ), @@ -1873,11 +1885,11 @@ def test_get_canonical_copyright_notice( """\ + + # SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.warning : ^0.replacements.0 : >1.replacements.0 + # - : >1.span + : >1.warning + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at @@ -1889,27 +1901,27 @@ def test_get_canonical_copyright_notice( + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. - : !1.span + : !1.warning : !1.replacements.0 + This file has not been changed """, # noqa: E501 False, True, [ - ( - "no SPDX-License-Identifier header found", - [ + { + "warning": "no SPDX-License-Identifier header found", + "replacements": [ "\n# SPDX-License-Identifier: Apache-2.0", ], - [], - ), - ( - "remove long-form copyright text", - [ + "notes": [], + }, + { + "warning": "remove long-form copyright text", + "replacements": [ "", ], - [], - ), + "notes": [], + }, ], id="force-spdx-unchanged-with-no-headers-and-long-form-text", ), @@ -1938,11 +1950,11 @@ def test_get_canonical_copyright_notice( """\ + + # SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.span + : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0.warning : ^0.replacements.0 : >1.replacements.0 + # - : >1.span + : >1.warning + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at @@ -1954,27 +1966,27 @@ def test_get_canonical_copyright_notice( + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. - : !1.span + : !1.warning : !1.replacements.0 + This file has been changed """, # noqa: E501 False, True, [ - ( - "no SPDX-License-Identifier header found", - [ + { + "warning": "no SPDX-License-Identifier header found", + "replacements": [ "\n# SPDX-License-Identifier: Apache-2.0", ], - [], - ), - ( - "remove long-form copyright text", - [ + "notes": [], + }, + { + "warning": "remove long-form copyright text", + "replacements": [ "", ], - [], - ), + "notes": [], + }, ], id="force-spdx-changed-with-no-identifier-and-long-form-text", ), @@ -2007,15 +2019,15 @@ def test_get_canonical_copyright_notice( "file_with_history.txt", """\ > No copyright notice - : ^0.span + : ^0.warning : ^0.replacements.0 """, False, True, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ dedent( """\ # SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. @@ -2024,8 +2036,8 @@ def test_get_canonical_copyright_notice( """ # noqa: E501 ), ], - [], - ), + "notes": [], + }, ], id="force-spdx-unchanged-with-history-and-no-copyright-notice", ), @@ -2036,16 +2048,16 @@ def test_get_canonical_copyright_notice( "file.sh", """\ + #!/bin/sh - : ^0.span + : ^0.warning > No copyright notice : ^0.replacements.0 """, True, False, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ dedent( """\ # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. @@ -2054,8 +2066,8 @@ def test_get_canonical_copyright_notice( """ # noqa: E501 ), ], - [], - ), + "notes": [], + }, ], id="spdx-added-with-no-copyright-notice-shebang", ), @@ -2066,7 +2078,7 @@ def test_get_canonical_copyright_notice( "file.sh", """\ + #!/bin/sh - : ^0.span + : ^0.warning + : ^0.replacements.0 > No copyright notice @@ -2074,9 +2086,9 @@ def test_get_canonical_copyright_notice( True, False, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ dedent( """\ # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. @@ -2084,8 +2096,8 @@ def test_get_canonical_copyright_notice( """ # noqa: E501 ), ], - [], - ), + "notes": [], + }, ], id="spdx-added-with-no-copyright-notice-shebang-second-line-blank", ), @@ -2096,15 +2108,15 @@ def test_get_canonical_copyright_notice( "file.sh", """\ + #!/bin/sh - : ^0.span + : ^0.warning : ^0.replacements.0 """, True, False, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ dedent( """\ # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. @@ -2112,8 +2124,8 @@ def test_get_canonical_copyright_notice( """ # noqa: E501 ), ], - [], - ), + "notes": [], + }, ], id="spdx-added-with-no-copyright-notice-shebang-no-contents", ), @@ -2124,15 +2136,15 @@ def test_get_canonical_copyright_notice( "file.bat", """\ > No copyright notice - : ^0.span + : ^0.warning : ^0.replacements.0 """, True, False, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ dedent( """\ REM SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. @@ -2141,8 +2153,8 @@ def test_get_canonical_copyright_notice( """ # noqa: E501 ), ], - [], - ), + "notes": [], + }, ], id="spdx-added-with-no-copyright-notice-batch-file", ), @@ -2153,15 +2165,15 @@ def test_get_canonical_copyright_notice( "file.xml", """\ > No copyright notice - : ^0.span + : ^0.warning : ^0.replacements.0 """, True, False, [ - ( - "no copyright notice found", - [ + { + "warning": "no copyright notice found", + "replacements": [ dedent( """\