From 3d03b09bd1ae6a6a175b68da83a012f6137898d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Fri, 23 Feb 2024 12:09:40 +0100 Subject: [PATCH] Change: Remove copyright_regex from update_header function The update_header function just expect a year, license and company name at the end. --- pontos/updateheader/updateheader.py | 9 +++------ tests/updateheader/test_header.py | 26 +++----------------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/pontos/updateheader/updateheader.py b/pontos/updateheader/updateheader.py index 16575781d..dd1bb89b9 100644 --- a/pontos/updateheader/updateheader.py +++ b/pontos/updateheader/updateheader.py @@ -145,7 +145,6 @@ def update_file( year: str, license_id: str, company: str, - copyright_regex: re.Pattern, cleanup_regexes: Optional[List[re.Pattern]] = None, ) -> None: """Function to update the header of the given file @@ -153,6 +152,9 @@ def update_file( Checks if header exists. If not it adds an header to that file, otherwise it checks if year is up to date """ + + copyright_regex = _compile_copyright_regex(company=[company, OLD_COMPANY]) + try: with file.open("r+") as fp: found = False @@ -341,10 +343,6 @@ def main() -> None: term.error("Specify files to update!") sys.exit(1) - copyright_regex: re.Pattern = _compile_copyright_regex( - company=[parsed_args.company, OLD_COMPANY] - ) - cleanup_regexes: Optional[List[re.Pattern]] = None if cleanup: cleanup_regexes = _compile_outdated_regex() @@ -368,7 +366,6 @@ def main() -> None: year, license_id, company, - copyright_regex, cleanup_regexes, ) except (FileNotFoundError, UnicodeDecodeError, ValueError): diff --git a/tests/updateheader/test_header.py b/tests/updateheader/test_header.py index f1366fbe1..f9eabfd61 100644 --- a/tests/updateheader/test_header.py +++ b/tests/updateheader/test_header.py @@ -4,7 +4,6 @@ # import datetime -import re import struct from argparse import Namespace from contextlib import redirect_stdout @@ -16,14 +15,13 @@ from pontos.errors import PontosError from pontos.terminal.terminal import ConsoleTerminal from pontos.testing import temp_directory, temp_file +from pontos.updateheader.updateheader import _add_header as add_header from pontos.updateheader.updateheader import ( - OLD_COMPANY, _compile_copyright_regex, main, parse_args, update_file, ) -from pontos.updateheader.updateheader import _add_header as add_header from pontos.updateheader.updateheader import ( _compile_outdated_regex as compile_outdated_regex, ) @@ -74,12 +72,9 @@ def test_get_modified_year_error(self): class FindCopyRightTestCase(TestCase): - def setUp(self): + def setUp(self) -> None: self.company = "Greenbone AG" - self.regex = re.compile( - "(SPDX-FileCopyrightText:|[Cc]opyright).*?(19[0-9]{2}|20[0-9]{2}) " - f"?-? ?(19[0-9]{{2}}|20[0-9]{{2}})? ({self.company})" - ) + self.regex = _compile_copyright_regex(self.company) def test_find_copyright(self): test_line = "# Copyright (C) 1995-2021 Greenbone AG" @@ -193,11 +188,6 @@ def setUp(self): self.path = Path(__file__).parent - self.regex = re.compile( - "(SPDX-FileCopyrightText:|[Cc]opyright).*?(19[0-9]{2}|20[0-9]{2}) " - f"?-? ?(19[0-9]{{2}}|20[0-9]{{2}})? ({self.company})" - ) - @patch("sys.stdout", new_callable=StringIO) def test_update_file_not_existing(self, mock_stdout): year = "2020" @@ -212,7 +202,6 @@ def test_update_file_not_existing(self, mock_stdout): year, license_id, self.company, - copyright_regex=self.regex, ) ret = mock_stdout.getvalue() @@ -232,7 +221,6 @@ def test_update_file_wrong_license(self, mock_stdout): year, license_id, self.company, - copyright_regex=self.regex, ) ret = mock_stdout.getvalue() @@ -253,7 +241,6 @@ def test_update_file_suffix_invalid(self, mock_stdout): year, license_id, self.company, - copyright_regex=self.regex, ) ret = mock_stdout.getvalue() @@ -280,7 +267,6 @@ def test_update_file_binary_file(self, mock_stdout): year, license_id, self.company, - copyright_regex=self.regex, ) ret = mock_stdout.getvalue() @@ -302,7 +288,6 @@ def test_update_create_header(self, mock_stdout): year, license_id, self.company, - copyright_regex=self.regex, ) ret = mock_stdout.getvalue() @@ -328,7 +313,6 @@ def test_update_header_in_file(self, mock_stdout): year, license_id, self.company, - copyright_regex=self.regex, ) ret = mock_stdout.getvalue() @@ -356,7 +340,6 @@ def test_update_header_ok_in_file(self, mock_stdout): year, license_id, self.company, - copyright_regex=self.regex, ) ret = mock_stdout.getvalue() @@ -416,9 +399,6 @@ def test_cleanup_file(self): year, license_id, company, - copyright_regex=_compile_copyright_regex( - ["Greenbone AG", OLD_COMPANY] - ), cleanup_regexes=compiled_regexes, )