From d27f41a927c5c3bfa5979448dfbcc1b3a08026dc Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:30:03 +0300 Subject: [PATCH 01/91] Add unit tests for betty_check function --- tests/test_autoprototype.py | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_autoprototype.py diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py new file mode 100644 index 0000000..4075aae --- /dev/null +++ b/tests/test_autoprototype.py @@ -0,0 +1,43 @@ +import unittest +import pytest +import os +from colorama import Fore +from bettyfixer.autoprototype import betty_check + + +class TestBettyCheck: + """ + Test the betty_check function from autoprototype.py + """ + + @pytest.fixture(autouse=True) + def setup_method(self): + """Set up the test """ + with open("test.c", "w") as f: + f.write("int main() { return 0; }") + yield + os.remove("test.c") + + def test_betty_check_installed(self): + """ Test if betty is installed""" + assert betty_check() is not None + + def test_betty_check_errors(self): + """ Test if there are errors in the files + Create a temporary file with errors""" + betty = betty_check() + assert not betty + + def test_betty_check_warnings(self): + """ Test if there are warnings in the files + Create a temporary file with warnings""" + assert not betty_check() + + def test_betty_check_no_errors(self): + """ Test if there are no errors in the files + Create a temporary file without errors""" + assert betty_check() + + +if __name__ == '__main__': + unittest.main() From b443876e7b5d0d1d572afa964faab33088e0d694 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:56:11 +0300 Subject: [PATCH 02/91] Fix print_check_betty_first() message formatting --- bettyfixer/autoprototype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bettyfixer/autoprototype.py b/bettyfixer/autoprototype.py index d1dfaf2..4add489 100644 --- a/bettyfixer/autoprototype.py +++ b/bettyfixer/autoprototype.py @@ -36,7 +36,7 @@ def print_check_betty_first(): """Prints a message to the user to fix betty errors first.""" print( Fore.RED + "You should fix betty Errors first before \ - copy prototype functions into The header file" + Fore.RESET +copy prototype functions into The header file" + Fore.RESET ) From a8fe53a4c668a042fbeca1fe213d8733c0b078d9 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:56:17 +0300 Subject: [PATCH 03/91] Refactor autoprototype.py and add test cases --- tests/test_autoprototype.py | 38 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 4075aae..6637bdf 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -1,19 +1,26 @@ -import unittest -import pytest +""" + Test the autoprototype.py file +""" import os +import pytest from colorama import Fore -from bettyfixer.autoprototype import betty_check +from bettyfixer.autoprototype import (betty_check, + print_check_betty_first, + # print_header_name_missing, + # print_ctags_header_error, + # check_ctags + ) -class TestBettyCheck: +class TestAutoprototypeSuite: """ - Test the betty_check function from autoprototype.py + Test the autoprototype.py file """ @pytest.fixture(autouse=True) def setup_method(self): """Set up the test """ - with open("test.c", "w") as f: + with open("test.c", "w", encoding="utf-8") as f: f.write("int main() { return 0; }") yield os.remove("test.c") @@ -22,22 +29,25 @@ def test_betty_check_installed(self): """ Test if betty is installed""" assert betty_check() is not None - def test_betty_check_errors(self): + def test_betty_check_errors(self, capsys): """ Test if there are errors in the files Create a temporary file with errors""" betty = betty_check() assert not betty + captured = capsys.readouterr() + assert "exit status 1" in captured.out def test_betty_check_warnings(self): """ Test if there are warnings in the files Create a temporary file with warnings""" assert not betty_check() - def test_betty_check_no_errors(self): - """ Test if there are no errors in the files - Create a temporary file without errors""" - assert betty_check() - + def test_print_check_betty_first(self, capsys): + """Test the print_check_betty_first function from autoprototype.py""" + expected_output = Fore.RED + \ + "You should fix betty Errors first before copy prototype\ + functions into The header file" + Fore.RESET + "\n" -if __name__ == '__main__': - unittest.main() + print_check_betty_first() + captured = capsys.readouterr() + assert captured.out == expected_output From ccf1b042bf3dbe2818aaf6ddd20bcee9db9b916e Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:53:07 +0300 Subject: [PATCH 04/91] Add tests for betty_check, print_header_name_missing, print_ctags_header_error, and check_ctags functions --- tests/test_autoprototype.py | 54 ++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 6637bdf..01a4325 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -2,13 +2,15 @@ Test the autoprototype.py file """ import os +from subprocess import CompletedProcess +import subprocess import pytest from colorama import Fore from bettyfixer.autoprototype import (betty_check, print_check_betty_first, - # print_header_name_missing, - # print_ctags_header_error, - # check_ctags + print_header_name_missing, + print_ctags_header_error, + check_ctags ) @@ -21,13 +23,21 @@ class TestAutoprototypeSuite: def setup_method(self): """Set up the test """ with open("test.c", "w", encoding="utf-8") as f: - f.write("int main() { return 0; }") + f.write( + "int main(int argc, char **argv){\nprintf(\"Hello World\"\nreturn 0; \n}") yield os.remove("test.c") - def test_betty_check_installed(self): + def test_betty_check_installed(self, mocker): """ Test if betty is installed""" - assert betty_check() is not None + mock_run = mocker.patch("subprocess.run") + mock_run.return_value = CompletedProcess(args=['betty', '--version'], + returncode=0, + stdout=b'', + stderr=b'' + ) + betty_check_result = betty_check() + assert betty_check_result is not None def test_betty_check_errors(self, capsys): """ Test if there are errors in the files @@ -51,3 +61,35 @@ def test_print_check_betty_first(self, capsys): print_check_betty_first() captured = capsys.readouterr() assert captured.out == expected_output + + def test_print_header_name_missing(self, capsys): + """Test the print_header_name_missing function from autoprototype.py""" + expected_output = Fore.RED + \ + "Usage : bettyfixer -H .h" + Fore.RESET + "\n" + print_header_name_missing() + captured = capsys.readouterr() + assert captured.out == expected_output + + def test_print_ctags_header_error(self, capsys): + """Test the print_ctags_header_error function from autoprototype.py""" + expected_output = Fore.RED + "Error" + Fore.RESET + "\n" + print_ctags_header_error("Error") + captured = capsys.readouterr() + assert captured.out == expected_output + + def test_check_ctags_installed(self, mocker): + """ Test if ctags is installed""" + mock_run = mocker.patch("subprocess.run") + mock_run.return_value = CompletedProcess(args=['ctags', '--version'], + returncode=0, + ) + ctag = check_ctags() + assert ctag[0] is True and ctag[1] is None + + def test_check_ctags_not_installed(self, mocker): + """ Test if ctags is not installed""" + mock_run = mocker.patch("subprocess.run") + mock_run.side_effect = subprocess.CalledProcessError( + returncode=1, cmd=['ctags', '--version'], stderr=b'') + ctag = check_ctags() + assert ctag[0] is False and isinstance(ctag[1], str) From da89c85bad3616e0911bdae26133d9d6eb23e052 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:09:08 +0300 Subject: [PATCH 05/91] Fix betty_check() function to handle error and warning messages properly --- tests/test_autoprototype.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 01a4325..2840dbd 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -31,10 +31,12 @@ def setup_method(self): def test_betty_check_installed(self, mocker): """ Test if betty is installed""" mock_run = mocker.patch("subprocess.run") - mock_run.return_value = CompletedProcess(args=['betty', '--version'], + mock_glob = mocker.patch("glob.glob") + mock_glob.return_value = ["test.c"] + mock_run.return_value = CompletedProcess(args=['betty'] + mock_glob.return_value, returncode=0, - stdout=b'', - stderr=b'' + stdout=b'ERROR: ', + stderr=b'WARNING:' ) betty_check_result = betty_check() assert betty_check_result is not None From e47f9777ed2bb6d51debbb9c3babd3c277ef3eb6 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:19:53 +0300 Subject: [PATCH 06/91] Fix betty_check_installed test and capture stdout and stderr --- tests/test_autoprototype.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 2840dbd..8ed2db1 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -28,18 +28,22 @@ def setup_method(self): yield os.remove("test.c") - def test_betty_check_installed(self, mocker): + def test_betty_check_installed(self, mocker, capsys): """ Test if betty is installed""" mock_run = mocker.patch("subprocess.run") mock_glob = mocker.patch("glob.glob") mock_glob.return_value = ["test.c"] mock_run.return_value = CompletedProcess(args=['betty'] + mock_glob.return_value, returncode=0, - stdout=b'ERROR: ', - stderr=b'WARNING:' + stdout='ERROR: ', + stderr='WARNING:' ) betty_check_result = betty_check() assert betty_check_result is not None + assert betty_check_result is False + cap = capsys.readouterr() + assert "ERROR:" in cap.out + assert "WARNING:" in cap.err def test_betty_check_errors(self, capsys): """ Test if there are errors in the files From cab837f3abcd4fa28e7d48badb1ed4736d4a71fc Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:32:41 +0300 Subject: [PATCH 07/91] Refactor test_betty_check_installed method to remove capsys dependency --- tests/test_autoprototype.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 8ed2db1..8e3b86b 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -28,7 +28,7 @@ def setup_method(self): yield os.remove("test.c") - def test_betty_check_installed(self, mocker, capsys): + def test_betty_check_installed(self, mocker): """ Test if betty is installed""" mock_run = mocker.patch("subprocess.run") mock_glob = mocker.patch("glob.glob") @@ -41,9 +41,10 @@ def test_betty_check_installed(self, mocker, capsys): betty_check_result = betty_check() assert betty_check_result is not None assert betty_check_result is False - cap = capsys.readouterr() - assert "ERROR:" in cap.out - assert "WARNING:" in cap.err + assert "ERROR:" in mock_run.return_value.stdout or \ + "ERROR:" in mock_run.return_value.stderr + assert "WARNING:" in mock_run.return_value.stderr or \ + "WARNING:" in mock_run.return_value.stdout def test_betty_check_errors(self, capsys): """ Test if there are errors in the files From e58b4a042ee18571aab058f3a6c7875951b7f645 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:39:19 +0300 Subject: [PATCH 08/91] Add test for generate_tags function in autoprototype.py --- tests/test_autoprototype.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 8e3b86b..323f9ef 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -100,3 +100,15 @@ def test_check_ctags_not_installed(self, mocker): returncode=1, cmd=['ctags', '--version'], stderr=b'') ctag = check_ctags() assert ctag[0] is False and isinstance(ctag[1], str) + + def test_generate_tags(self, mocker): + """ Test the generate_tags function from autoprototype.py""" + mock_run = mocker.patch("subprocess.run") + mock_run.return_value = CompletedProcess(args=['ctags', '-R', '.'], + returncode=0, + ) + assert check_ctags() + mock_run.assert_called_once_with(['ctags', '-R', '.'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True) From bca93f480cf7ebba6b017acb8d124faf57e8dda0 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:46:38 +0300 Subject: [PATCH 09/91] Fix generate_tags function in test_autoprototype.py --- tests/test_autoprototype.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 323f9ef..2679fe2 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -6,7 +6,7 @@ import subprocess import pytest from colorama import Fore -from bettyfixer.autoprototype import (betty_check, +from bettyfixer.autoprototype import (betty_check, generate_tags, print_check_betty_first, print_header_name_missing, print_ctags_header_error, @@ -107,8 +107,7 @@ def test_generate_tags(self, mocker): mock_run.return_value = CompletedProcess(args=['ctags', '-R', '.'], returncode=0, ) - assert check_ctags() - mock_run.assert_called_once_with(['ctags', '-R', '.'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - check=True) + assert generate_tags('.') + mock_run.side_effect = subprocess.CalledProcessError( + returncode=1, cmd=['ctags', '-R', '.'], stderr="Error") + assert not generate_tags('.') From 10fae922f9e01f0500d385dad56a08f39569d4f2 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:50:20 +0300 Subject: [PATCH 10/91] Fix filter_tags function in test_autoprototype.py --- tests/test_autoprototype.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 2679fe2..252f96c 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -6,7 +6,7 @@ import subprocess import pytest from colorama import Fore -from bettyfixer.autoprototype import (betty_check, generate_tags, +from bettyfixer.autoprototype import (betty_check, filter_tags, generate_tags, print_check_betty_first, print_header_name_missing, print_ctags_header_error, @@ -111,3 +111,38 @@ def test_generate_tags(self, mocker): mock_run.side_effect = subprocess.CalledProcessError( returncode=1, cmd=['ctags', '-R', '.'], stderr="Error") assert not generate_tags('.') + + def test_filter_tags_success(self, tmpdir): + """Test the filter_tags function when the subprocess command succeeds.""" + generate_tags(".") + result = filter_tags(str(tmpdir), "tags") + print(result) + assert result is not None + assert "int main" in result + + # def test_filter_tags_failure(self, mocker, tmpdir, capsys): + # """Test the filter_tags function when the subprocess command fails.""" + # # Mock subprocess.run to simulate a failed command + # mocker.patch("subprocess.run", + # side_effect=subprocess.CalledProcessError(1, "cmd")) + + # # Call the function and check the result + # result = filter_tags(str(tmpdir), "tags") + # assert result is None + + # # Check the error message + # captured = capsys.readouterr() + # assert "Error: File" in captured.out + + # def test_filter_tags_no_file(self, mocker, tmpdir, capsys): + # """Test the filter_tags function when the tags file does not exist.""" + # # Mock subprocess.run to simulate a successful command + # mocker.patch("subprocess.run") + + # # Call the function with a non-existent tags file and check the result + # result = filter_tags(str(tmpdir), "nonexistent") + # assert result is None + + # # Check the error message + # captured = capsys.readouterr() + # assert "Error: File" in captured.out From 95a38f4becd8827618b081e42363e5ae92af2e9b Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:53:00 +0300 Subject: [PATCH 11/91] Add .gitignore file and remove main.c*** --- .gitignore | 6 ++++++ main.c | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 .gitignore delete mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..874e549 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +main.c +__pycache__/ +*.pyc +.coverage +htmlcov/ +launch.json \ No newline at end of file diff --git a/main.c b/main.c deleted file mode 100644 index a6beaaf..0000000 --- a/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void main(int argc, **argv){ - printf("Hello, World\n"); - return 0; -} - From 2db2f08bd8c403c989a9b0cf4e7d4d06390eefc8 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:43:59 +0300 Subject: [PATCH 12/91] Refactor setup_method to generate and remove tags file --- tests/test_autoprototype.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 252f96c..dc1ff77 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -20,13 +20,18 @@ class TestAutoprototypeSuite: """ @pytest.fixture(autouse=True) - def setup_method(self): + def setup_method(self, request): """Set up the test """ + if "filter_tag" in request.node.name: + generate_tags(".") with open("test.c", "w", encoding="utf-8") as f: f.write( "int main(int argc, char **argv){\nprintf(\"Hello World\"\nreturn 0; \n}") yield os.remove("test.c") + if "filter_tag" in request.node.name: + os.remove("tags") + os.remove("temp_tags") def test_betty_check_installed(self, mocker): """ Test if betty is installed""" @@ -112,27 +117,24 @@ def test_generate_tags(self, mocker): returncode=1, cmd=['ctags', '-R', '.'], stderr="Error") assert not generate_tags('.') - def test_filter_tags_success(self, tmpdir): + def test_filter_tags_success(self): """Test the filter_tags function when the subprocess command succeeds.""" generate_tags(".") - result = filter_tags(str(tmpdir), "tags") - print(result) + result = filter_tags('.', "tags") + assert result is not None - assert "int main" in result + with open("tags", "r", encoding='utf-8') as f: + assert 'int main(int argc, char **argv)' in f.read() - # def test_filter_tags_failure(self, mocker, tmpdir, capsys): - # """Test the filter_tags function when the subprocess command fails.""" - # # Mock subprocess.run to simulate a failed command - # mocker.patch("subprocess.run", - # side_effect=subprocess.CalledProcessError(1, "cmd")) + def test_filter_tags_failure(self, mocker): + """Test the filter_tags function when the subprocess command fails.""" - # # Call the function and check the result - # result = filter_tags(str(tmpdir), "tags") - # assert result is None + # Call the function and check the result + assert filter_tags('.', "tags") is None - # # Check the error message - # captured = capsys.readouterr() - # assert "Error: File" in captured.out + # # Check the error message + # captured = capsys.readouterr() + # assert "Error: File" in captured.out # def test_filter_tags_no_file(self, mocker, tmpdir, capsys): # """Test the filter_tags function when the tags file does not exist.""" From d494bbb727e1961a5c5356efc211fbcf7801ca92 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 15 Feb 2024 15:04:05 +0300 Subject: [PATCH 13/91] Add filter_tags function and mock subprocess.run in test_filter_tags_failure --- tests/test_autoprototype.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index dc1ff77..d44e501 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -24,6 +24,7 @@ def setup_method(self, request): """Set up the test """ if "filter_tag" in request.node.name: generate_tags(".") + filter_tags(".", "tags") with open("test.c", "w", encoding="utf-8") as f: f.write( "int main(int argc, char **argv){\nprintf(\"Hello World\"\nreturn 0; \n}") @@ -128,9 +129,15 @@ def test_filter_tags_success(self): def test_filter_tags_failure(self, mocker): """Test the filter_tags function when the subprocess command fails.""" + mock_run = mocker.patch("subprocess.run") + mock_run.return_value = CompletedProcess(args=['ctags', '-R', '.'], + returncode=1, + stderr="Error" + ) # Call the function and check the result - assert filter_tags('.', "tags") is None + assert not filter_tags('.', "tags") + assert os.path.exists("temp_tags") is True # # Check the error message # captured = capsys.readouterr() From 30e12393b079834e5363241430806c4401a5513d Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:07:09 +0300 Subject: [PATCH 14/91] Remove commented out code in test_autoprototype.py --- tests/test_autoprototype.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index d44e501..788af7a 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -151,7 +151,3 @@ def test_filter_tags_failure(self, mocker): # # Call the function with a non-existent tags file and check the result # result = filter_tags(str(tmpdir), "nonexistent") # assert result is None - - # # Check the error message - # captured = capsys.readouterr() - # assert "Error: File" in captured.out From 18e9a03301dd86c47e05fd106bed9f8ddaf5296e Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 11 Feb 2024 16:07:39 +0300 Subject: [PATCH 15/91] Remove commented out code in test_autoprototype.py --- tests/test_autoprototype.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 788af7a..3561973 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -142,12 +142,3 @@ def test_filter_tags_failure(self, mocker): # # Check the error message # captured = capsys.readouterr() # assert "Error: File" in captured.out - - # def test_filter_tags_no_file(self, mocker, tmpdir, capsys): - # """Test the filter_tags function when the tags file does not exist.""" - # # Mock subprocess.run to simulate a successful command - # mocker.patch("subprocess.run") - - # # Call the function with a non-existent tags file and check the result - # result = filter_tags(str(tmpdir), "nonexistent") - # assert result is None From d99fe8bde023fbb75f7cedbf061b22d6d1696a19 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:01:11 +0300 Subject: [PATCH 16/91] Add tests/__init__.py file --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 70de3037c25724d0a77ec04a585a8c604ee8d6ed Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 11:23:36 +0300 Subject: [PATCH 17/91] Fix generate_tags function and add test cases --- tests/test_autoprototype.py | 54 ++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 3561973..583c245 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -22,22 +22,30 @@ class TestAutoprototypeSuite: @pytest.fixture(autouse=True) def setup_method(self, request): """Set up the test """ - if "filter_tag" in request.node.name: + is_filter_tag_test = "filter_tag" in request.node.name + + if is_filter_tag_test: generate_tags(".") filter_tags(".", "tags") + with open("test.c", "w", encoding="utf-8") as f: f.write( - "int main(int argc, char **argv){\nprintf(\"Hello World\"\nreturn 0; \n}") + 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') + yield + os.remove("test.c") - if "filter_tag" in request.node.name: - os.remove("tags") - os.remove("temp_tags") + + if is_filter_tag_test: + for file in ["tags", "temp_tags"]: + os.remove(file) def test_betty_check_installed(self, mocker): """ Test if betty is installed""" - mock_run = mocker.patch("subprocess.run") - mock_glob = mocker.patch("glob.glob") + + mock_run, mock_glob = mocker.patch( + "subprocess.run"), mocker.patch("glob.glob") + mock_glob.return_value = ["test.c"] mock_run.return_value = CompletedProcess(args=['betty'] + mock_glob.return_value, returncode=0, @@ -107,25 +115,41 @@ def test_check_ctags_not_installed(self, mocker): ctag = check_ctags() assert ctag[0] is False and isinstance(ctag[1], str) - def test_generate_tags(self, mocker): - """ Test the generate_tags function from autoprototype.py""" + def test_generate_tags_failure(self, mocker): + """ Test the generate_tags function not working from autoprototype.py""" mock_run = mocker.patch("subprocess.run") - mock_run.return_value = CompletedProcess(args=['ctags', '-R', '.'], - returncode=0, - ) - assert generate_tags('.') mock_run.side_effect = subprocess.CalledProcessError( returncode=1, cmd=['ctags', '-R', '.'], stderr="Error") assert not generate_tags('.') + def test_generate_tags_success(self, mocker): + """Test the generate_tags function when the subprocess command succeeds.""" + mock_run = mocker.patch("subprocess.run") + mock_run.return_value = CompletedProcess(args=[ + 'ctags', '-R', '--c-kinds=+p', + '--fields=+S', '--extra=+q', + '--languages=c', '--langmap=c:.c' + ], + returncode=0, + ) + assert generate_tags('.') + mock_run.assert_called_once_with(['ctags', '-R', '--c-kinds=+p', + '--fields=+S', '--extra=+q', + '--languages=c', '--langmap=c:.c', + '.'], check=True) + mocker.stopall() + result = generate_tags(".") + assert result is not None + assert os.path.exists("tags") is True + with open("tags", "r", encoding='utf-8') as f: + assert 'int main(int argc, char **argv)' in f.read() + def test_filter_tags_success(self): """Test the filter_tags function when the subprocess command succeeds.""" generate_tags(".") result = filter_tags('.', "tags") assert result is not None - with open("tags", "r", encoding='utf-8') as f: - assert 'int main(int argc, char **argv)' in f.read() def test_filter_tags_failure(self, mocker): """Test the filter_tags function when the subprocess command fails.""" From 5c1e464dddbb85e05fc82fc58f88108d28af2b24 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 11:30:21 +0300 Subject: [PATCH 18/91] Add create_header function to autoprototype.py --- tests/test_autoprototype.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 583c245..6343c41 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -10,7 +10,7 @@ print_check_betty_first, print_header_name_missing, print_ctags_header_error, - check_ctags + check_ctags, create_header ) @@ -31,7 +31,6 @@ def setup_method(self, request): with open("test.c", "w", encoding="utf-8") as f: f.write( 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') - yield os.remove("test.c") @@ -163,6 +162,9 @@ def test_filter_tags_failure(self, mocker): assert not filter_tags('.', "tags") assert os.path.exists("temp_tags") is True - # # Check the error message - # captured = capsys.readouterr() - # assert "Error: File" in captured.out + def test_create_header(self): + """Test the create_header function from autoprototype.py""" + assert create_header("test.h", "test.c") + with open("test.h", "r", encoding='utf-8') as f: + assert 'int main(int argc, char **argv);' in f.read() + os.remove("test.h") From 359ac9ff6db9f3750be43584abde8feceab5aebd Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 11:42:23 +0300 Subject: [PATCH 19/91] Add generate_tags and filter_tags functions to create_header function --- tests/test_autoprototype.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 6343c41..4221396 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -164,7 +164,12 @@ def test_filter_tags_failure(self, mocker): def test_create_header(self): """Test the create_header function from autoprototype.py""" - assert create_header("test.h", "test.c") + generate_tags(".") + filtered_tags = filter_tags(".", "tags") + + create_header("test.h", filtered_tags=filtered_tags) + assert os.path.exists("test.h") is True with open("test.h", "r", encoding='utf-8') as f: + assert 'test'.upper() in f.read() assert 'int main(int argc, char **argv);' in f.read() os.remove("test.h") From af4753fe82ee18fbaf211170e9d57ed64dc40664 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:56:48 +0300 Subject: [PATCH 20/91] Refactor test_autoprototype.py: Improve file handling and remove unnecessary files --- tests/test_autoprototype.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 4221396..9158760 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -170,6 +170,9 @@ def test_create_header(self): create_header("test.h", filtered_tags=filtered_tags) assert os.path.exists("test.h") is True with open("test.h", "r", encoding='utf-8') as f: - assert 'test'.upper() in f.read() - assert 'int main(int argc, char **argv);' in f.read() + content = f.read() + assert 'test'.upper() in content + assert 'endif' in content os.remove("test.h") + os.remove("tags") + os.remove("temp_tags") From ac34b45b4c758a6248f73d8cee521ce99544af10 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:22:37 +0300 Subject: [PATCH 21/91] found bugs in filter_tags function --- bettyfixer/autoprototype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bettyfixer/autoprototype.py b/bettyfixer/autoprototype.py index 4add489..27a2d15 100644 --- a/bettyfixer/autoprototype.py +++ b/bettyfixer/autoprototype.py @@ -84,7 +84,7 @@ def generate_tags(directory): return False -def filter_tags(directory, tags_file): +def filter_tags(directory, tags_file): # ❗ This function has bugs """ Filter the tags file to get only the function prototypes. Args: From 01804963f05dfc323f1b4289a19e2e90e4fc77c9 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:27:52 +0300 Subject: [PATCH 22/91] Add test for create_header function in autoprototype.py --- tests/test_autoprototype.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 9158760..7a9956f 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -176,3 +176,14 @@ def test_create_header(self): os.remove("test.h") os.remove("tags") os.remove("temp_tags") + + def test_create_header_failure(self, mocker): + """Test the create_header function from autoprototype.py""" + mock_open = mocker.patch("builtins.open") + mock_open.side_effect = AttributeError + with pytest.raises(AttributeError): + create_header(123, filtered_tags="test") + assert os.path.exists("test.h") is False + with pytest.raises(FileNotFoundError): + os.remove("tags") + os.remove("temp_tags") From 4cd484ed46b60abd5757f25422a3ad6ccb429596 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:41:43 +0300 Subject: [PATCH 23/91] Add delete_files test function to autoprototype.py --- tests/test_autoprototype.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 7a9956f..f63db5f 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -10,7 +10,8 @@ print_check_betty_first, print_header_name_missing, print_ctags_header_error, - check_ctags, create_header + check_ctags, create_header, + delete_files ) @@ -187,3 +188,24 @@ def test_create_header_failure(self, mocker): with pytest.raises(FileNotFoundError): os.remove("tags") os.remove("temp_tags") + + def test_delete_files(self): + """Test the delete_files function from autoprototype.py""" + + with open("tags", "w", encoding="utf-8"): + pass + with open("temp_tags", "w", encoding="utf-8"): + pass + delete_files('tags', 'temp_tags') + assert os.path.exists("tags") is False + assert os.path.exists("temp_tags") is False + + def test_delete_files_failure(self, mocker): + """Test the delete_files function from autoprototype.py""" + mock_remove = mocker.patch("subprocess.run") + mock_remove.side_effect = subprocess.CalledProcessError( + returncode=1, cmd=['rm', 'tags', 'temp_tags'], stderr="Error") + with pytest.raises(subprocess.CalledProcessError): + delete_files('tags', 'temp_tags') + mock_remove.assert_called_once_with( + 'rm tags temp_tags', check=True, shell=True) From 73fc60ffcb1de6298279dc7c103dec2dc59823dd Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:15:16 +0300 Subject: [PATCH 24/91] Add tests for check_header_file and autoproto functions --- tests/test_autoprototype.py | 78 ++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index f63db5f..437a12d 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -6,12 +6,14 @@ import subprocess import pytest from colorama import Fore +from pytest_mock.plugin import _mocker from bettyfixer.autoprototype import (betty_check, filter_tags, generate_tags, print_check_betty_first, print_header_name_missing, print_ctags_header_error, check_ctags, create_header, - delete_files + delete_files, check_header_file, + autoproto ) @@ -21,13 +23,8 @@ class TestAutoprototypeSuite: """ @pytest.fixture(autouse=True) - def setup_method(self, request): + def setup_method(self): """Set up the test """ - is_filter_tag_test = "filter_tag" in request.node.name - - if is_filter_tag_test: - generate_tags(".") - filter_tags(".", "tags") with open("test.c", "w", encoding="utf-8") as f: f.write( @@ -36,9 +33,18 @@ def setup_method(self, request): os.remove("test.c") - if is_filter_tag_test: - for file in ["tags", "temp_tags"]: - os.remove(file) + @pytest.fixture() + def setup_tear_down_temp_files(self): + """Set up the test """ + generate_tags(".") + filter_tags(".", "tags") + yield + if os.path.exists("tags"): + os.remove("tags") + if os.path.exists("temp_tags"): + os.remove("temp_tags") + if os.path.exists("test.h"): + os.remove("test.h") def test_betty_check_installed(self, mocker): """ Test if betty is installed""" @@ -144,6 +150,7 @@ def test_generate_tags_success(self, mocker): with open("tags", "r", encoding='utf-8') as f: assert 'int main(int argc, char **argv)' in f.read() + @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_filter_tags_success(self): """Test the filter_tags function when the subprocess command succeeds.""" generate_tags(".") @@ -151,6 +158,7 @@ def test_filter_tags_success(self): assert result is not None + @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_filter_tags_failure(self, mocker): """Test the filter_tags function when the subprocess command fails.""" mock_run = mocker.patch("subprocess.run") @@ -163,6 +171,7 @@ def test_filter_tags_failure(self, mocker): assert not filter_tags('.', "tags") assert os.path.exists("temp_tags") is True + @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_create_header(self): """Test the create_header function from autoprototype.py""" generate_tags(".") @@ -174,32 +183,24 @@ def test_create_header(self): content = f.read() assert 'test'.upper() in content assert 'endif' in content - os.remove("test.h") - os.remove("tags") - os.remove("temp_tags") + @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_create_header_failure(self, mocker): """Test the create_header function from autoprototype.py""" mock_open = mocker.patch("builtins.open") mock_open.side_effect = AttributeError with pytest.raises(AttributeError): - create_header(123, filtered_tags="test") + create_header(123, filtered_tags="tags") assert os.path.exists("test.h") is False - with pytest.raises(FileNotFoundError): - os.remove("tags") - os.remove("temp_tags") + @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_delete_files(self): """Test the delete_files function from autoprototype.py""" - - with open("tags", "w", encoding="utf-8"): - pass - with open("temp_tags", "w", encoding="utf-8"): - pass delete_files('tags', 'temp_tags') assert os.path.exists("tags") is False assert os.path.exists("temp_tags") is False + @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_delete_files_failure(self, mocker): """Test the delete_files function from autoprototype.py""" mock_remove = mocker.patch("subprocess.run") @@ -209,3 +210,36 @@ def test_delete_files_failure(self, mocker): delete_files('tags', 'temp_tags') mock_remove.assert_called_once_with( 'rm tags temp_tags', check=True, shell=True) + assert os.path.exists("tags") is True + + def test_check_header_file(self): + """ Test the check_header_file function from autoprototype.py""" + os.mknod("test.h") + result = check_header_file("test.h") + assert result == (True, None) + os.remove("test.h") + result = check_header_file("test") + assert result == ( + False, "Error: Invalid header file. It should have a '.h' extension.") + + @pytest.mark.usefixtures("setup_tear_down_temp_files") + def test_autoproto(self, mocker): + """ Test the autoproto function from autoprototype.py""" + mock_check_header_file, mock_filter_tags, mock_generate_tags, mock_create_header = mocker.patch( + "bettyfixer.autoprototype.check_header_file"), mocker.patch( + "bettyfixer.autoprototype.filter_tags"), mocker.patch( + "bettyfixer.autoprototype.generate_tags"), mocker.patch( + "bettyfixer.autoprototype.create_header") + + mock_check_header_file.return_value = (True, None) + mock_generate_tags.return_value = True + mock_filter_tags.return_value = True + mock_create_header.return_value = None + + autoproto(".", "test.h") + mock_check_header_file.assert_called_once_with("test.h") + mock_generate_tags.assert_called_once() + mock_filter_tags.assert_called_once() + mock_create_header.assert_called_once_with( + "test.h", mock_filter_tags.return_value) + mocker.stopall() From f4fa6a4b0c3bdb890007245d0c2449a63c7fffa9 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:17:41 +0300 Subject: [PATCH 25/91] Fix mock_generate_tags call in test_autoprototype.py --- tests/test_autoprototype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 437a12d..043f530 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -238,7 +238,7 @@ def test_autoproto(self, mocker): autoproto(".", "test.h") mock_check_header_file.assert_called_once_with("test.h") - mock_generate_tags.assert_called_once() + mock_generate_tags.assert_called_once_with(".") mock_filter_tags.assert_called_once() mock_create_header.assert_called_once_with( "test.h", mock_filter_tags.return_value) From 632ad7d7b8241a3c926e546193f77b47a9df6f4c Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:27:09 +0300 Subject: [PATCH 26/91] Refactor test_autoproto function in test_autoprototype.py --- tests/test_autoprototype.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 043f530..2171a93 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -225,11 +225,12 @@ def test_check_header_file(self): @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_autoproto(self, mocker): """ Test the autoproto function from autoprototype.py""" - mock_check_header_file, mock_filter_tags, mock_generate_tags, mock_create_header = mocker.patch( - "bettyfixer.autoprototype.check_header_file"), mocker.patch( - "bettyfixer.autoprototype.filter_tags"), mocker.patch( - "bettyfixer.autoprototype.generate_tags"), mocker.patch( - "bettyfixer.autoprototype.create_header") + mock_check_header_file, mock_filter_tags, \ + mock_generate_tags, mock_create_header = mocker.patch( + "bettyfixer.autoprototype.check_header_file"), mocker.patch( + "bettyfixer.autoprototype.filter_tags"), mocker.patch( + "bettyfixer.autoprototype.generate_tags"), mocker.patch( + "bettyfixer.autoprototype.create_header") mock_check_header_file.return_value = (True, None) mock_generate_tags.return_value = True From daa28ce50e24c6836293fd178997495debbcd1a8 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:41:51 +0300 Subject: [PATCH 27/91] Commented out pytest_mock.plugin import --- tests/test_autoprototype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 2171a93..7bc7729 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -6,7 +6,7 @@ import subprocess import pytest from colorama import Fore -from pytest_mock.plugin import _mocker +# from pytest_mock.plugin import _mocker from bettyfixer.autoprototype import (betty_check, filter_tags, generate_tags, print_check_betty_first, print_header_name_missing, From eb68d9f1fd1c036a470cd5d6c7247477c84ffc1f Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 14:58:36 +0300 Subject: [PATCH 28/91] Add test cases for backup module --- tests/test_backup.py | 69 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/test_backup.py diff --git a/tests/test_backup.py b/tests/test_backup.py new file mode 100644 index 0000000..bfd80b9 --- /dev/null +++ b/tests/test_backup.py @@ -0,0 +1,69 @@ +""" +Test the backup module. +""" +import os +import pytest +from bettyfixer import backup + + +class TestBackup: + """Test the backup module.""" + + @pytest.fixture(autouse=True) + def setup_method(self): + """Create a test file.""" # pylint: disable=attribute-defined-outside-init + self.test_file = 'test.c' + with open(self.test_file, 'w', encoding='utf-8') as f: + self.test_file = f.name + f.write( + 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') + yield + os.remove(self.test_file) + if os.path.exists(self.test_file + '.bak'): + os.remove(self.test_file + '.bak') + + def test_create_backup(self): + """Test the create_backup function.""" + backup.create_backup(self.test_file) + assert os.path.exists(self.test_file + '.bak') + with open(self.test_file + '.bak', 'r', encoding='utf-8') as f: + assert f.read() == 'test' + os.remove(self.test_file + '.bak') + + def test_create_backup_same_file_error(self): + """Test the create_backup function with a same file error.""" + with open(self.test_file + '.bak', 'w', encoding='utf-8') as f: + f.write('test') + backup.create_backup(self.test_file) + assert os.path.exists(self.test_file + '.bak') + with open(self.test_file + '.bak', 'r', encoding='utf-8') as f: + assert f.read() == 'test' + os.remove(self.test_file + '.bak') + + def test_create_backup_file_not_found(self): + """Test the create_backup function with a file not found error.""" + os.remove(self.test_file) + backup.create_backup(self.test_file) + assert not os.path.exists(self.test_file + '.bak') + + def test_create_backup_is_a_directory_error(self): + """Test the create_backup function with an is a directory error.""" + os.remove(self.test_file) + os.mkdir(self.test_file) + backup.create_backup(self.test_file) + assert not os.path.exists(self.test_file + '.bak') + + def test_create_backup_permission_error(self): + """Test the create_backup function with a permission error.""" + os.chmod(self.test_file, 0o000) + backup.create_backup(self.test_file) + assert not os.path.exists(self.test_file + '.bak') + + def test_create_backup_os_error(self): + """Test the create_backup function with an os error.""" + os.remove(self.test_file) + with open(self.test_file, 'w', encoding='utf-8') as f: + f.write('test') + os.chmod(self.test_file, 0o000) + backup.create_backup(self.test_file) + assert not os.path.exists(self.test_file + '.bak') From be0790927ee9a38d78291ac8b7223b8f1f029a6b Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:10:42 +0300 Subject: [PATCH 29/91] Add import shutil and modify test_create_backup_same_file_error --- tests/test_backup.py | 57 +++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/tests/test_backup.py b/tests/test_backup.py index bfd80b9..c885872 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -2,6 +2,7 @@ Test the backup module. """ import os +import shutil import pytest from bettyfixer import backup @@ -27,43 +28,45 @@ def test_create_backup(self): backup.create_backup(self.test_file) assert os.path.exists(self.test_file + '.bak') with open(self.test_file + '.bak', 'r', encoding='utf-8') as f: - assert f.read() == 'test' + assert 'int main(int argc,' in f.read() os.remove(self.test_file + '.bak') def test_create_backup_same_file_error(self): """Test the create_backup function with a same file error.""" with open(self.test_file + '.bak', 'w', encoding='utf-8') as f: - f.write('test') - backup.create_backup(self.test_file) + f.write( + 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') assert os.path.exists(self.test_file + '.bak') + with pytest.raises(shutil.SameFileError): + backup.create_backup(self.test_file) with open(self.test_file + '.bak', 'r', encoding='utf-8') as f: assert f.read() == 'test' os.remove(self.test_file + '.bak') - def test_create_backup_file_not_found(self): - """Test the create_backup function with a file not found error.""" - os.remove(self.test_file) - backup.create_backup(self.test_file) - assert not os.path.exists(self.test_file + '.bak') + # def test_create_backup_file_not_found(self): + # """Test the create_backup function with a file not found error.""" + # os.remove(self.test_file) + # backup.create_backup(self.test_file) + # assert not os.path.exists(self.test_file + '.bak') - def test_create_backup_is_a_directory_error(self): - """Test the create_backup function with an is a directory error.""" - os.remove(self.test_file) - os.mkdir(self.test_file) - backup.create_backup(self.test_file) - assert not os.path.exists(self.test_file + '.bak') + # def test_create_backup_is_a_directory_error(self): + # """Test the create_backup function with an is a directory error.""" + # os.remove(self.test_file) + # os.mkdir(self.test_file) + # backup.create_backup(self.test_file) + # assert not os.path.exists(self.test_file + '.bak') - def test_create_backup_permission_error(self): - """Test the create_backup function with a permission error.""" - os.chmod(self.test_file, 0o000) - backup.create_backup(self.test_file) - assert not os.path.exists(self.test_file + '.bak') + # def test_create_backup_permission_error(self): + # """Test the create_backup function with a permission error.""" + # os.chmod(self.test_file, 0o000) + # backup.create_backup(self.test_file) + # assert not os.path.exists(self.test_file + '.bak') - def test_create_backup_os_error(self): - """Test the create_backup function with an os error.""" - os.remove(self.test_file) - with open(self.test_file, 'w', encoding='utf-8') as f: - f.write('test') - os.chmod(self.test_file, 0o000) - backup.create_backup(self.test_file) - assert not os.path.exists(self.test_file + '.bak') + # def test_create_backup_os_error(self): + # """Test the create_backup function with an os error.""" + # os.remove(self.test_file) + # with open(self.test_file, 'w', encoding='utf-8') as f: + # f.write('test') + # os.chmod(self.test_file, 0o000) + # backup.create_backup(self.test_file) + # assert not os.path.exists(self.test_file + '.bak') From 1ba0473f264e78d5123ae4a5ae6b2f64b0b2bef1 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:18:57 +0300 Subject: [PATCH 30/91] Refactor test_create_backup_same_file_error method*** --- tests/test_backup.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/test_backup.py b/tests/test_backup.py index c885872..f546895 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -31,17 +31,14 @@ def test_create_backup(self): assert 'int main(int argc,' in f.read() os.remove(self.test_file + '.bak') - def test_create_backup_same_file_error(self): + def test_create_backup_same_file_error(self, mocker, capsys): """Test the create_backup function with a same file error.""" - with open(self.test_file + '.bak', 'w', encoding='utf-8') as f: - f.write( - 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') - assert os.path.exists(self.test_file + '.bak') - with pytest.raises(shutil.SameFileError): - backup.create_backup(self.test_file) - with open(self.test_file + '.bak', 'r', encoding='utf-8') as f: - assert f.read() == 'test' - os.remove(self.test_file + '.bak') + + mocker.patch('shutil.copy2', side_effect=shutil.SameFileError) + backup.create_backup(self.test_file) + captured = capsys.readouterr() + assert 'Err creating backup' in captured.out + assert not os.path.exists(self.test_file + '.bak') # def test_create_backup_file_not_found(self): # """Test the create_backup function with a file not found error.""" From 7b30761dbf05aa012501bf9128720a30ae7d121f Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:14:09 +0300 Subject: [PATCH 31/91] Add test for create_backup function with file not found error --- tests/test_backup.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_backup.py b/tests/test_backup.py index f546895..e8a7867 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -37,14 +37,16 @@ def test_create_backup_same_file_error(self, mocker, capsys): mocker.patch('shutil.copy2', side_effect=shutil.SameFileError) backup.create_backup(self.test_file) captured = capsys.readouterr() - assert 'Err creating backup' in captured.out + assert 'Src and dest are same file' in captured.out assert not os.path.exists(self.test_file + '.bak') - # def test_create_backup_file_not_found(self): - # """Test the create_backup function with a file not found error.""" - # os.remove(self.test_file) - # backup.create_backup(self.test_file) - # assert not os.path.exists(self.test_file + '.bak') + def test_create_backup_file_not_found(self, mocker, capsys): + """Test the create_backup function with a file not found error.""" + mocker.patch('shutil.copy2', side_effect=FileNotFoundError) + backup.create_backup(self.test_file) + captured = capsys.readouterr() + assert 'File not found' in captured.out + assert not os.path.exists(self.test_file + '.bak') # def test_create_backup_is_a_directory_error(self): # """Test the create_backup function with an is a directory error.""" From e4e7b26997abe698139cc78334802c7175ce59a5 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:14:16 +0300 Subject: [PATCH 32/91] Fix error message in create_backup function --- bettyfixer/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bettyfixer/backup.py b/bettyfixer/backup.py index 4d2d734..5d096d0 100644 --- a/bettyfixer/backup.py +++ b/bettyfixer/backup.py @@ -15,7 +15,7 @@ def create_backup(file_path): shutil.copy2(file_path, backup_path) except shutil.SameFileError: print( - f"Err creating backup {file_path}: Src and dest are same file.") + f"Error creating backup {file_path}: Src and dest are same file.") except FileNotFoundError: print(f"Error creating backup for {file_path}: File not found.") except IsADirectoryError: From 0b7898b0bb830db8a274005a8372c4a8f914160c Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:32:05 +0300 Subject: [PATCH 33/91] Add error handling tests for create_backup function --- tests/test_backup.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/test_backup.py b/tests/test_backup.py index e8a7867..a91f4ae 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -48,24 +48,26 @@ def test_create_backup_file_not_found(self, mocker, capsys): assert 'File not found' in captured.out assert not os.path.exists(self.test_file + '.bak') - # def test_create_backup_is_a_directory_error(self): - # """Test the create_backup function with an is a directory error.""" - # os.remove(self.test_file) - # os.mkdir(self.test_file) - # backup.create_backup(self.test_file) - # assert not os.path.exists(self.test_file + '.bak') + def test_create_backup_is_a_directory_error(self, mocker, capsys): + """Test the create_backup function with an is a directory error.""" + mocker.patch('shutil.copy2', side_effect=IsADirectoryError) + backup.create_backup(self.test_file) + captured = capsys.readouterr() + assert 'Is a directory error' in captured.out + assert not os.path.exists(self.test_file + '.bak') - # def test_create_backup_permission_error(self): - # """Test the create_backup function with a permission error.""" - # os.chmod(self.test_file, 0o000) - # backup.create_backup(self.test_file) - # assert not os.path.exists(self.test_file + '.bak') + def test_create_backup_permission_error(self, mocker, capsys): + """Test the create_backup function with a permission error.""" + mocker.patch('shutil.copy2', side_effect=PermissionError) + backup.create_backup(self.test_file) + captured = capsys.readouterr() + assert 'Permission error' in captured.out + assert not os.path.exists(self.test_file + '.bak') - # def test_create_backup_os_error(self): - # """Test the create_backup function with an os error.""" - # os.remove(self.test_file) - # with open(self.test_file, 'w', encoding='utf-8') as f: - # f.write('test') - # os.chmod(self.test_file, 0o000) - # backup.create_backup(self.test_file) - # assert not os.path.exists(self.test_file + '.bak') + def test_create_backup_os_error(self, mocker, capsys): + """Test the create_backup function with an os error.""" + mocker.patch('shutil.copy2', side_effect=OSError) + backup.create_backup(self.test_file) + captured = capsys.readouterr() + assert 'Unexpected error' in captured.out + assert not os.path.exists(self.test_file + '.bak') From 9311a06cb20c2469b2a53a634f628ee50d879149 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:32:16 +0300 Subject: [PATCH 34/91] Add test for betty_fixer module --- tests/test_betty_fixer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/test_betty_fixer.py diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py new file mode 100644 index 0000000..b9bc9e6 --- /dev/null +++ b/tests/test_betty_fixer.py @@ -0,0 +1,11 @@ +""" +Test the betty_fixer module. +""" +import os +import subprocess +import pytest +from bettyfixer.betty_fixer import * as betty_fixer + + +class TestBettyFixer: + pass From 76d16bbeb55af8e80a804cf7e21cf843dff78068 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 17:42:12 +0300 Subject: [PATCH 35/91] Fix filter_tags function and add error handling --- tests/test_autoprototype.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 7bc7729..34d45f0 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -13,7 +13,7 @@ print_ctags_header_error, check_ctags, create_header, delete_files, check_header_file, - autoproto + autoproto, print_ctags_header_error ) @@ -159,7 +159,7 @@ def test_filter_tags_success(self): assert result is not None @pytest.mark.usefixtures("setup_tear_down_temp_files") - def test_filter_tags_failure(self, mocker): + def test_filter_tags_failure(self, mocker, capsys): """Test the filter_tags function when the subprocess command fails.""" mock_run = mocker.patch("subprocess.run") mock_run.return_value = CompletedProcess(args=['ctags', '-R', '.'], @@ -170,6 +170,12 @@ def test_filter_tags_failure(self, mocker): # Call the function and check the result assert not filter_tags('.', "tags") assert os.path.exists("temp_tags") is True + mocker.stopall() + mock_run = mocker.patch("os.path.exists") + mock_run.return_value = False + assert filter_tags('.', "tags") is None + captured = capsys.readouterr() + assert "Error" in captured.out @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_create_header(self): @@ -226,11 +232,12 @@ def test_check_header_file(self): def test_autoproto(self, mocker): """ Test the autoproto function from autoprototype.py""" mock_check_header_file, mock_filter_tags, \ - mock_generate_tags, mock_create_header = mocker.patch( + mock_generate_tags, mock_create_header, mock_ctag_print = mocker.patch( "bettyfixer.autoprototype.check_header_file"), mocker.patch( "bettyfixer.autoprototype.filter_tags"), mocker.patch( "bettyfixer.autoprototype.generate_tags"), mocker.patch( - "bettyfixer.autoprototype.create_header") + "bettyfixer.autoprototype.create_header"), mocker.patch( + "bettyfixer.autoprototype.print_ctags_header_error") mock_check_header_file.return_value = (True, None) mock_generate_tags.return_value = True @@ -244,3 +251,6 @@ def test_autoproto(self, mocker): mock_create_header.assert_called_once_with( "test.h", mock_filter_tags.return_value) mocker.stopall() + # mock_check_header_file.return_value = (False, None) + # autoproto(".", "test.h") + # mock_ctag_print.assert_called_once() From ce314662642ccc48005ee7fe75c8d77481c61429 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 17 Feb 2024 17:42:15 +0300 Subject: [PATCH 36/91] Fix import statement in test_betty_fixer.py --- tests/test_betty_fixer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index b9bc9e6..ba3909c 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -4,7 +4,7 @@ import os import subprocess import pytest -from bettyfixer.betty_fixer import * as betty_fixer +# from bettyfixer.betty_fixer import * as betty_fixer class TestBettyFixer: From d1c2f974b89ff34a7975ce14a0a3931434c92f10 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:16 +0300 Subject: [PATCH 37/91] Add linter script for code quality checks --- linter.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 linter.sh diff --git a/linter.sh b/linter.sh new file mode 100644 index 0000000..e1d3ecb --- /dev/null +++ b/linter.sh @@ -0,0 +1,42 @@ +#!/bin/env bash + +# Get the current date and time +CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + +# Get the name of the person from git config +NAME=$(git config --get user.name) + +# path from the root of project to the directory where the log files will be saved +PATHLOG=$(git rev-parse --show-toplevel)/error_logs/linting +# Check if pylint is installed +if ! command -v pylint &> /dev/null +then + echo "pylint is not installed" + exit 1 +fi + +# Check if person's name is set in git config +if [ -z "$(git config --get user.name)" ] +then + echo "Please set your name in git config" + exit 1 +fi + + +if [ ! -d "$PATHLOG" ] +then + mkdir -p "$PATHLOG" +fi +# Loop over all command line arguments +for file in "$@" +do + # Change the file suffix to .txt + output_file="${file%.py}.txt" + + + echo -e "\n\nName: $NAME\n" >> "${PATHLOG}/${output_file}" + echo -e "Date: $CURRENT_DATE\n" >> "${PATHLOG}/${output_file}" + pylint "$file" + # Run pylint with the current command line argument + pylint "$file" --reports=y -f parseable >> "${PATHLOG}/${output_file}" +done \ No newline at end of file From bc6c0278830355cff1ea00330d33d8dea66a29c0 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:21 +0300 Subject: [PATCH 38/91] Fix code formatting and documentation issues --- errors_logs/autoprototype.txt | 135 ---------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 errors_logs/autoprototype.txt diff --git a/errors_logs/autoprototype.txt b/errors_logs/autoprototype.txt deleted file mode 100644 index e15e8e3..0000000 --- a/errors_logs/autoprototype.txt +++ /dev/null @@ -1,135 +0,0 @@ -************* Module bettyfixer.autoprototype -bettyfixer/autoprototype.py:12: [C0301(line-too-long), ] Line too long (124/100) -bettyfixer/autoprototype.py:28: [C0301(line-too-long), ] Line too long (123/100) -bettyfixer/autoprototype.py:36: [C0301(line-too-long), ] Line too long (106/100) -bettyfixer/autoprototype.py:44: [C0301(line-too-long), ] Line too long (143/100) -bettyfixer/autoprototype.py:53: [C0301(line-too-long), ] Line too long (199/100) -bettyfixer/autoprototype.py:54: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/autoprototype.py:85: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/autoprototype.py:87: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/autoprototype.py:90: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 -bettyfixer/autoprototype.py:91: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 -bettyfixer/autoprototype.py:92: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 -bettyfixer/autoprototype.py:92: [C0325(superfluous-parens), ] Unnecessary parens after 'if' keyword -bettyfixer/autoprototype.py:93: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 -bettyfixer/autoprototype.py:94: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 -bettyfixer/autoprototype.py:94: [C0325(superfluous-parens), ] Unnecessary parens after 'elif' keyword -bettyfixer/autoprototype.py:95: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 -bettyfixer/autoprototype.py:96: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 -bettyfixer/autoprototype.py:97: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 -bettyfixer/autoprototype.py:98: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/autoprototype.py:98: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 -bettyfixer/autoprototype.py:99: [W0311(bad-indentation), ] Bad indentation. Found 16 spaces, expected 12 -bettyfixer/autoprototype.py:100: [W0311(bad-indentation), ] Bad indentation. Found 16 spaces, expected 12 -bettyfixer/autoprototype.py:1: [C0114(missing-module-docstring), ] Missing module docstring -bettyfixer/autoprototype.py:9: [C0116(missing-function-docstring), betty_check] Missing function or method docstring -bettyfixer/autoprototype.py:27: [C0116(missing-function-docstring), print_check_betty_first] Missing function or method docstring -bettyfixer/autoprototype.py:29: [C0116(missing-function-docstring), print_header_name_missing] Missing function or method docstring -bettyfixer/autoprototype.py:31: [C0116(missing-function-docstring), print_Ctags_header_error] Missing function or method docstring -bettyfixer/autoprototype.py:31: [C0103(invalid-name), print_Ctags_header_error] Function name "print_Ctags_header_error" doesn't conform to snake_case naming style -bettyfixer/autoprototype.py:34: [C0116(missing-function-docstring), check_ctags] Missing function or method docstring -bettyfixer/autoprototype.py:42: [C0116(missing-function-docstring), generate_tags] Missing function or method docstring -bettyfixer/autoprototype.py:44: [W1309(f-string-without-interpolation), generate_tags] Using an f-string that does not have any interpolated variables -bettyfixer/autoprototype.py:49: [C0116(missing-function-docstring), filter_tags] Missing function or method docstring -bettyfixer/autoprototype.py:53: [C0209(consider-using-f-string), filter_tags] Formatting a regular string which could be an f-string -bettyfixer/autoprototype.py:59: [R1705(no-else-return), filter_tags] Unnecessary "else" after "return", remove the "else" and de-indent the code inside it -bettyfixer/autoprototype.py:60: [W1514(unspecified-encoding), filter_tags] Using open without explicitly specifying an encoding -bettyfixer/autoprototype.py:69: [C0116(missing-function-docstring), create_header] Missing function or method docstring -bettyfixer/autoprototype.py:73: [W1514(unspecified-encoding), create_header] Using open without explicitly specifying an encoding -bettyfixer/autoprototype.py:78: [C0116(missing-function-docstring), delete_files] Missing function or method docstring -bettyfixer/autoprototype.py:79: [C0209(consider-using-f-string), delete_files] Formatting a regular string which could be an f-string -bettyfixer/autoprototype.py:83: [C0116(missing-function-docstring), check_header_file] Missing function or method docstring -bettyfixer/autoprototype.py:89: [C0116(missing-function-docstring), autoproto] Missing function or method docstring -bettyfixer/autoprototype.py:96: [C0121(singleton-comparison), autoproto] Comparison 'generate_tags(directory) != False' should be 'generate_tags(directory) is not False' if checking for the singleton value False, or 'generate_tags(directory)' if testing for truthiness -bettyfixer/autoprototype.py:98: [C0121(singleton-comparison), autoproto] Comparison 'filtered_tags != None' should be 'filtered_tags is not None' -bettyfixer/autoprototype.py:6: [C0411(wrong-import-order), ] standard import "import glob" should be placed before "from colorama import Fore" -bettyfixer/autoprototype.py:1: [W0611(unused-import), ] Unused import argparse -bettyfixer/autoprototype.py:4: [W0611(unused-import), ] Unused import re - - -## Report -====== -**79 statements analysed.** - -Statistics by type ------------------- - -|type |number |old number |difference |%documented |%badname | -|---------|-------|-----------|-----------|------------|---------| -|module |1 |NC |NC |0.00 |0.00 | -|class |0 |NC |NC |0 |0 | -|method |0 |NC |NC |0 |0 | -|function |11 |NC |NC |0.00 |9.09 | - - - -External dependencies ---------------------- -:: - - colorama (bettyfixer.autoprototype) - - - -102 lines have been analyzed - -Raw metrics ------------ - -|type |number |% |previous |difference | -|----------|-------|------|---------|-----------| -|code |82 |80.39 |NC |NC | -|docstring |0 |0.00 |NC |NC | -|comment |5 |4.90 |NC |NC | -|empty |15 |14.71 |NC |NC | - - - -Duplication ------------ - -| |now |previous |difference | -|-------------------------|------|---------|-----------| -|nb duplicated lines |0 |NC |NC | -|percent duplicated lines |0.000 |NC |NC | - - - -Messages by category --------------------- - -|type |number |previous |difference | -|-----------|-------|---------|-----------| -|convention |29 |NC |NC | -|refactor |1 |NC |NC | -|warning |16 |NC |NC | -|error |0 |NC |NC | - - - -Messages --------- - -| message id | occurrences | -|--------------------------------|-------------| -| missing-function-docstring | 11 | -| bad-indentation | 11 | -| line-too-long | 5 | -| trailing-whitespace | 4 | -| unused-import | 2 | -| unspecified-encoding | 2 | -| superfluous-parens | 2 | -| singleton-comparison | 2 | -| consider-using-f-string | 2 | -| wrong-import-order | 1 | -| no-else-return | 1 | -| missing-module-docstring | 1 | -| invalid-name | 1 | -| f-string-without-interpolation | 1 | - - - - ------------------------------------ -Your code has been rated at 4.18/10 - From 70cf6d5be5f03fbd4bdd3646af00debc324dad4b Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:25 +0300 Subject: [PATCH 39/91] Remove backup.txt and fix code style issues --- errors_logs/backup.txt | 78 ------------------------------------------ 1 file changed, 78 deletions(-) delete mode 100644 errors_logs/backup.txt diff --git a/errors_logs/backup.txt b/errors_logs/backup.txt deleted file mode 100644 index 75fc26a..0000000 --- a/errors_logs/backup.txt +++ /dev/null @@ -1,78 +0,0 @@ -************* Module bettyfixer.backup -bettyfixer/backup.py:12: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/backup.py:13: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/backup.py:14: [C0305(trailing-newlines), ] Trailing newlines -bettyfixer/backup.py:1: [C0114(missing-module-docstring), ] Missing module docstring -bettyfixer/backup.py:3: [C0116(missing-function-docstring), create_backup] Missing function or method docstring -bettyfixer/backup.py:10: [W0718(broad-exception-caught), create_backup] Catching too general exception Exception - - -## Report -====== -**9 statements analysed.** - -Statistics by type ------------------- - -|type |number |old number |difference |%documented |%badname | -|---------|-------|-----------|-----------|------------|---------| -|module |1 |NC |NC |0.00 |0.00 | -|class |0 |NC |NC |0 |0 | -|method |0 |NC |NC |0 |0 | -|function |1 |NC |NC |0.00 |0.00 | - - - -16 lines have been analyzed - -Raw metrics ------------ - -| type | number | % | previous | difference | -|-----------|--------|-------|----------|------------| -| code | 11 | 68.75 | NC | NC | -| docstring | 0 | 0.00 | NC | NC | -| comment | 1 | 6.25 | NC | NC | -| empty | 4 | 25.00 | NC | NC | - - - -Duplication ------------ - -| |now |previous |difference | -|-------------------------|------|---------|-----------| -|nb duplicated lines |0 |NC |NC | -|percent duplicated lines |0.000 |NC |NC | - - - -Messages by category --------------------- - -|type |number |previous |difference | -|-----------|-------|---------|-----------| -|convention |5 |NC |NC | -|refactor |0 |NC |NC | -|warning |1 |NC |NC | -|error |0 |NC |NC | - - - -Messages --------- - -| message id | occurrences | -|---------------------------|-------------| -| trailing-whitespace | 2 | -| trailing-newlines | 1 | -| missing-module-docstring | 1 | -| missing-function-docstring| 1 | -| broad-exception-caught | 1 | - - - - ------------------------------------ -Your code has been rated at 3.33/10 - From c123ddbb223c328dbaef317a6ab01d19a1d42ceb Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:28 +0300 Subject: [PATCH 40/91] Refactor code to improve performance and readability --- errors_logs/betty_fixer.txt | 168 ------------------------------------ 1 file changed, 168 deletions(-) delete mode 100644 errors_logs/betty_fixer.txt diff --git a/errors_logs/betty_fixer.txt b/errors_logs/betty_fixer.txt deleted file mode 100644 index 5167a52..0000000 --- a/errors_logs/betty_fixer.txt +++ /dev/null @@ -1,168 +0,0 @@ -************* Module bettyfixer.betty_fixer -bettyfixer/betty_fixer.py:29: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/betty_fixer.py:117: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/betty_fixer.py:177: [C0301(line-too-long), ] Line too long (115/100) -bettyfixer/betty_fixer.py:208: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/betty_fixer.py:258: [C0301(line-too-long), ] Line too long (136/100) -bettyfixer/betty_fixer.py:273: [C0301(line-too-long), ] Line too long (130/100) -bettyfixer/betty_fixer.py:277: [C0301(line-too-long), ] Line too long (109/100) -bettyfixer/betty_fixer.py:303: [C0325(superfluous-parens), ] Unnecessary parens after 'if' keyword -bettyfixer/betty_fixer.py:330: [C0304(missing-final-newline), ] Final newline missing -bettyfixer/betty_fixer.py:1: [C0114(missing-module-docstring), ] Missing module docstring -bettyfixer/betty_fixer.py:4: [W0401(wildcard-import), ] Wildcard import bettyfixer.backup -bettyfixer/betty_fixer.py:5: [W0401(wildcard-import), ] Wildcard import bettyfixer.errors_extractor -bettyfixer/betty_fixer.py:6: [W0401(wildcard-import), ] Wildcard import bettyfixer.extract_line -bettyfixer/betty_fixer.py:7: [W0401(wildcard-import), ] Wildcard import bettyfixer.autoprototype -bettyfixer/betty_fixer.py:11: [C0116(missing-function-docstring), read_file] Missing function or method docstring -bettyfixer/betty_fixer.py:11: [W0621(redefined-outer-name), read_file] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:12: [W1514(unspecified-encoding), read_file] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:16: [C0116(missing-function-docstring), write_file] Missing function or method docstring -bettyfixer/betty_fixer.py:16: [W0621(redefined-outer-name), write_file] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:17: [W1514(unspecified-encoding), write_file] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:20: [C0116(missing-function-docstring), add_line_without_newline] Missing function or method docstring -bettyfixer/betty_fixer.py:20: [W0621(redefined-outer-name), add_line_without_newline] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:22: [W1514(unspecified-encoding), add_line_without_newline] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:27: [W1514(unspecified-encoding), add_line_without_newline] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:30: [C0116(missing-function-docstring), remove_consecutive_blank_lines] Missing function or method docstring -bettyfixer/betty_fixer.py:34: [C0116(missing-function-docstring), add_parentheses_around_return] Missing function or method docstring -bettyfixer/betty_fixer.py:48: [C0116(missing-function-docstring), fix_comments] Missing function or method docstring -bettyfixer/betty_fixer.py:52: [C0116(missing-function-docstring), remove_trailing_whitespaces] Missing function or method docstring -bettyfixer/betty_fixer.py:57: [C0116(missing-function-docstring), process_errors] Missing function or method docstring -bettyfixer/betty_fixer.py:57: [W0621(redefined-outer-name), process_errors] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:59: [W0621(redefined-outer-name), process_errors] Redefining name 'errors_file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:57: [W0613(unused-argument), process_errors] Unused argument 'file_path' -bettyfixer/betty_fixer.py:62: [C0116(missing-function-docstring), fix_betty_warnings] Missing function or method docstring -bettyfixer/betty_fixer.py:62: [W0621(redefined-outer-name), fix_betty_warnings] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:73: [C0116(missing-function-docstring), remove_blank_lines_inside_comments] Missing function or method docstring -bettyfixer/betty_fixer.py:73: [W0621(redefined-outer-name), remove_blank_lines_inside_comments] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:76: [W1514(unspecified-encoding), remove_blank_lines_inside_comments] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:91: [W1514(unspecified-encoding), remove_blank_lines_inside_comments] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:80: [R1702(too-many-nested-blocks), remove_blank_lines_inside_comments] Too many nested blocks (6/5) -bettyfixer/betty_fixer.py:94: [C0116(missing-function-docstring), fix_betty_style] Missing function or method docstring -bettyfixer/betty_fixer.py:95: [W0621(redefined-outer-name), fix_betty_style] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:111: [W0621(redefined-outer-name), fix_betty_style] Redefining name 'errors_file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:115: [W1514(unspecified-encoding), fix_betty_style] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:121: [W1514(unspecified-encoding), fix_betty_style] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:141: [C0116(missing-function-docstring), More_than_5_functions_in_the_file] Missing function or method docstring -bettyfixer/betty_fixer.py:141: [C0103(invalid-name), More_than_5_functions_in_the_file] Function name "More_than_5_functions_in_the_file" doesn't conform to snake_case naming style -bettyfixer/betty_fixer.py:141: [R0914(too-many-locals), More_than_5_functions_in_the_file] Too many local variables (17/15) -bettyfixer/betty_fixer.py:141: [W0621(redefined-outer-name), More_than_5_functions_in_the_file] Redefining name 'errors_file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:156: [W0621(redefined-outer-name), More_than_5_functions_in_the_file] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:148: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:158: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:182: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:185: [R1732(consider-using-with), More_than_5_functions_in_the_file] Consider using 'with' for resource-allocating operations -bettyfixer/betty_fixer.py:185: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:193: [C0116(missing-function-docstring), find_available_file_name] Missing function or method docstring -bettyfixer/betty_fixer.py:204: [C0116(missing-function-docstring), copy_remaining_lines] Missing function or method docstring -bettyfixer/betty_fixer.py:206: [W1514(unspecified-encoding), copy_remaining_lines] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:210: [C0116(missing-function-docstring), betty_handler] Missing function or method docstring -bettyfixer/betty_fixer.py:210: [W0621(redefined-outer-name), betty_handler] Redefining name 'errors_file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:225: [W0621(redefined-outer-name), betty_handler] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:211: [W1514(unspecified-encoding), betty_handler] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:228: [C0116(missing-function-docstring), other_handlers] Missing function or method docstring -bettyfixer/betty_fixer.py:228: [W0621(redefined-outer-name), other_handlers] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:229: [W0621(redefined-outer-name), other_handlers] Redefining name 'errors_file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:243: [C0116(missing-function-docstring), create_tasks_directory] Missing function or method docstring -bettyfixer/betty_fixer.py:248: [C0116(missing-function-docstring), copy_files_to_tasks] Missing function or method docstring -bettyfixer/betty_fixer.py:250: [W0621(redefined-outer-name), copy_files_to_tasks] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:254: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:261: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:265: [C0116(missing-function-docstring), modify_main_files] Missing function or method docstring -bettyfixer/betty_fixer.py:267: [W0621(redefined-outer-name), modify_main_files] Redefining name 'file_path' from outer scope (line 5) -bettyfixer/betty_fixer.py:269: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:276: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:280: [C0116(missing-function-docstring), record_processed_file] Missing function or method docstring -bettyfixer/betty_fixer.py:281: [W1514(unspecified-encoding), record_processed_file] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:284: [C0116(missing-function-docstring), is_file_processed] Missing function or method docstring -bettyfixer/betty_fixer.py:288: [W1514(unspecified-encoding), is_file_processed] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:292: [C0116(missing-function-docstring), main] Missing function or method docstring -bettyfixer/betty_fixer.py:303: [C0121(singleton-comparison), main] Comparison 'v == False' should be 'v is False' if checking for the singleton value False, or 'not v' if testing for falsiness -bettyfixer/betty_fixer.py:318: [R1732(consider-using-with), main] Consider using 'with' for resource-allocating operations -bettyfixer/betty_fixer.py:318: [W1514(unspecified-encoding), main] Using open without explicitly specifying an encoding -bettyfixer/betty_fixer.py:4: [W0614(unused-wildcard-import), ] Unused import(s) shutil from wildcard import of bettyfixer.backup -bettyfixer/betty_fixer.py:5: [W0614(unused-wildcard-import), ] Unused import(s) subprocess, errors_file_path and file_path from wildcard import of bettyfixer.errors_extractor -bettyfixer/betty_fixer.py:6: [W0614(unused-wildcard-import), ] Unused import(s) clean_up_line, fix_errors_from_file, should_be_void, fix_missing_blank_line_after_declaration, fix_should_be_foo_star_star_bar, fix_lines_in_file, generate_documentation, fix_space_prohibited_between_function_name_and_open_parenthesis, fix_space_prohibited_after_that_open_parenthesis, fix_space_prohibited_before_that_close_parenthesis, fix_space_required_before_the_open_parenthesis, fix_brace_on_the_next_line, brace_go_next_line, fix_brace_on_the_previous_line, fix_space_prohibited_before_semicolon, fix_should_be_foo_star_bar, fix_spaces_prohibited_around_that, fix_space_prohibited_after_that, fix_space_prohibited_before_that, fix_spaces_preferred_around_that, fix_space_required_around_that, fix_space_required_after_that, fix_space_required_before_the_open_brace and fix_space_required_after_the_close_brace from wildcard import of bettyfixer.extract_line -bettyfixer/betty_fixer.py:7: [W0614(unused-wildcard-import), ] Unused import(s) argparse, glob, print_Ctags_header_error, check_ctags, generate_tags, filter_tags, create_header, delete_files, check_header_file and Fore from wildcard import of bettyfixer.autoprototype - - - ## Report -====== -**210 statements analysed.** - -Statistics by type ------------------- - -|type |number |old number |difference |%documented |%badname | -|---------|-------|-----------|-----------|------------|---------| -|module |1 |NC |NC |0.00 |0.00 | -|class |0 |NC |NC |0 |0 | -|method |0 |NC |NC |0 |0 | -|function |22 |NC |NC |0.00 |4.55 | - - - -**332 lines have been analyzed** - -Raw metrics ------------ - -|type |number |% |previous |difference | -|----------|-------|------|---------|-----------| -|code |215 |64.76 |NC |NC | -|docstring |1 |0.30 |NC |NC | -|comment |50 |15.06 |NC |NC | -|empty |66 |19.88 |NC |NC | - - - -Duplication ------------ - -| |now |previous |difference | -|-------------------------|------|---------|-----------| -|nb duplicated lines |0 |NC |NC | -|percent duplicated lines |0.000 |NC |NC | - - - -Messages by category --------------------- - -|type |number |previous |difference | -|-----------|-------|---------|-----------| -|convention |34 |NC |NC | -|refactor |4 |NC |NC | -|warning |47 |NC |NC | -|error |0 |NC |NC | - - - -Messages --------- - -| message id | occurrences | -|---------------------------|-------------| -| missing-function-docstring| 22 | -| unspecified-encoding | 21 | -| redefined-outer-name | 17 | -| wildcard-import | 4 | -| unused-wildcard-import | 4 | -| line-too-long | 4 | -| trailing-whitespace | 3 | -| consider-using-with | 2 | -| unused-argument | 1 | -| too-many-nested-blocks | 1 | -| too-many-locals | 1 | -| superfluous-parens | 1 | -| singleton-comparison | 1 | -| missing-module-docstring | 1 | -| missing-final-newline | 1 | -| invalid-name | 1 | - - - - ------------------------------------ -Your code has been rated at 5.95/10 - From 15b27cd7d73e410e9da13e685a0a5c9423284c5e Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:32 +0300 Subject: [PATCH 41/91] Fix code style issues and remove unused file --- errors_logs/betty_handler.txt | 84 ----------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 errors_logs/betty_handler.txt diff --git a/errors_logs/betty_handler.txt b/errors_logs/betty_handler.txt deleted file mode 100644 index 6611154..0000000 --- a/errors_logs/betty_handler.txt +++ /dev/null @@ -1,84 +0,0 @@ -************* Module bettyfixer.betty_handler -bettyfixer/betty_handler.py:24: [C0301(line-too-long), ] Line too long (136/100) -bettyfixer/betty_handler.py:38: [C0301(line-too-long), ] Line too long (130/100) -bettyfixer/betty_handler.py:42: [C0301(line-too-long), ] Line too long (109/100) -bettyfixer/betty_handler.py:1: [C0114(missing-module-docstring), ] Missing module docstring -bettyfixer/betty_handler.py:4: [C0116(missing-function-docstring), other_handler] Missing function or method docstring -bettyfixer/betty_handler.py:9: [C0116(missing-function-docstring), create_tasks_directory] Missing function or method docstring -bettyfixer/betty_handler.py:14: [C0116(missing-function-docstring), copy_files_to_tasks] Missing function or method docstring -bettyfixer/betty_handler.py:20: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding -bettyfixer/betty_handler.py:27: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding -bettyfixer/betty_handler.py:30: [C0116(missing-function-docstring), modify_main_files] Missing function or method docstring -bettyfixer/betty_handler.py:34: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding -bettyfixer/betty_handler.py:41: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding - - -Report ------- -33 statements analysed. - -Statistics by type ------------------- - -|type |number |old number |difference |%documented |%badname | -|---------|-------|-----------|-----------|------------|---------| -|module |1 |NC |NC |0.00 |0.00 | -|class |0 |NC |NC |0 |0 | -|method |0 |NC |NC |0 |0 | -|function |4 |NC |NC |0.00 |0.00 | - -
- - -**61 lines have been analyzed** - -**Raw metrics** ------------ - -|type |number |% |previous |difference | -|----------|-------|------|---------|-----------| -|code |35 |57.38 |NC |NC | -|docstring |0 |0.00 |NC |NC | -|comment |13 |21.31 |NC |NC | -|empty |13 |21.31 |NC |NC | - -
- -Duplication ------------ - -| |now |previous |difference | -|-------------------------|------|---------|-----------| -|nb duplicated lines |0 |NC |NC | -|percent duplicated lines |0.000 |NC |NC | - - - -Messages by category --------------------- - -|type |number |previous |difference | -|-----------|-------|---------|-----------| -|convention |8 |NC |NC | -|refactor |0 |NC |NC | -|warning |4 |NC |NC | -|error |0 |NC |NC | - - - -Messages --------- - -|message id |occurrences | -|---------------------------|------------| -|unspecified-encoding |4 | -|missing-function-docstring |4 | -|line-too-long |3 | -|missing-module-docstring |1 | - - -
- ------------------------------------ -Your code has been rated at 6.36/10 - From 74529df31b6f0121d4b1576a806aa5255f199ba7 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:36 +0300 Subject: [PATCH 42/91] Remove errors_extractor.txt and fix code style issues --- errors_logs/errors_exractor.txt | 86 --------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 errors_logs/errors_exractor.txt diff --git a/errors_logs/errors_exractor.txt b/errors_logs/errors_exractor.txt deleted file mode 100644 index 9065d34..0000000 --- a/errors_logs/errors_exractor.txt +++ /dev/null @@ -1,86 +0,0 @@ -************* Module bettyfixer.errors_extractor -bettyfixer/errors_extractor.py:1: [C0114(missing-module-docstring), ] Missing module docstring -bettyfixer/errors_extractor.py:4: [C0116(missing-function-docstring), exctract_errors] Missing function or method docstring -bettyfixer/errors_extractor.py:4: [W0621(redefined-outer-name), exctract_errors] Redefining name 'file_path' from outer scope (line 36) -bettyfixer/errors_extractor.py:13: [W0621(redefined-outer-name), exctract_errors] Redefining name 'errors_file_path' from outer scope (line 30) -bettyfixer/errors_extractor.py:13: [W1514(unspecified-encoding), exctract_errors] Using open without explicitly specifying an encoding -bettyfixer/errors_extractor.py:17: [W0107(unnecessary-pass), exctract_errors] Unnecessary pass statement -bettyfixer/errors_extractor.py:19: [W1514(unspecified-encoding), exctract_errors] Using open without explicitly specifying an encoding -bettyfixer/errors_extractor.py:30: [C0103(invalid-name), ] Constant name "errors_file_path" doesn't conform to UPPER_CASE naming style -bettyfixer/errors_extractor.py:33: [R1732(consider-using-with), ] Consider using 'with' for resource-allocating operations -bettyfixer/errors_extractor.py:33: [W1514(unspecified-encoding), ] Using open without explicitly specifying an encoding - - -## Report ------- - -**21 statements analysed.** - -Statistics by type ------------------- - -|type |number |old number |difference |%documented |%badname | -|---------|-------|-----------|-----------|------------|---------| -|module |1 |NC |NC |0.00 |0.00 | -|class |0 |NC |NC |0 |0 | -|method |0 |NC |NC |0 |0 | -|function |1 |NC |NC |0.00 |0.00 | - - - -**39 lines have been analyzed** - -Raw metrics ------------ - -|type |number |% |previous |difference | -|----------|-------|------|---------|-----------| -|code |23 |58.97 |NC |NC | -|docstring |0 |0.00 |NC |NC | -|comment |9 |23.08 |NC |NC | -|empty |7 |17.95 |NC |NC | - - - -Duplication ------------ - -| |now |previous |difference | -|-------------------------|------|---------|-----------| -|nb duplicated lines |0 |NC |NC | -|percent duplicated lines |0.000 |NC |NC | - - - -Messages by category --------------------- - -|type |number |previous |difference | -|-----------|-------|---------|-----------| -|convention |3 |NC |NC | -|refactor |1 |NC |NC | -|warning |6 |NC |NC | -|error |0 |NC |NC | - - - -Messages --------- - -|message id |occurrences | -|---------------------------|------------| -|unspecified-encoding |3 | -|redefined-outer-name |2 | -|unnecessary-pass |1 | -|missing-module-docstring |1 | -|missing-function-docstring |1 | -|invalid-name |1 | -|consider-using-with |1 | - -
- - - ------------------------------------ -Your code has been rated at 5.24/10 - From 393b2e0e862af4f2119b6d0fb5716d0ceb7736a8 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:40 +0300 Subject: [PATCH 43/91] Update user authentication logic to use bcrypt for password hashing --- errors_logs/extract_line.txt | 247 ----------------------------------- 1 file changed, 247 deletions(-) delete mode 100644 errors_logs/extract_line.txt diff --git a/errors_logs/extract_line.txt b/errors_logs/extract_line.txt deleted file mode 100644 index 14ef1c1..0000000 --- a/errors_logs/extract_line.txt +++ /dev/null @@ -1,247 +0,0 @@ -************* Module bettyfixer.extract_line -bettyfixer/extract_line.py:31: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:78: [C0301(line-too-long), ] Line too long (122/100) -bettyfixer/extract_line.py:80: [C0301(line-too-long), ] Line too long (107/100) -bettyfixer/extract_line.py:82: [C0301(line-too-long), ] Line too long (109/100) -bettyfixer/extract_line.py:84: [C0301(line-too-long), ] Line too long (105/100) -bettyfixer/extract_line.py:148: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:187: [C0301(line-too-long), ] Line too long (106/100) -bettyfixer/extract_line.py:209: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:259: [C0301(line-too-long), ] Line too long (107/100) -bettyfixer/extract_line.py:262: [W0311(bad-indentation), ] Bad indentation. Found 16 spaces, expected 12 -bettyfixer/extract_line.py:267: [C0301(line-too-long), ] Line too long (102/100) -bettyfixer/extract_line.py:269: [C0301(line-too-long), ] Line too long (122/100) -bettyfixer/extract_line.py:276: [C0301(line-too-long), ] Line too long (180/100) -bettyfixer/extract_line.py:299: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:310: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:323: [C0301(line-too-long), ] Line too long (110/100) -bettyfixer/extract_line.py:327: [C0301(line-too-long), ] Line too long (119/100) -bettyfixer/extract_line.py:333: [C0301(line-too-long), ] Line too long (146/100) -bettyfixer/extract_line.py:341: [C0301(line-too-long), ] Line too long (104/100) -bettyfixer/extract_line.py:359: [C0301(line-too-long), ] Line too long (101/100) -bettyfixer/extract_line.py:361: [C0301(line-too-long), ] Line too long (113/100) -bettyfixer/extract_line.py:368: [C0301(line-too-long), ] Line too long (111/100) -bettyfixer/extract_line.py:382: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:388: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:452: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:504: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:507: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:517: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:519: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:570: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:580: [C0301(line-too-long), ] Line too long (117/100) -bettyfixer/extract_line.py:584: [C0301(line-too-long), ] Line too long (151/100) -bettyfixer/extract_line.py:589: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:649: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:671: [C0325(superfluous-parens), ] Unnecessary parens after 'not' keyword -bettyfixer/extract_line.py:700: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:743: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:784: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:807: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:822: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:834: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:857: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:872: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:884: [C0303(trailing-whitespace), ] Trailing whitespace -bettyfixer/extract_line.py:1: [C0114(missing-module-docstring), ] Missing module docstring -bettyfixer/extract_line.py:7: [C0116(missing-function-docstring), run_vi_script] Missing function or method docstring -bettyfixer/extract_line.py:11: [W1510(subprocess-run-check), run_vi_script] 'subprocess.run' used without explicitly defining the value for 'check'. -bettyfixer/extract_line.py:13: [C0116(missing-function-docstring), remove_extra_spaces] Missing function or method docstring -bettyfixer/extract_line.py:24: [C0116(missing-function-docstring), process_error_file] Missing function or method docstring -bettyfixer/extract_line.py:24: [W0621(redefined-outer-name), process_error_file] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:25: [W1514(unspecified-encoding), process_error_file] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:32: [C0116(missing-function-docstring), extract_and_print_variables] Missing function or method docstring -bettyfixer/extract_line.py:44: [C0116(missing-function-docstring), clean_up_line] Missing function or method docstring -bettyfixer/extract_line.py:53: [C0116(missing-function-docstring), fix_errors_from_file] Missing function or method docstring -bettyfixer/extract_line.py:53: [R0912(too-many-branches), fix_errors_from_file] Too many branches (18/12) -bettyfixer/extract_line.py:110: [C0116(missing-function-docstring), fix_should_be_void] Missing function or method docstring -bettyfixer/extract_line.py:110: [W0621(redefined-outer-name), fix_should_be_void] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:116: [W1514(unspecified-encoding), fix_should_be_void] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:132: [C0116(missing-function-docstring), should_be_void] Missing function or method docstring -bettyfixer/extract_line.py:132: [W0621(redefined-outer-name), should_be_void] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:139: [W1514(unspecified-encoding), should_be_void] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:146: [W1514(unspecified-encoding), should_be_void] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:159: [C0116(missing-function-docstring), clean_errors_file] Missing function or method docstring -bettyfixer/extract_line.py:159: [W0621(redefined-outer-name), clean_errors_file] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:163: [R1732(consider-using-with), clean_errors_file] Consider using 'with' for resource-allocating operations -bettyfixer/extract_line.py:163: [W1514(unspecified-encoding), clean_errors_file] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:169: [C0116(missing-function-docstring), fix_missing_blank_line_after_declarations] Missing function or method docstring -bettyfixer/extract_line.py:169: [W0621(redefined-outer-name), fix_missing_blank_line_after_declarations] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:175: [W1514(unspecified-encoding), fix_missing_blank_line_after_declarations] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:190: [C0116(missing-function-docstring), fix_missing_blank_line_after_declaration] Missing function or method docstring -bettyfixer/extract_line.py:190: [W0621(redefined-outer-name), fix_missing_blank_line_after_declaration] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:195: [W1514(unspecified-encoding), fix_missing_blank_line_after_declaration] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:207: [W1514(unspecified-encoding), fix_missing_blank_line_after_declaration] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:215: [C0116(missing-function-docstring), fix_should_be_foo_star_star_bar] Missing function or method docstring -bettyfixer/extract_line.py:220: [W1514(unspecified-encoding), fix_should_be_foo_star_star_bar] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:227: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:229: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:231: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:233: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:243: [W1514(unspecified-encoding), fix_should_be_foo_star_star_bar] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:246: [C0116(missing-function-docstring), remove_unused_attribute] Missing function or method docstring -bettyfixer/extract_line.py:283: [W0718(broad-exception-caught), remove_unused_attribute] Catching too general exception Exception -bettyfixer/extract_line.py:248: [W1514(unspecified-encoding), remove_unused_attribute] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:279: [W1514(unspecified-encoding), remove_unused_attribute] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:264: [W0612(unused-variable), remove_unused_attribute] Unused variable 'original_declaration' -bettyfixer/extract_line.py:286: [C0116(missing-function-docstring), fix_lines_in_file] Missing function or method docstring -bettyfixer/extract_line.py:308: [W0718(broad-exception-caught), fix_lines_in_file] Catching too general exception Exception -bettyfixer/extract_line.py:288: [W1514(unspecified-encoding), fix_lines_in_file] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:306: [W1514(unspecified-encoding), fix_lines_in_file] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:287: [R1702(too-many-nested-blocks), fix_lines_in_file] Too many nested blocks (6/5) -bettyfixer/extract_line.py:311: [C0116(missing-function-docstring), generate_documentation] Missing function or method docstring -bettyfixer/extract_line.py:352: [C0116(missing-function-docstring), extract_functions_with_no_description] Missing function or method docstring -bettyfixer/extract_line.py:355: [W1514(unspecified-encoding), extract_functions_with_no_description] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:368: [C0116(missing-function-docstring), fix_space_prohibited_between_function_name_and_open_parenthesis] Missing function or method docstring -bettyfixer/extract_line.py:374: [W1514(unspecified-encoding), fix_space_prohibited_between_function_name_and_open_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:387: [W1514(unspecified-encoding), fix_space_prohibited_between_function_name_and_open_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:389: [C0116(missing-function-docstring), fix_space_prohibited_after_that_open_parenthesis] Missing function or method docstring -bettyfixer/extract_line.py:395: [W1514(unspecified-encoding), fix_space_prohibited_after_that_open_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:408: [W1514(unspecified-encoding), fix_space_prohibited_after_that_open_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:410: [C0116(missing-function-docstring), fix_space_prohibited_before_that_close_parenthesis] Missing function or method docstring -bettyfixer/extract_line.py:416: [W1514(unspecified-encoding), fix_space_prohibited_before_that_close_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:429: [W1514(unspecified-encoding), fix_space_prohibited_before_that_close_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:431: [C0116(missing-function-docstring), fix_space_required_before_the_open_parenthesis] Missing function or method docstring -bettyfixer/extract_line.py:437: [W1514(unspecified-encoding), fix_space_required_before_the_open_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:450: [W1514(unspecified-encoding), fix_space_required_before_the_open_parenthesis] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:453: [C0116(missing-function-docstring), fix_brace_should_be_on_the_next_line] Missing function or method docstring -bettyfixer/extract_line.py:453: [W0621(redefined-outer-name), fix_brace_should_be_on_the_next_line] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:459: [W1514(unspecified-encoding), fix_brace_should_be_on_the_next_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:492: [C0116(missing-function-docstring), fix_brace_on_the_next_line] Missing function or method docstring -bettyfixer/extract_line.py:492: [W0621(redefined-outer-name), fix_brace_on_the_next_line] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:497: [W1514(unspecified-encoding), fix_brace_on_the_next_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:509: [W1514(unspecified-encoding), fix_brace_on_the_next_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:520: [C0116(missing-function-docstring), brace_go_next_line] Missing function or method docstring -bettyfixer/extract_line.py:524: [W1514(unspecified-encoding), brace_go_next_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:539: [W1514(unspecified-encoding), brace_go_next_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:542: [C0116(missing-function-docstring), fix_brace_should_be_on_the_previous_line] Missing function or method docstring -bettyfixer/extract_line.py:542: [W0621(redefined-outer-name), fix_brace_should_be_on_the_previous_line] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:548: [W1514(unspecified-encoding), fix_brace_should_be_on_the_previous_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:563: [C0116(missing-function-docstring), fix_brace_on_the_previous_line] Missing function or method docstring -bettyfixer/extract_line.py:563: [W0621(redefined-outer-name), fix_brace_on_the_previous_line] Redefining name 'errors_file_path' from outer scope (line 968) -bettyfixer/extract_line.py:568: [W1514(unspecified-encoding), fix_brace_on_the_previous_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:587: [W1514(unspecified-encoding), fix_brace_on_the_previous_line] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:596: [C0116(missing-function-docstring), fix_space_prohibited_before_semicolon] Missing function or method docstring -bettyfixer/extract_line.py:599: [W1514(unspecified-encoding), fix_space_prohibited_before_semicolon] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:613: [W1514(unspecified-encoding), fix_space_prohibited_before_semicolon] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:615: [C0116(missing-function-docstring), fix_should_be_foo_star_bar] Missing function or method docstring -bettyfixer/extract_line.py:620: [W1514(unspecified-encoding), fix_should_be_foo_star_bar] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:627: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:629: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:631: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:633: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables -bettyfixer/extract_line.py:643: [W1514(unspecified-encoding), fix_should_be_foo_star_bar] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:645: [C0116(missing-function-docstring), fix_spaces_prohibited_around_that] Missing function or method docstring -bettyfixer/extract_line.py:667: [W1514(unspecified-encoding), fix_spaces_prohibited_around_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:693: [W1514(unspecified-encoding), fix_spaces_prohibited_around_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:696: [C0116(missing-function-docstring), fix_space_prohibited_after_that] Missing function or method docstring -bettyfixer/extract_line.py:718: [W1514(unspecified-encoding), fix_space_prohibited_after_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:737: [W1514(unspecified-encoding), fix_space_prohibited_after_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:739: [C0116(missing-function-docstring), fix_space_prohibited_before_that] Missing function or method docstring -bettyfixer/extract_line.py:761: [W1514(unspecified-encoding), fix_space_prohibited_before_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:768: [R1714(consider-using-in), fix_space_prohibited_before_that] Consider merging these comparisons with 'in' by using 'context in ('WxV', 'WxO', 'WxE', 'WxW')'. Use a set instead if elements are hashable. -bettyfixer/extract_line.py:778: [W1514(unspecified-encoding), fix_space_prohibited_before_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:780: [C0116(missing-function-docstring), fix_spaces_preferred_around_that] Missing function or method docstring -bettyfixer/extract_line.py:802: [W1514(unspecified-encoding), fix_spaces_preferred_around_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:828: [W1514(unspecified-encoding), fix_spaces_preferred_around_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:830: [C0116(missing-function-docstring), fix_space_required_around_that] Missing function or method docstring -bettyfixer/extract_line.py:852: [W1514(unspecified-encoding), fix_space_required_around_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:878: [W1514(unspecified-encoding), fix_space_required_around_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:880: [C0116(missing-function-docstring), fix_space_required_after_that] Missing function or method docstring -bettyfixer/extract_line.py:902: [W1514(unspecified-encoding), fix_space_required_after_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:909: [R1714(consider-using-in), fix_space_required_after_that] Consider merging these comparisons with 'in' by using 'context in ('WxV', 'VxV')'. Use a set instead if elements are hashable. -bettyfixer/extract_line.py:919: [W1514(unspecified-encoding), fix_space_required_after_that] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:921: [C0116(missing-function-docstring), fix_space_required_before_the_open_brace] Missing function or method docstring -bettyfixer/extract_line.py:927: [W1514(unspecified-encoding), fix_space_required_before_the_open_brace] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:940: [W1514(unspecified-encoding), fix_space_required_before_the_open_brace] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:942: [C0116(missing-function-docstring), fix_space_required_after_the_close_brace] Missing function or method docstring -bettyfixer/extract_line.py:948: [W1514(unspecified-encoding), fix_space_required_after_the_close_brace] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:961: [W1514(unspecified-encoding), fix_space_required_after_the_close_brace] Using open without explicitly specifying an encoding -bettyfixer/extract_line.py:968: [C0103(invalid-name), ] Constant name "errors_file_path" doesn't conform to UPPER_CASE naming style -bettyfixer/extract_line.py:4: [C0411(wrong-import-order), ] standard import "import os" should be placed before "from bettyfixer.errors_extractor import exctract_errors" -bettyfixer/extract_line.py:5: [C0411(wrong-import-order), ] standard import "import subprocess" should be placed before "from bettyfixer.errors_extractor import exctract_errors" - - - ## Report - -**522 statements analysed.** - -Statistics by type ------------------- - -| type | number | old number | difference | %documented | %badname | -|----------|--------|------------|------------|-------------|----------| -| module | 1 | 1 | = | 0.00 | 0.00 | -| class | 0 | NC | NC | 0 | 0 | -| method | 0 | NC | NC | 0 | 0 | -| function | 35 | 35 | = | 0.00 | 0.00 | - - -**971 lines have been analyzed** - -Raw metrics ------------ - -|type |number |% |previous |difference | -|----------|-------|------|---------|-----------| -|code |536 |55.20 |NC |NC | -|docstring |16 |1.65 |NC |NC | -|comment |206 |21.22 |NC |NC | -|empty |213 |21.94 |NC |NC | - - - -Duplication ------------ - -| |now |previous |difference | -|-------------------------|------|---------|-----------| -|nb duplicated lines |0 |0 |0 | -|percent duplicated lines |0.000 |0.000 |= | - - - -Messages by category --------------------- - -|type |number |previous |difference | -|-----------|-------|---------|-----------| -|convention |82 |82 |82 | -|refactor |5 |5 |5 | -|warning |74 |74 |74 | -|error |0 |0 |0 | - - - -Messages --------- - - -| message id | occurrences | -|------------------------------- | ------------| -| unspecified-encoding | 51 | -| missing-function-docstring | 35 | -| trailing-whitespace | 24 | -| line-too-long | 18 | -| redefined-outer-name | 10 | -| f-string-without-interpolation | 8 | -| wrong-import-order | 2 | -| consider-using-in | 2 | -| broad-exception-caught | 2 | -| unused-variable | 1 | -| too-many-nested-blocks | 1 | -| too-many-branches | 1 | -| superfluous-parens | 1 | -| subprocess-run-check | 1 | -| missing-module-docstring | 1 | -| invalid-name | 1 | -| consider-using-with | 1 | -| bad-indentation | 1 | - - - - - ------------------------------------------------------------------- -Your code has been rated at 6.92/10 (previous run: 6.92/10, +0.00) - From 48381b384a936b16ea2300f5f7e121fbc5f8ddbf Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:43 +0300 Subject: [PATCH 44/91] Fix linting issues and improve code quality --- errors_logs/linting/autoprototype.txt | 135 ++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 errors_logs/linting/autoprototype.txt diff --git a/errors_logs/linting/autoprototype.txt b/errors_logs/linting/autoprototype.txt new file mode 100644 index 0000000..e15e8e3 --- /dev/null +++ b/errors_logs/linting/autoprototype.txt @@ -0,0 +1,135 @@ +************* Module bettyfixer.autoprototype +bettyfixer/autoprototype.py:12: [C0301(line-too-long), ] Line too long (124/100) +bettyfixer/autoprototype.py:28: [C0301(line-too-long), ] Line too long (123/100) +bettyfixer/autoprototype.py:36: [C0301(line-too-long), ] Line too long (106/100) +bettyfixer/autoprototype.py:44: [C0301(line-too-long), ] Line too long (143/100) +bettyfixer/autoprototype.py:53: [C0301(line-too-long), ] Line too long (199/100) +bettyfixer/autoprototype.py:54: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/autoprototype.py:85: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/autoprototype.py:87: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/autoprototype.py:90: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 +bettyfixer/autoprototype.py:91: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 +bettyfixer/autoprototype.py:92: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 +bettyfixer/autoprototype.py:92: [C0325(superfluous-parens), ] Unnecessary parens after 'if' keyword +bettyfixer/autoprototype.py:93: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 +bettyfixer/autoprototype.py:94: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 +bettyfixer/autoprototype.py:94: [C0325(superfluous-parens), ] Unnecessary parens after 'elif' keyword +bettyfixer/autoprototype.py:95: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 +bettyfixer/autoprototype.py:96: [W0311(bad-indentation), ] Bad indentation. Found 8 spaces, expected 4 +bettyfixer/autoprototype.py:97: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 +bettyfixer/autoprototype.py:98: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/autoprototype.py:98: [W0311(bad-indentation), ] Bad indentation. Found 12 spaces, expected 8 +bettyfixer/autoprototype.py:99: [W0311(bad-indentation), ] Bad indentation. Found 16 spaces, expected 12 +bettyfixer/autoprototype.py:100: [W0311(bad-indentation), ] Bad indentation. Found 16 spaces, expected 12 +bettyfixer/autoprototype.py:1: [C0114(missing-module-docstring), ] Missing module docstring +bettyfixer/autoprototype.py:9: [C0116(missing-function-docstring), betty_check] Missing function or method docstring +bettyfixer/autoprototype.py:27: [C0116(missing-function-docstring), print_check_betty_first] Missing function or method docstring +bettyfixer/autoprototype.py:29: [C0116(missing-function-docstring), print_header_name_missing] Missing function or method docstring +bettyfixer/autoprototype.py:31: [C0116(missing-function-docstring), print_Ctags_header_error] Missing function or method docstring +bettyfixer/autoprototype.py:31: [C0103(invalid-name), print_Ctags_header_error] Function name "print_Ctags_header_error" doesn't conform to snake_case naming style +bettyfixer/autoprototype.py:34: [C0116(missing-function-docstring), check_ctags] Missing function or method docstring +bettyfixer/autoprototype.py:42: [C0116(missing-function-docstring), generate_tags] Missing function or method docstring +bettyfixer/autoprototype.py:44: [W1309(f-string-without-interpolation), generate_tags] Using an f-string that does not have any interpolated variables +bettyfixer/autoprototype.py:49: [C0116(missing-function-docstring), filter_tags] Missing function or method docstring +bettyfixer/autoprototype.py:53: [C0209(consider-using-f-string), filter_tags] Formatting a regular string which could be an f-string +bettyfixer/autoprototype.py:59: [R1705(no-else-return), filter_tags] Unnecessary "else" after "return", remove the "else" and de-indent the code inside it +bettyfixer/autoprototype.py:60: [W1514(unspecified-encoding), filter_tags] Using open without explicitly specifying an encoding +bettyfixer/autoprototype.py:69: [C0116(missing-function-docstring), create_header] Missing function or method docstring +bettyfixer/autoprototype.py:73: [W1514(unspecified-encoding), create_header] Using open without explicitly specifying an encoding +bettyfixer/autoprototype.py:78: [C0116(missing-function-docstring), delete_files] Missing function or method docstring +bettyfixer/autoprototype.py:79: [C0209(consider-using-f-string), delete_files] Formatting a regular string which could be an f-string +bettyfixer/autoprototype.py:83: [C0116(missing-function-docstring), check_header_file] Missing function or method docstring +bettyfixer/autoprototype.py:89: [C0116(missing-function-docstring), autoproto] Missing function or method docstring +bettyfixer/autoprototype.py:96: [C0121(singleton-comparison), autoproto] Comparison 'generate_tags(directory) != False' should be 'generate_tags(directory) is not False' if checking for the singleton value False, or 'generate_tags(directory)' if testing for truthiness +bettyfixer/autoprototype.py:98: [C0121(singleton-comparison), autoproto] Comparison 'filtered_tags != None' should be 'filtered_tags is not None' +bettyfixer/autoprototype.py:6: [C0411(wrong-import-order), ] standard import "import glob" should be placed before "from colorama import Fore" +bettyfixer/autoprototype.py:1: [W0611(unused-import), ] Unused import argparse +bettyfixer/autoprototype.py:4: [W0611(unused-import), ] Unused import re + + +## Report +====== +**79 statements analysed.** + +Statistics by type +------------------ + +|type |number |old number |difference |%documented |%badname | +|---------|-------|-----------|-----------|------------|---------| +|module |1 |NC |NC |0.00 |0.00 | +|class |0 |NC |NC |0 |0 | +|method |0 |NC |NC |0 |0 | +|function |11 |NC |NC |0.00 |9.09 | + + + +External dependencies +--------------------- +:: + + colorama (bettyfixer.autoprototype) + + + +102 lines have been analyzed + +Raw metrics +----------- + +|type |number |% |previous |difference | +|----------|-------|------|---------|-----------| +|code |82 |80.39 |NC |NC | +|docstring |0 |0.00 |NC |NC | +|comment |5 |4.90 |NC |NC | +|empty |15 |14.71 |NC |NC | + + + +Duplication +----------- + +| |now |previous |difference | +|-------------------------|------|---------|-----------| +|nb duplicated lines |0 |NC |NC | +|percent duplicated lines |0.000 |NC |NC | + + + +Messages by category +-------------------- + +|type |number |previous |difference | +|-----------|-------|---------|-----------| +|convention |29 |NC |NC | +|refactor |1 |NC |NC | +|warning |16 |NC |NC | +|error |0 |NC |NC | + + + +Messages +-------- + +| message id | occurrences | +|--------------------------------|-------------| +| missing-function-docstring | 11 | +| bad-indentation | 11 | +| line-too-long | 5 | +| trailing-whitespace | 4 | +| unused-import | 2 | +| unspecified-encoding | 2 | +| superfluous-parens | 2 | +| singleton-comparison | 2 | +| consider-using-f-string | 2 | +| wrong-import-order | 1 | +| no-else-return | 1 | +| missing-module-docstring | 1 | +| invalid-name | 1 | +| f-string-without-interpolation | 1 | + + + + +----------------------------------- +Your code has been rated at 4.18/10 + From 3b02d41c3bba50d19d2d690a5269bef103fb735a Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:47 +0300 Subject: [PATCH 45/91] Fix linting issues and improve code quality --- errors_logs/linting/backup.txt | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 errors_logs/linting/backup.txt diff --git a/errors_logs/linting/backup.txt b/errors_logs/linting/backup.txt new file mode 100644 index 0000000..75fc26a --- /dev/null +++ b/errors_logs/linting/backup.txt @@ -0,0 +1,78 @@ +************* Module bettyfixer.backup +bettyfixer/backup.py:12: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/backup.py:13: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/backup.py:14: [C0305(trailing-newlines), ] Trailing newlines +bettyfixer/backup.py:1: [C0114(missing-module-docstring), ] Missing module docstring +bettyfixer/backup.py:3: [C0116(missing-function-docstring), create_backup] Missing function or method docstring +bettyfixer/backup.py:10: [W0718(broad-exception-caught), create_backup] Catching too general exception Exception + + +## Report +====== +**9 statements analysed.** + +Statistics by type +------------------ + +|type |number |old number |difference |%documented |%badname | +|---------|-------|-----------|-----------|------------|---------| +|module |1 |NC |NC |0.00 |0.00 | +|class |0 |NC |NC |0 |0 | +|method |0 |NC |NC |0 |0 | +|function |1 |NC |NC |0.00 |0.00 | + + + +16 lines have been analyzed + +Raw metrics +----------- + +| type | number | % | previous | difference | +|-----------|--------|-------|----------|------------| +| code | 11 | 68.75 | NC | NC | +| docstring | 0 | 0.00 | NC | NC | +| comment | 1 | 6.25 | NC | NC | +| empty | 4 | 25.00 | NC | NC | + + + +Duplication +----------- + +| |now |previous |difference | +|-------------------------|------|---------|-----------| +|nb duplicated lines |0 |NC |NC | +|percent duplicated lines |0.000 |NC |NC | + + + +Messages by category +-------------------- + +|type |number |previous |difference | +|-----------|-------|---------|-----------| +|convention |5 |NC |NC | +|refactor |0 |NC |NC | +|warning |1 |NC |NC | +|error |0 |NC |NC | + + + +Messages +-------- + +| message id | occurrences | +|---------------------------|-------------| +| trailing-whitespace | 2 | +| trailing-newlines | 1 | +| missing-module-docstring | 1 | +| missing-function-docstring| 1 | +| broad-exception-caught | 1 | + + + + +----------------------------------- +Your code has been rated at 3.33/10 + From 32ff8d8aff04285e017766409be8cbd75bfae2e9 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:50 +0300 Subject: [PATCH 46/91] Update user authentication logic --- errors_logs/linting/betty_fixer.txt | 168 ++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 errors_logs/linting/betty_fixer.txt diff --git a/errors_logs/linting/betty_fixer.txt b/errors_logs/linting/betty_fixer.txt new file mode 100644 index 0000000..5167a52 --- /dev/null +++ b/errors_logs/linting/betty_fixer.txt @@ -0,0 +1,168 @@ +************* Module bettyfixer.betty_fixer +bettyfixer/betty_fixer.py:29: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/betty_fixer.py:117: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/betty_fixer.py:177: [C0301(line-too-long), ] Line too long (115/100) +bettyfixer/betty_fixer.py:208: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/betty_fixer.py:258: [C0301(line-too-long), ] Line too long (136/100) +bettyfixer/betty_fixer.py:273: [C0301(line-too-long), ] Line too long (130/100) +bettyfixer/betty_fixer.py:277: [C0301(line-too-long), ] Line too long (109/100) +bettyfixer/betty_fixer.py:303: [C0325(superfluous-parens), ] Unnecessary parens after 'if' keyword +bettyfixer/betty_fixer.py:330: [C0304(missing-final-newline), ] Final newline missing +bettyfixer/betty_fixer.py:1: [C0114(missing-module-docstring), ] Missing module docstring +bettyfixer/betty_fixer.py:4: [W0401(wildcard-import), ] Wildcard import bettyfixer.backup +bettyfixer/betty_fixer.py:5: [W0401(wildcard-import), ] Wildcard import bettyfixer.errors_extractor +bettyfixer/betty_fixer.py:6: [W0401(wildcard-import), ] Wildcard import bettyfixer.extract_line +bettyfixer/betty_fixer.py:7: [W0401(wildcard-import), ] Wildcard import bettyfixer.autoprototype +bettyfixer/betty_fixer.py:11: [C0116(missing-function-docstring), read_file] Missing function or method docstring +bettyfixer/betty_fixer.py:11: [W0621(redefined-outer-name), read_file] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:12: [W1514(unspecified-encoding), read_file] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:16: [C0116(missing-function-docstring), write_file] Missing function or method docstring +bettyfixer/betty_fixer.py:16: [W0621(redefined-outer-name), write_file] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:17: [W1514(unspecified-encoding), write_file] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:20: [C0116(missing-function-docstring), add_line_without_newline] Missing function or method docstring +bettyfixer/betty_fixer.py:20: [W0621(redefined-outer-name), add_line_without_newline] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:22: [W1514(unspecified-encoding), add_line_without_newline] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:27: [W1514(unspecified-encoding), add_line_without_newline] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:30: [C0116(missing-function-docstring), remove_consecutive_blank_lines] Missing function or method docstring +bettyfixer/betty_fixer.py:34: [C0116(missing-function-docstring), add_parentheses_around_return] Missing function or method docstring +bettyfixer/betty_fixer.py:48: [C0116(missing-function-docstring), fix_comments] Missing function or method docstring +bettyfixer/betty_fixer.py:52: [C0116(missing-function-docstring), remove_trailing_whitespaces] Missing function or method docstring +bettyfixer/betty_fixer.py:57: [C0116(missing-function-docstring), process_errors] Missing function or method docstring +bettyfixer/betty_fixer.py:57: [W0621(redefined-outer-name), process_errors] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:59: [W0621(redefined-outer-name), process_errors] Redefining name 'errors_file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:57: [W0613(unused-argument), process_errors] Unused argument 'file_path' +bettyfixer/betty_fixer.py:62: [C0116(missing-function-docstring), fix_betty_warnings] Missing function or method docstring +bettyfixer/betty_fixer.py:62: [W0621(redefined-outer-name), fix_betty_warnings] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:73: [C0116(missing-function-docstring), remove_blank_lines_inside_comments] Missing function or method docstring +bettyfixer/betty_fixer.py:73: [W0621(redefined-outer-name), remove_blank_lines_inside_comments] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:76: [W1514(unspecified-encoding), remove_blank_lines_inside_comments] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:91: [W1514(unspecified-encoding), remove_blank_lines_inside_comments] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:80: [R1702(too-many-nested-blocks), remove_blank_lines_inside_comments] Too many nested blocks (6/5) +bettyfixer/betty_fixer.py:94: [C0116(missing-function-docstring), fix_betty_style] Missing function or method docstring +bettyfixer/betty_fixer.py:95: [W0621(redefined-outer-name), fix_betty_style] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:111: [W0621(redefined-outer-name), fix_betty_style] Redefining name 'errors_file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:115: [W1514(unspecified-encoding), fix_betty_style] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:121: [W1514(unspecified-encoding), fix_betty_style] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:141: [C0116(missing-function-docstring), More_than_5_functions_in_the_file] Missing function or method docstring +bettyfixer/betty_fixer.py:141: [C0103(invalid-name), More_than_5_functions_in_the_file] Function name "More_than_5_functions_in_the_file" doesn't conform to snake_case naming style +bettyfixer/betty_fixer.py:141: [R0914(too-many-locals), More_than_5_functions_in_the_file] Too many local variables (17/15) +bettyfixer/betty_fixer.py:141: [W0621(redefined-outer-name), More_than_5_functions_in_the_file] Redefining name 'errors_file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:156: [W0621(redefined-outer-name), More_than_5_functions_in_the_file] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:148: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:158: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:182: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:185: [R1732(consider-using-with), More_than_5_functions_in_the_file] Consider using 'with' for resource-allocating operations +bettyfixer/betty_fixer.py:185: [W1514(unspecified-encoding), More_than_5_functions_in_the_file] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:193: [C0116(missing-function-docstring), find_available_file_name] Missing function or method docstring +bettyfixer/betty_fixer.py:204: [C0116(missing-function-docstring), copy_remaining_lines] Missing function or method docstring +bettyfixer/betty_fixer.py:206: [W1514(unspecified-encoding), copy_remaining_lines] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:210: [C0116(missing-function-docstring), betty_handler] Missing function or method docstring +bettyfixer/betty_fixer.py:210: [W0621(redefined-outer-name), betty_handler] Redefining name 'errors_file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:225: [W0621(redefined-outer-name), betty_handler] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:211: [W1514(unspecified-encoding), betty_handler] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:228: [C0116(missing-function-docstring), other_handlers] Missing function or method docstring +bettyfixer/betty_fixer.py:228: [W0621(redefined-outer-name), other_handlers] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:229: [W0621(redefined-outer-name), other_handlers] Redefining name 'errors_file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:243: [C0116(missing-function-docstring), create_tasks_directory] Missing function or method docstring +bettyfixer/betty_fixer.py:248: [C0116(missing-function-docstring), copy_files_to_tasks] Missing function or method docstring +bettyfixer/betty_fixer.py:250: [W0621(redefined-outer-name), copy_files_to_tasks] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:254: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:261: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:265: [C0116(missing-function-docstring), modify_main_files] Missing function or method docstring +bettyfixer/betty_fixer.py:267: [W0621(redefined-outer-name), modify_main_files] Redefining name 'file_path' from outer scope (line 5) +bettyfixer/betty_fixer.py:269: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:276: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:280: [C0116(missing-function-docstring), record_processed_file] Missing function or method docstring +bettyfixer/betty_fixer.py:281: [W1514(unspecified-encoding), record_processed_file] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:284: [C0116(missing-function-docstring), is_file_processed] Missing function or method docstring +bettyfixer/betty_fixer.py:288: [W1514(unspecified-encoding), is_file_processed] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:292: [C0116(missing-function-docstring), main] Missing function or method docstring +bettyfixer/betty_fixer.py:303: [C0121(singleton-comparison), main] Comparison 'v == False' should be 'v is False' if checking for the singleton value False, or 'not v' if testing for falsiness +bettyfixer/betty_fixer.py:318: [R1732(consider-using-with), main] Consider using 'with' for resource-allocating operations +bettyfixer/betty_fixer.py:318: [W1514(unspecified-encoding), main] Using open without explicitly specifying an encoding +bettyfixer/betty_fixer.py:4: [W0614(unused-wildcard-import), ] Unused import(s) shutil from wildcard import of bettyfixer.backup +bettyfixer/betty_fixer.py:5: [W0614(unused-wildcard-import), ] Unused import(s) subprocess, errors_file_path and file_path from wildcard import of bettyfixer.errors_extractor +bettyfixer/betty_fixer.py:6: [W0614(unused-wildcard-import), ] Unused import(s) clean_up_line, fix_errors_from_file, should_be_void, fix_missing_blank_line_after_declaration, fix_should_be_foo_star_star_bar, fix_lines_in_file, generate_documentation, fix_space_prohibited_between_function_name_and_open_parenthesis, fix_space_prohibited_after_that_open_parenthesis, fix_space_prohibited_before_that_close_parenthesis, fix_space_required_before_the_open_parenthesis, fix_brace_on_the_next_line, brace_go_next_line, fix_brace_on_the_previous_line, fix_space_prohibited_before_semicolon, fix_should_be_foo_star_bar, fix_spaces_prohibited_around_that, fix_space_prohibited_after_that, fix_space_prohibited_before_that, fix_spaces_preferred_around_that, fix_space_required_around_that, fix_space_required_after_that, fix_space_required_before_the_open_brace and fix_space_required_after_the_close_brace from wildcard import of bettyfixer.extract_line +bettyfixer/betty_fixer.py:7: [W0614(unused-wildcard-import), ] Unused import(s) argparse, glob, print_Ctags_header_error, check_ctags, generate_tags, filter_tags, create_header, delete_files, check_header_file and Fore from wildcard import of bettyfixer.autoprototype + + + ## Report +====== +**210 statements analysed.** + +Statistics by type +------------------ + +|type |number |old number |difference |%documented |%badname | +|---------|-------|-----------|-----------|------------|---------| +|module |1 |NC |NC |0.00 |0.00 | +|class |0 |NC |NC |0 |0 | +|method |0 |NC |NC |0 |0 | +|function |22 |NC |NC |0.00 |4.55 | + + + +**332 lines have been analyzed** + +Raw metrics +----------- + +|type |number |% |previous |difference | +|----------|-------|------|---------|-----------| +|code |215 |64.76 |NC |NC | +|docstring |1 |0.30 |NC |NC | +|comment |50 |15.06 |NC |NC | +|empty |66 |19.88 |NC |NC | + + + +Duplication +----------- + +| |now |previous |difference | +|-------------------------|------|---------|-----------| +|nb duplicated lines |0 |NC |NC | +|percent duplicated lines |0.000 |NC |NC | + + + +Messages by category +-------------------- + +|type |number |previous |difference | +|-----------|-------|---------|-----------| +|convention |34 |NC |NC | +|refactor |4 |NC |NC | +|warning |47 |NC |NC | +|error |0 |NC |NC | + + + +Messages +-------- + +| message id | occurrences | +|---------------------------|-------------| +| missing-function-docstring| 22 | +| unspecified-encoding | 21 | +| redefined-outer-name | 17 | +| wildcard-import | 4 | +| unused-wildcard-import | 4 | +| line-too-long | 4 | +| trailing-whitespace | 3 | +| consider-using-with | 2 | +| unused-argument | 1 | +| too-many-nested-blocks | 1 | +| too-many-locals | 1 | +| superfluous-parens | 1 | +| singleton-comparison | 1 | +| missing-module-docstring | 1 | +| missing-final-newline | 1 | +| invalid-name | 1 | + + + + +----------------------------------- +Your code has been rated at 5.95/10 + From 06d2dfeb33ff8d12a2a3c2a8c0a71a516d19f8f8 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:19:54 +0300 Subject: [PATCH 47/91] Fix linting issues and add missing docstrings --- errors_logs/linting/betty_handler.txt | 84 +++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 errors_logs/linting/betty_handler.txt diff --git a/errors_logs/linting/betty_handler.txt b/errors_logs/linting/betty_handler.txt new file mode 100644 index 0000000..6611154 --- /dev/null +++ b/errors_logs/linting/betty_handler.txt @@ -0,0 +1,84 @@ +************* Module bettyfixer.betty_handler +bettyfixer/betty_handler.py:24: [C0301(line-too-long), ] Line too long (136/100) +bettyfixer/betty_handler.py:38: [C0301(line-too-long), ] Line too long (130/100) +bettyfixer/betty_handler.py:42: [C0301(line-too-long), ] Line too long (109/100) +bettyfixer/betty_handler.py:1: [C0114(missing-module-docstring), ] Missing module docstring +bettyfixer/betty_handler.py:4: [C0116(missing-function-docstring), other_handler] Missing function or method docstring +bettyfixer/betty_handler.py:9: [C0116(missing-function-docstring), create_tasks_directory] Missing function or method docstring +bettyfixer/betty_handler.py:14: [C0116(missing-function-docstring), copy_files_to_tasks] Missing function or method docstring +bettyfixer/betty_handler.py:20: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding +bettyfixer/betty_handler.py:27: [W1514(unspecified-encoding), copy_files_to_tasks] Using open without explicitly specifying an encoding +bettyfixer/betty_handler.py:30: [C0116(missing-function-docstring), modify_main_files] Missing function or method docstring +bettyfixer/betty_handler.py:34: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding +bettyfixer/betty_handler.py:41: [W1514(unspecified-encoding), modify_main_files] Using open without explicitly specifying an encoding + + +Report +------ +33 statements analysed. + +Statistics by type +------------------ + +|type |number |old number |difference |%documented |%badname | +|---------|-------|-----------|-----------|------------|---------| +|module |1 |NC |NC |0.00 |0.00 | +|class |0 |NC |NC |0 |0 | +|method |0 |NC |NC |0 |0 | +|function |4 |NC |NC |0.00 |0.00 | + +
+ + +**61 lines have been analyzed** + +**Raw metrics** +----------- + +|type |number |% |previous |difference | +|----------|-------|------|---------|-----------| +|code |35 |57.38 |NC |NC | +|docstring |0 |0.00 |NC |NC | +|comment |13 |21.31 |NC |NC | +|empty |13 |21.31 |NC |NC | + +
+ +Duplication +----------- + +| |now |previous |difference | +|-------------------------|------|---------|-----------| +|nb duplicated lines |0 |NC |NC | +|percent duplicated lines |0.000 |NC |NC | + + + +Messages by category +-------------------- + +|type |number |previous |difference | +|-----------|-------|---------|-----------| +|convention |8 |NC |NC | +|refactor |0 |NC |NC | +|warning |4 |NC |NC | +|error |0 |NC |NC | + + + +Messages +-------- + +|message id |occurrences | +|---------------------------|------------| +|unspecified-encoding |4 | +|missing-function-docstring |4 | +|line-too-long |3 | +|missing-module-docstring |1 | + + +
+ +----------------------------------- +Your code has been rated at 6.36/10 + From c274ac503297127c939dc9244f27edbe4398b4d4 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:20:00 +0300 Subject: [PATCH 48/91] Add linting errors extractor script --- errors_logs/linting/errors_exractor.txt | 86 +++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 errors_logs/linting/errors_exractor.txt diff --git a/errors_logs/linting/errors_exractor.txt b/errors_logs/linting/errors_exractor.txt new file mode 100644 index 0000000..9065d34 --- /dev/null +++ b/errors_logs/linting/errors_exractor.txt @@ -0,0 +1,86 @@ +************* Module bettyfixer.errors_extractor +bettyfixer/errors_extractor.py:1: [C0114(missing-module-docstring), ] Missing module docstring +bettyfixer/errors_extractor.py:4: [C0116(missing-function-docstring), exctract_errors] Missing function or method docstring +bettyfixer/errors_extractor.py:4: [W0621(redefined-outer-name), exctract_errors] Redefining name 'file_path' from outer scope (line 36) +bettyfixer/errors_extractor.py:13: [W0621(redefined-outer-name), exctract_errors] Redefining name 'errors_file_path' from outer scope (line 30) +bettyfixer/errors_extractor.py:13: [W1514(unspecified-encoding), exctract_errors] Using open without explicitly specifying an encoding +bettyfixer/errors_extractor.py:17: [W0107(unnecessary-pass), exctract_errors] Unnecessary pass statement +bettyfixer/errors_extractor.py:19: [W1514(unspecified-encoding), exctract_errors] Using open without explicitly specifying an encoding +bettyfixer/errors_extractor.py:30: [C0103(invalid-name), ] Constant name "errors_file_path" doesn't conform to UPPER_CASE naming style +bettyfixer/errors_extractor.py:33: [R1732(consider-using-with), ] Consider using 'with' for resource-allocating operations +bettyfixer/errors_extractor.py:33: [W1514(unspecified-encoding), ] Using open without explicitly specifying an encoding + + +## Report +------ + +**21 statements analysed.** + +Statistics by type +------------------ + +|type |number |old number |difference |%documented |%badname | +|---------|-------|-----------|-----------|------------|---------| +|module |1 |NC |NC |0.00 |0.00 | +|class |0 |NC |NC |0 |0 | +|method |0 |NC |NC |0 |0 | +|function |1 |NC |NC |0.00 |0.00 | + + + +**39 lines have been analyzed** + +Raw metrics +----------- + +|type |number |% |previous |difference | +|----------|-------|------|---------|-----------| +|code |23 |58.97 |NC |NC | +|docstring |0 |0.00 |NC |NC | +|comment |9 |23.08 |NC |NC | +|empty |7 |17.95 |NC |NC | + + + +Duplication +----------- + +| |now |previous |difference | +|-------------------------|------|---------|-----------| +|nb duplicated lines |0 |NC |NC | +|percent duplicated lines |0.000 |NC |NC | + + + +Messages by category +-------------------- + +|type |number |previous |difference | +|-----------|-------|---------|-----------| +|convention |3 |NC |NC | +|refactor |1 |NC |NC | +|warning |6 |NC |NC | +|error |0 |NC |NC | + + + +Messages +-------- + +|message id |occurrences | +|---------------------------|------------| +|unspecified-encoding |3 | +|redefined-outer-name |2 | +|unnecessary-pass |1 | +|missing-module-docstring |1 | +|missing-function-docstring |1 | +|invalid-name |1 | +|consider-using-with |1 | + +
+ + + +----------------------------------- +Your code has been rated at 5.24/10 + From 6bf2f9770b18d946de9cf09dd1d02564d4323fc6 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:20:04 +0300 Subject: [PATCH 49/91] Update user authentication logic*** --- errors_logs/linting/extract_line.txt | 247 +++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 errors_logs/linting/extract_line.txt diff --git a/errors_logs/linting/extract_line.txt b/errors_logs/linting/extract_line.txt new file mode 100644 index 0000000..14ef1c1 --- /dev/null +++ b/errors_logs/linting/extract_line.txt @@ -0,0 +1,247 @@ +************* Module bettyfixer.extract_line +bettyfixer/extract_line.py:31: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:78: [C0301(line-too-long), ] Line too long (122/100) +bettyfixer/extract_line.py:80: [C0301(line-too-long), ] Line too long (107/100) +bettyfixer/extract_line.py:82: [C0301(line-too-long), ] Line too long (109/100) +bettyfixer/extract_line.py:84: [C0301(line-too-long), ] Line too long (105/100) +bettyfixer/extract_line.py:148: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:187: [C0301(line-too-long), ] Line too long (106/100) +bettyfixer/extract_line.py:209: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:259: [C0301(line-too-long), ] Line too long (107/100) +bettyfixer/extract_line.py:262: [W0311(bad-indentation), ] Bad indentation. Found 16 spaces, expected 12 +bettyfixer/extract_line.py:267: [C0301(line-too-long), ] Line too long (102/100) +bettyfixer/extract_line.py:269: [C0301(line-too-long), ] Line too long (122/100) +bettyfixer/extract_line.py:276: [C0301(line-too-long), ] Line too long (180/100) +bettyfixer/extract_line.py:299: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:310: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:323: [C0301(line-too-long), ] Line too long (110/100) +bettyfixer/extract_line.py:327: [C0301(line-too-long), ] Line too long (119/100) +bettyfixer/extract_line.py:333: [C0301(line-too-long), ] Line too long (146/100) +bettyfixer/extract_line.py:341: [C0301(line-too-long), ] Line too long (104/100) +bettyfixer/extract_line.py:359: [C0301(line-too-long), ] Line too long (101/100) +bettyfixer/extract_line.py:361: [C0301(line-too-long), ] Line too long (113/100) +bettyfixer/extract_line.py:368: [C0301(line-too-long), ] Line too long (111/100) +bettyfixer/extract_line.py:382: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:388: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:452: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:504: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:507: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:517: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:519: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:570: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:580: [C0301(line-too-long), ] Line too long (117/100) +bettyfixer/extract_line.py:584: [C0301(line-too-long), ] Line too long (151/100) +bettyfixer/extract_line.py:589: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:649: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:671: [C0325(superfluous-parens), ] Unnecessary parens after 'not' keyword +bettyfixer/extract_line.py:700: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:743: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:784: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:807: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:822: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:834: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:857: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:872: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:884: [C0303(trailing-whitespace), ] Trailing whitespace +bettyfixer/extract_line.py:1: [C0114(missing-module-docstring), ] Missing module docstring +bettyfixer/extract_line.py:7: [C0116(missing-function-docstring), run_vi_script] Missing function or method docstring +bettyfixer/extract_line.py:11: [W1510(subprocess-run-check), run_vi_script] 'subprocess.run' used without explicitly defining the value for 'check'. +bettyfixer/extract_line.py:13: [C0116(missing-function-docstring), remove_extra_spaces] Missing function or method docstring +bettyfixer/extract_line.py:24: [C0116(missing-function-docstring), process_error_file] Missing function or method docstring +bettyfixer/extract_line.py:24: [W0621(redefined-outer-name), process_error_file] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:25: [W1514(unspecified-encoding), process_error_file] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:32: [C0116(missing-function-docstring), extract_and_print_variables] Missing function or method docstring +bettyfixer/extract_line.py:44: [C0116(missing-function-docstring), clean_up_line] Missing function or method docstring +bettyfixer/extract_line.py:53: [C0116(missing-function-docstring), fix_errors_from_file] Missing function or method docstring +bettyfixer/extract_line.py:53: [R0912(too-many-branches), fix_errors_from_file] Too many branches (18/12) +bettyfixer/extract_line.py:110: [C0116(missing-function-docstring), fix_should_be_void] Missing function or method docstring +bettyfixer/extract_line.py:110: [W0621(redefined-outer-name), fix_should_be_void] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:116: [W1514(unspecified-encoding), fix_should_be_void] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:132: [C0116(missing-function-docstring), should_be_void] Missing function or method docstring +bettyfixer/extract_line.py:132: [W0621(redefined-outer-name), should_be_void] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:139: [W1514(unspecified-encoding), should_be_void] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:146: [W1514(unspecified-encoding), should_be_void] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:159: [C0116(missing-function-docstring), clean_errors_file] Missing function or method docstring +bettyfixer/extract_line.py:159: [W0621(redefined-outer-name), clean_errors_file] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:163: [R1732(consider-using-with), clean_errors_file] Consider using 'with' for resource-allocating operations +bettyfixer/extract_line.py:163: [W1514(unspecified-encoding), clean_errors_file] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:169: [C0116(missing-function-docstring), fix_missing_blank_line_after_declarations] Missing function or method docstring +bettyfixer/extract_line.py:169: [W0621(redefined-outer-name), fix_missing_blank_line_after_declarations] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:175: [W1514(unspecified-encoding), fix_missing_blank_line_after_declarations] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:190: [C0116(missing-function-docstring), fix_missing_blank_line_after_declaration] Missing function or method docstring +bettyfixer/extract_line.py:190: [W0621(redefined-outer-name), fix_missing_blank_line_after_declaration] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:195: [W1514(unspecified-encoding), fix_missing_blank_line_after_declaration] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:207: [W1514(unspecified-encoding), fix_missing_blank_line_after_declaration] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:215: [C0116(missing-function-docstring), fix_should_be_foo_star_star_bar] Missing function or method docstring +bettyfixer/extract_line.py:220: [W1514(unspecified-encoding), fix_should_be_foo_star_star_bar] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:227: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:229: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:231: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:233: [W1309(f-string-without-interpolation), fix_should_be_foo_star_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:243: [W1514(unspecified-encoding), fix_should_be_foo_star_star_bar] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:246: [C0116(missing-function-docstring), remove_unused_attribute] Missing function or method docstring +bettyfixer/extract_line.py:283: [W0718(broad-exception-caught), remove_unused_attribute] Catching too general exception Exception +bettyfixer/extract_line.py:248: [W1514(unspecified-encoding), remove_unused_attribute] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:279: [W1514(unspecified-encoding), remove_unused_attribute] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:264: [W0612(unused-variable), remove_unused_attribute] Unused variable 'original_declaration' +bettyfixer/extract_line.py:286: [C0116(missing-function-docstring), fix_lines_in_file] Missing function or method docstring +bettyfixer/extract_line.py:308: [W0718(broad-exception-caught), fix_lines_in_file] Catching too general exception Exception +bettyfixer/extract_line.py:288: [W1514(unspecified-encoding), fix_lines_in_file] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:306: [W1514(unspecified-encoding), fix_lines_in_file] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:287: [R1702(too-many-nested-blocks), fix_lines_in_file] Too many nested blocks (6/5) +bettyfixer/extract_line.py:311: [C0116(missing-function-docstring), generate_documentation] Missing function or method docstring +bettyfixer/extract_line.py:352: [C0116(missing-function-docstring), extract_functions_with_no_description] Missing function or method docstring +bettyfixer/extract_line.py:355: [W1514(unspecified-encoding), extract_functions_with_no_description] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:368: [C0116(missing-function-docstring), fix_space_prohibited_between_function_name_and_open_parenthesis] Missing function or method docstring +bettyfixer/extract_line.py:374: [W1514(unspecified-encoding), fix_space_prohibited_between_function_name_and_open_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:387: [W1514(unspecified-encoding), fix_space_prohibited_between_function_name_and_open_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:389: [C0116(missing-function-docstring), fix_space_prohibited_after_that_open_parenthesis] Missing function or method docstring +bettyfixer/extract_line.py:395: [W1514(unspecified-encoding), fix_space_prohibited_after_that_open_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:408: [W1514(unspecified-encoding), fix_space_prohibited_after_that_open_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:410: [C0116(missing-function-docstring), fix_space_prohibited_before_that_close_parenthesis] Missing function or method docstring +bettyfixer/extract_line.py:416: [W1514(unspecified-encoding), fix_space_prohibited_before_that_close_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:429: [W1514(unspecified-encoding), fix_space_prohibited_before_that_close_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:431: [C0116(missing-function-docstring), fix_space_required_before_the_open_parenthesis] Missing function or method docstring +bettyfixer/extract_line.py:437: [W1514(unspecified-encoding), fix_space_required_before_the_open_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:450: [W1514(unspecified-encoding), fix_space_required_before_the_open_parenthesis] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:453: [C0116(missing-function-docstring), fix_brace_should_be_on_the_next_line] Missing function or method docstring +bettyfixer/extract_line.py:453: [W0621(redefined-outer-name), fix_brace_should_be_on_the_next_line] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:459: [W1514(unspecified-encoding), fix_brace_should_be_on_the_next_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:492: [C0116(missing-function-docstring), fix_brace_on_the_next_line] Missing function or method docstring +bettyfixer/extract_line.py:492: [W0621(redefined-outer-name), fix_brace_on_the_next_line] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:497: [W1514(unspecified-encoding), fix_brace_on_the_next_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:509: [W1514(unspecified-encoding), fix_brace_on_the_next_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:520: [C0116(missing-function-docstring), brace_go_next_line] Missing function or method docstring +bettyfixer/extract_line.py:524: [W1514(unspecified-encoding), brace_go_next_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:539: [W1514(unspecified-encoding), brace_go_next_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:542: [C0116(missing-function-docstring), fix_brace_should_be_on_the_previous_line] Missing function or method docstring +bettyfixer/extract_line.py:542: [W0621(redefined-outer-name), fix_brace_should_be_on_the_previous_line] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:548: [W1514(unspecified-encoding), fix_brace_should_be_on_the_previous_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:563: [C0116(missing-function-docstring), fix_brace_on_the_previous_line] Missing function or method docstring +bettyfixer/extract_line.py:563: [W0621(redefined-outer-name), fix_brace_on_the_previous_line] Redefining name 'errors_file_path' from outer scope (line 968) +bettyfixer/extract_line.py:568: [W1514(unspecified-encoding), fix_brace_on_the_previous_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:587: [W1514(unspecified-encoding), fix_brace_on_the_previous_line] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:596: [C0116(missing-function-docstring), fix_space_prohibited_before_semicolon] Missing function or method docstring +bettyfixer/extract_line.py:599: [W1514(unspecified-encoding), fix_space_prohibited_before_semicolon] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:613: [W1514(unspecified-encoding), fix_space_prohibited_before_semicolon] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:615: [C0116(missing-function-docstring), fix_should_be_foo_star_bar] Missing function or method docstring +bettyfixer/extract_line.py:620: [W1514(unspecified-encoding), fix_should_be_foo_star_bar] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:627: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:629: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:631: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:633: [W1309(f-string-without-interpolation), fix_should_be_foo_star_bar] Using an f-string that does not have any interpolated variables +bettyfixer/extract_line.py:643: [W1514(unspecified-encoding), fix_should_be_foo_star_bar] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:645: [C0116(missing-function-docstring), fix_spaces_prohibited_around_that] Missing function or method docstring +bettyfixer/extract_line.py:667: [W1514(unspecified-encoding), fix_spaces_prohibited_around_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:693: [W1514(unspecified-encoding), fix_spaces_prohibited_around_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:696: [C0116(missing-function-docstring), fix_space_prohibited_after_that] Missing function or method docstring +bettyfixer/extract_line.py:718: [W1514(unspecified-encoding), fix_space_prohibited_after_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:737: [W1514(unspecified-encoding), fix_space_prohibited_after_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:739: [C0116(missing-function-docstring), fix_space_prohibited_before_that] Missing function or method docstring +bettyfixer/extract_line.py:761: [W1514(unspecified-encoding), fix_space_prohibited_before_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:768: [R1714(consider-using-in), fix_space_prohibited_before_that] Consider merging these comparisons with 'in' by using 'context in ('WxV', 'WxO', 'WxE', 'WxW')'. Use a set instead if elements are hashable. +bettyfixer/extract_line.py:778: [W1514(unspecified-encoding), fix_space_prohibited_before_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:780: [C0116(missing-function-docstring), fix_spaces_preferred_around_that] Missing function or method docstring +bettyfixer/extract_line.py:802: [W1514(unspecified-encoding), fix_spaces_preferred_around_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:828: [W1514(unspecified-encoding), fix_spaces_preferred_around_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:830: [C0116(missing-function-docstring), fix_space_required_around_that] Missing function or method docstring +bettyfixer/extract_line.py:852: [W1514(unspecified-encoding), fix_space_required_around_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:878: [W1514(unspecified-encoding), fix_space_required_around_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:880: [C0116(missing-function-docstring), fix_space_required_after_that] Missing function or method docstring +bettyfixer/extract_line.py:902: [W1514(unspecified-encoding), fix_space_required_after_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:909: [R1714(consider-using-in), fix_space_required_after_that] Consider merging these comparisons with 'in' by using 'context in ('WxV', 'VxV')'. Use a set instead if elements are hashable. +bettyfixer/extract_line.py:919: [W1514(unspecified-encoding), fix_space_required_after_that] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:921: [C0116(missing-function-docstring), fix_space_required_before_the_open_brace] Missing function or method docstring +bettyfixer/extract_line.py:927: [W1514(unspecified-encoding), fix_space_required_before_the_open_brace] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:940: [W1514(unspecified-encoding), fix_space_required_before_the_open_brace] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:942: [C0116(missing-function-docstring), fix_space_required_after_the_close_brace] Missing function or method docstring +bettyfixer/extract_line.py:948: [W1514(unspecified-encoding), fix_space_required_after_the_close_brace] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:961: [W1514(unspecified-encoding), fix_space_required_after_the_close_brace] Using open without explicitly specifying an encoding +bettyfixer/extract_line.py:968: [C0103(invalid-name), ] Constant name "errors_file_path" doesn't conform to UPPER_CASE naming style +bettyfixer/extract_line.py:4: [C0411(wrong-import-order), ] standard import "import os" should be placed before "from bettyfixer.errors_extractor import exctract_errors" +bettyfixer/extract_line.py:5: [C0411(wrong-import-order), ] standard import "import subprocess" should be placed before "from bettyfixer.errors_extractor import exctract_errors" + + + ## Report + +**522 statements analysed.** + +Statistics by type +------------------ + +| type | number | old number | difference | %documented | %badname | +|----------|--------|------------|------------|-------------|----------| +| module | 1 | 1 | = | 0.00 | 0.00 | +| class | 0 | NC | NC | 0 | 0 | +| method | 0 | NC | NC | 0 | 0 | +| function | 35 | 35 | = | 0.00 | 0.00 | + + +**971 lines have been analyzed** + +Raw metrics +----------- + +|type |number |% |previous |difference | +|----------|-------|------|---------|-----------| +|code |536 |55.20 |NC |NC | +|docstring |16 |1.65 |NC |NC | +|comment |206 |21.22 |NC |NC | +|empty |213 |21.94 |NC |NC | + + + +Duplication +----------- + +| |now |previous |difference | +|-------------------------|------|---------|-----------| +|nb duplicated lines |0 |0 |0 | +|percent duplicated lines |0.000 |0.000 |= | + + + +Messages by category +-------------------- + +|type |number |previous |difference | +|-----------|-------|---------|-----------| +|convention |82 |82 |82 | +|refactor |5 |5 |5 | +|warning |74 |74 |74 | +|error |0 |0 |0 | + + + +Messages +-------- + + +| message id | occurrences | +|------------------------------- | ------------| +| unspecified-encoding | 51 | +| missing-function-docstring | 35 | +| trailing-whitespace | 24 | +| line-too-long | 18 | +| redefined-outer-name | 10 | +| f-string-without-interpolation | 8 | +| wrong-import-order | 2 | +| consider-using-in | 2 | +| broad-exception-caught | 2 | +| unused-variable | 1 | +| too-many-nested-blocks | 1 | +| too-many-branches | 1 | +| superfluous-parens | 1 | +| subprocess-run-check | 1 | +| missing-module-docstring | 1 | +| invalid-name | 1 | +| consider-using-with | 1 | +| bad-indentation | 1 | + + + + + +------------------------------------------------------------------ +Your code has been rated at 6.92/10 (previous run: 6.92/10, +0.00) + From ecf2f8b1d2e52bf5572db2be3d5a1a9d13f5ec46 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 17:47:11 +0300 Subject: [PATCH 50/91] Change file suffix to .txt in linter.sh --- linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 linter.sh diff --git a/linter.sh b/linter.sh old mode 100644 new mode 100755 index e1d3ecb..f542ab5 --- a/linter.sh +++ b/linter.sh @@ -31,9 +31,9 @@ fi for file in "$@" do # Change the file suffix to .txt + filename=$(basename "$file") output_file="${file%.py}.txt" - echo -e "\n\nName: $NAME\n" >> "${PATHLOG}/${output_file}" echo -e "Date: $CURRENT_DATE\n" >> "${PATHLOG}/${output_file}" pylint "$file" From 45fa4c595c214443aec16060fb0e9c2064074c00 Mon Sep 17 00:00:00 2001 From: jonaahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 17:48:31 +0300 Subject: [PATCH 51/91] Fix file suffix in linter.sh --- linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linter.sh b/linter.sh index f542ab5..f39d386 100755 --- a/linter.sh +++ b/linter.sh @@ -32,7 +32,7 @@ for file in "$@" do # Change the file suffix to .txt filename=$(basename "$file") - output_file="${file%.py}.txt" + output_file="${filename%.py}.txt" echo -e "\n\nName: $NAME\n" >> "${PATHLOG}/${output_file}" echo -e "Date: $CURRENT_DATE\n" >> "${PATHLOG}/${output_file}" From bbcdb9292396fdca8eb2b3b37ce355c8915750ae Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sun, 18 Feb 2024 18:17:20 +0300 Subject: [PATCH 52/91] Fix path to error logs in linter.sh --- linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linter.sh b/linter.sh index f39d386..b5968c6 100755 --- a/linter.sh +++ b/linter.sh @@ -7,7 +7,7 @@ CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") NAME=$(git config --get user.name) # path from the root of project to the directory where the log files will be saved -PATHLOG=$(git rev-parse --show-toplevel)/error_logs/linting +PATHLOG=$(git rev-parse --show-toplevel)/errors_logs/linting # Check if pylint is installed if ! command -v pylint &> /dev/null then From 65be892f1846a2a65c0cdd423d450f39c99c960b Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:55:08 +0300 Subject: [PATCH 53/91] Refactor autoprototype.py and test_autoprototype.py --- tests/test_autoprototype.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index 34d45f0..ee93e2b 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -13,7 +13,7 @@ print_ctags_header_error, check_ctags, create_header, delete_files, check_header_file, - autoproto, print_ctags_header_error + autoproto ) @@ -232,12 +232,11 @@ def test_check_header_file(self): def test_autoproto(self, mocker): """ Test the autoproto function from autoprototype.py""" mock_check_header_file, mock_filter_tags, \ - mock_generate_tags, mock_create_header, mock_ctag_print = mocker.patch( + mock_generate_tags, mock_create_header = mocker.patch( "bettyfixer.autoprototype.check_header_file"), mocker.patch( "bettyfixer.autoprototype.filter_tags"), mocker.patch( "bettyfixer.autoprototype.generate_tags"), mocker.patch( - "bettyfixer.autoprototype.create_header"), mocker.patch( - "bettyfixer.autoprototype.print_ctags_header_error") + "bettyfixer.autoprototype.create_header") mock_check_header_file.return_value = (True, None) mock_generate_tags.return_value = True @@ -251,6 +250,3 @@ def test_autoproto(self, mocker): mock_create_header.assert_called_once_with( "test.h", mock_filter_tags.return_value) mocker.stopall() - # mock_check_header_file.return_value = (False, None) - # autoproto(".", "test.h") - # mock_ctag_print.assert_called_once() From b35cee22b1b3c6bc1ec2b05ee24c0b33d4e2aaf2 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:55:13 +0300 Subject: [PATCH 54/91] Add test cases for read_file and write_file functions --- tests/test_betty_fixer.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index ba3909c..a6c1ad6 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -2,10 +2,42 @@ Test the betty_fixer module. """ import os -import subprocess import pytest -# from bettyfixer.betty_fixer import * as betty_fixer +from bettyfixer.betty_fixer import ( + read_file, write_file, add_line_without_newline, + remove_consecutive_blank_lines, add_parentheses_around_return, + fix_comments, remove_trailing_whitespaces, process_errors, + fix_betty_warnings, remove_blank_lines_inside_comments, + fix_betty_style, more_than_5_functions_in_the_file, + find_available_file_name, copy_remaining_lines, + betty_handler, other_handlers, create_tasks_directory, + copy_files_to_tasks, modify_main_files, record_processed_file, + is_file_processed +) class TestBettyFixer: - pass + """ + Test the betty_fixer module. + """ + @pytest.fixture(autouse=True) + def setup_teardown(self): + """Set up the test """ + + with open("test.c", "w", encoding="utf-8") as f: + f.write( + 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') + yield + + os.remove("test.c") + + def test_read_file(self): + """Test read_file function.""" + assert read_file( + "test.c") == 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}' + + def test_write_file(self): + """Test write_file function.""" + write_file("./hello.txt", "Hello World") + assert read_file("./hello.txt") == "Hello World" + os.remove("./hello.txt") From 00026863105e15efa414cf8d6480874009d664a8 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:03:25 +0300 Subject: [PATCH 55/91] Add tests for add_line_without_newline function --- tests/test_betty_fixer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index a6c1ad6..e5fbccc 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -41,3 +41,14 @@ def test_write_file(self): write_file("./hello.txt", "Hello World") assert read_file("./hello.txt") == "Hello World" os.remove("./hello.txt") + + def test_add_line_without_newline(self): + """Test add_line_without_newline function.""" + add_line_without_newline("test.c", "\n") + assert read_file( + "test.c") == 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}\n' + + def test_add_line_without_newline_fail(self): + """Test add_line_without_newline function.""" + with pytest.raises(FileNotFoundError): + add_line_without_newline("notFound", "\n") From d39e0a88d0ae29eb9c555cb4c602b1ec64b7644c Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:57:53 +0300 Subject: [PATCH 56/91] Add tests for remove_consecutive_blank_lines and add_parentheses_around_return functions --- tests/test_betty_fixer.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index e5fbccc..d831947 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -3,6 +3,7 @@ """ import os import pytest +import re from bettyfixer.betty_fixer import ( read_file, write_file, add_line_without_newline, remove_consecutive_blank_lines, add_parentheses_around_return, @@ -52,3 +53,26 @@ def test_add_line_without_newline_fail(self): """Test add_line_without_newline function.""" with pytest.raises(FileNotFoundError): add_line_without_newline("notFound", "\n") + + def test_remove_consecutive_blank_lines(self): + """Test remove_consecutive_blank_lines function.""" + list_str_blank = ["Hello\n\n\nWorld", "Hello\n\n\nWorld\n\n\n", + "Hello\n\n\nWorld\n\n\n\n\n", + "\n\n\nHello\n\n\nWorld\n\n\n\n\n\n"] + + assert all(remove_consecutive_blank_lines(string) != re.search( + "\n{3,}", string) for string in list_str_blank) + + def test_add_parentheses_around_return(self): + """Test add_parentheses_around_return function.""" + + return_ = { + "return 0;": r"return\s*\((\d+)\);", + "return (0);": r"return\s*\((\d+)\);", + "return ;": r"return\s*;", + "return value;": r"return\s*\(value\);", + "return (value);": r"return\s*\(value\);" + } + + for key, value in return_.items(): + assert re.search(value, add_parentheses_around_return(key)) From b5fd845530ee4ccf3f9dcfa02db996fd4dce0f59 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:56:37 +0300 Subject: [PATCH 57/91] test fix comment regex --- tests/test_betty_fixer.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index d831947..06f4731 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -75,4 +75,17 @@ def test_add_parentheses_around_return(self): } for key, value in return_.items(): - assert re.search(value, add_parentheses_around_return(key)) + assert re.search( + value, add_parentheses_around_return(key)) is not None + + def test_fix_comments(self): + """Test fix_comments function.""" + comments = { + "something// comment": r"something\s*", + "something // comment": r"something\s*", + "something // comment\n": r"something\s*", + "// comment": r"\s*", + "/* comment */": r"\s*\/\* comment \*/\s*", + } + for key, value in comments.items(): + assert re.search(value, fix_comments(key)) is not None From e699497a476cde6aa6385210be0fa7f6f88da226 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:48:53 +0300 Subject: [PATCH 58/91] Fix test assertions in test_betty_fixer.py --- tests/test_betty_fixer.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 06f4731..f3ce7d4 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -76,7 +76,7 @@ def test_add_parentheses_around_return(self): for key, value in return_.items(): assert re.search( - value, add_parentheses_around_return(key)) is not None + value, add_parentheses_around_return(key)) def test_fix_comments(self): """Test fix_comments function.""" @@ -88,4 +88,11 @@ def test_fix_comments(self): "/* comment */": r"\s*\/\* comment \*/\s*", } for key, value in comments.items(): - assert re.search(value, fix_comments(key)) is not None + assert re.search(value, fix_comments(key)) + + def test_remove_trailing_whitespaces(self): + """Test remove_trailing_whitespaces function.""" + lines = ["Hello World ", "Hello World", + "Hello World\t", "Hello World\t\t"] # ❗ "Hello World\n" and "Hello World\n " is failing + assert all(remove_trailing_whitespaces(line) + == re.search(r"Hello World\S*", line).group() for line in lines) From 57d759c3b4022b22723c7b5e7352eaf0ba7b2a46 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:49:19 +0300 Subject: [PATCH 59/91] Fix trailing whitespace issue in test_betty_fixer.py --- tests/test_betty_fixer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index f3ce7d4..b172f8f 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -93,6 +93,7 @@ def test_fix_comments(self): def test_remove_trailing_whitespaces(self): """Test remove_trailing_whitespaces function.""" lines = ["Hello World ", "Hello World", - "Hello World\t", "Hello World\t\t"] # ❗ "Hello World\n" and "Hello World\n " is failing + "Hello World\t", "Hello World\t\t"] + # ❗ "Hello World\n" and "Hello World\n " is failing assert all(remove_trailing_whitespaces(line) == re.search(r"Hello World\S*", line).group() for line in lines) From 4bee77ff56bd5dfb73c130ff0b458d6ac329ba6e Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:29:41 +0300 Subject: [PATCH 60/91] Refactor test_betty_fixer.py --- tests/test_betty_fixer.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index b172f8f..436fc63 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -2,12 +2,12 @@ Test the betty_fixer module. """ import os -import pytest import re +import pytest from bettyfixer.betty_fixer import ( read_file, write_file, add_line_without_newline, remove_consecutive_blank_lines, add_parentheses_around_return, - fix_comments, remove_trailing_whitespaces, process_errors, + fix_comments, remove_trailing_whitespaces, fix_betty_warnings, remove_blank_lines_inside_comments, fix_betty_style, more_than_5_functions_in_the_file, find_available_file_name, copy_remaining_lines, @@ -31,6 +31,8 @@ def setup_teardown(self): yield os.remove("test.c") + if os.path.exists("errors.txt"): + os.remove("errors.txt") def test_read_file(self): """Test read_file function.""" @@ -97,3 +99,35 @@ def test_remove_trailing_whitespaces(self): # ❗ "Hello World\n" and "Hello World\n " is failing assert all(remove_trailing_whitespaces(line) == re.search(r"Hello World\S*", line).group() for line in lines) + + # @pytest.mark.skip(reason="Needs to be refactored with Dependency Injection in mind") + def test_fix_betty_warnings(self, mocker): + """Test fix_betty_warnings function.""" + mock_remove_consecutive_blank_lines = mocker.patch( + "bettyfixer.betty_fixer.remove_consecutive_blank_lines", return_value="some_content") + mock_fix_comments = mocker.patch( + "bettyfixer.betty_fixer.fix_comments", return_value="some_content") + mock_remove_trailing_whitespaces = mocker.patch( + "bettyfixer.betty_fixer.remove_trailing_whitespaces") + fix_betty_warnings("some_content", "test.c") + mock_remove_consecutive_blank_lines.assert_called_once_with( + "some_content") + mock_fix_comments.assert_called_once_with("some_content") + mock_remove_trailing_whitespaces.assert_called_once_with( + "some_content") + + +def test_remove_blank_lines_inside_comments(mocker): + """Test remove_blank_lines_inside_comments function.""" + + mock_clean_errors_file = mocker.patch( + "bettyfixer.betty_fixer.clean_errors_file") + mock_open = mocker.patch( + "builtins.open", mocker.mock_open(read_data="/**\n\n*/")) + + remove_blank_lines_inside_comments("some_file") + mock_clean_errors_file.assert_called_once_with('errors.txt') + assert mock_open.call_count == 2 + mock_open.assert_any_call("some_file", 'r', encoding='utf-8') + mock_open.assert_any_call("some_file", 'w', encoding='utf-8') + mock_open().writelines.assert_called_once_with(["/**\n", "*/"]) From 03ac3d6dfaf400daa71a6b93f471a631efb82443 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:22:10 +0300 Subject: [PATCH 61/91] Refactor remove_blank_lines_inside_comments function --- tests/test_betty_fixer.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 436fc63..412484c 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -116,18 +116,17 @@ def test_fix_betty_warnings(self, mocker): mock_remove_trailing_whitespaces.assert_called_once_with( "some_content") - -def test_remove_blank_lines_inside_comments(mocker): - """Test remove_blank_lines_inside_comments function.""" - - mock_clean_errors_file = mocker.patch( - "bettyfixer.betty_fixer.clean_errors_file") - mock_open = mocker.patch( - "builtins.open", mocker.mock_open(read_data="/**\n\n*/")) - - remove_blank_lines_inside_comments("some_file") - mock_clean_errors_file.assert_called_once_with('errors.txt') - assert mock_open.call_count == 2 - mock_open.assert_any_call("some_file", 'r', encoding='utf-8') - mock_open.assert_any_call("some_file", 'w', encoding='utf-8') - mock_open().writelines.assert_called_once_with(["/**\n", "*/"]) + def test_remove_blank_lines_inside_comments(self, mocker): + """Test remove_blank_lines_inside_comments function.""" + + mock_clean_errors_file = mocker.patch( + "bettyfixer.betty_fixer.clean_errors_file") + mock_open = mocker.patch( + "builtins.open", mocker.mock_open(read_data="/**\n\n*/")) + + remove_blank_lines_inside_comments("some_file") + mock_clean_errors_file.assert_called_once_with('errors.txt') + assert mock_open.call_count == 2 + mock_open.assert_any_call("some_file", 'r', encoding='utf-8') + mock_open.assert_any_call("some_file", 'w', encoding='utf-8') + mock_open().writelines.assert_called_once_with(["/**\n", "*/"]) From dfab6c166e730c7ebc8c89af68076b8dd9f72d70 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:26:38 +0300 Subject: [PATCH 62/91] Refactor test_betty_fixer.py and add missing comments --- tests/test_betty_fixer.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 412484c..39fd149 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -100,7 +100,7 @@ def test_remove_trailing_whitespaces(self): assert all(remove_trailing_whitespaces(line) == re.search(r"Hello World\S*", line).group() for line in lines) - # @pytest.mark.skip(reason="Needs to be refactored with Dependency Injection in mind") + # ❗ @pytest.mark.skip(reason="Needs to be refactored with Dependency Injection in mind") def test_fix_betty_warnings(self, mocker): """Test fix_betty_warnings function.""" mock_remove_consecutive_blank_lines = mocker.patch( @@ -130,3 +130,38 @@ def test_remove_blank_lines_inside_comments(self, mocker): mock_open.assert_any_call("some_file", 'r', encoding='utf-8') mock_open.assert_any_call("some_file", 'w', encoding='utf-8') mock_open().writelines.assert_called_once_with(["/**\n", "*/"]) + + # ❗ @pytest.mark.skip(reason="in serious need of refactoring. Decoupling and Dependency Injection") + def test_fix_betty_style(self, mocker): + """Test fix_betty_style function.""" + file_paths = ["file1", "file2", "file3"] + mock_create_backup = mocker.patch( + "bettyfixer.betty_fixer.create_backup", return_value="file content") + mock_run_vi_script = mocker.patch( + "bettyfixer.betty_fixer.run_vi_script", return_value="file content") + mock_read_file = mocker.patch( + "bettyfixer.betty_fixer.read_file", return_value="file content") + mock_write_file = mocker.patch( + "bettyfixer.betty_fixer.write_file", return_value="file content") + mock_add_line_without_newline = mocker.patch( + "bettyfixer.betty_fixer.add_line_without_newline", return_value="file content") + mock_process_errors = mocker.patch( + "bettyfixer.betty_fixer.process_errors", return_value="file content") + mock_open = mocker.patch( + "builtins.open", mocker.mock_open(read_data="file content")) + + fix_betty_style(file_paths) + + mock_process_errors.call_count = len(file_paths) * 2 + # Check that the mocked functions were called with the correct arguments + for file_path in file_paths: + mock_create_backup.assert_any_call(file_path) + mock_run_vi_script.assert_any_call(file_path) + mock_read_file.assert_any_call(file_path) + mock_write_file.assert_any_call(file_path, "file content") + mock_add_line_without_newline.assert_any_call(file_path, "\n") + mock_process_errors.assert_any_call(file_path) + + mock_open.assert_any_call(file_path, 'r', encoding='utf-8') + mock_open.assert_any_call(file_path, 'w', encoding='utf-8') + mock_open().writelines.assert_called_with(["file content"]) From 87eb40d2ec27ea87a0538f71168334d7dc03768f Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:06:06 +0300 Subject: [PATCH 63/91] Fix betty style test and remove unnecessary spaces --- tests/test_betty_fixer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 39fd149..3bd9b23 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -131,7 +131,7 @@ def test_remove_blank_lines_inside_comments(self, mocker): mock_open.assert_any_call("some_file", 'w', encoding='utf-8') mock_open().writelines.assert_called_once_with(["/**\n", "*/"]) - # ❗ @pytest.mark.skip(reason="in serious need of refactoring. Decoupling and Dependency Injection") + # ❗@pytest.mark.skip(reason="in serious need of refactoring.Decoupling and Dependency Injection") def test_fix_betty_style(self, mocker): """Test fix_betty_style function.""" file_paths = ["file1", "file2", "file3"] From 881acba8281a11070bffd7fa87c348b0f9ea1ef2 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:01:08 +0300 Subject: [PATCH 64/91] Refactor tests and add find_available_file_name tests --- tests/test_betty_fixer.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 3bd9b23..ee0a401 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -165,3 +165,31 @@ def test_fix_betty_style(self, mocker): mock_open.assert_any_call(file_path, 'r', encoding='utf-8') mock_open.assert_any_call(file_path, 'w', encoding='utf-8') mock_open().writelines.assert_called_with(["file content"]) + + # ❗ + @pytest.mark.skip(reason="Needs refactoring [DI, pure functions, decoupling]") + def test_more_than_5_functions_in_the_file(self, mocker): + """Test more_than_5_functions_in_the_file function.""" + pass # pylint: disable=unnecessary-pass + + def test_find_available_file_name_no_existing_files(self, mocker): + """Test find_available_file_name when there are + no existing files with the same base name.""" + mocker.patch('os.path.exists', return_value=False) + assert find_available_file_name("test.txt") == "test1.txt" + + def test_find_available_file_name_with_existing_files(self, mocker): + """Test find_available_file_name when + there are existing files with the same base name.""" + exists_side_effect = [ + True, True, False] # Simulate that "test1.txt" and "test2.txt" exist + mocker.patch('os.path.exists', side_effect=exists_side_effect) + assert find_available_file_name("test.txt") == "test3.txt" + + def test_find_available_file_name_with_many_existing_files(self, mocker): + """Test find_available_file_name when there are many existing + files with the same base name.""" + exists_side_effect = [ + True] * 100 + [False] # Simulate that "test1.txt" to "test100.txt" exist + mocker.patch('os.path.exists', side_effect=exists_side_effect) + assert find_available_file_name("test.txt") == "test101.txt" From 5f09258a6d33e4bb0be4369a32a12c4e743ccf92 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:30:21 +0300 Subject: [PATCH 65/91] Add test for copy_remaining_lines function --- tests/test_betty_fixer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index ee0a401..fa97f59 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -193,3 +193,13 @@ def test_find_available_file_name_with_many_existing_files(self, mocker): True] * 100 + [False] # Simulate that "test1.txt" to "test100.txt" exist mocker.patch('os.path.exists', side_effect=exists_side_effect) assert find_available_file_name("test.txt") == "test101.txt" + + def test_copy_remaining_lines(self, mocker): + """Test copy_remaining_lines function.""" + mock_open = mocker.patch("builtins.open", mocker.mock_open()) + lines = ["line1\n", "line2\n", "line3\n"] + start_line = 1 + new_file_path = "new_file.txt" + copy_remaining_lines(lines, start_line, new_file_path) + mock_open.assert_called_once_with(new_file_path, 'w', encoding='utf-8') + mock_open().write.assert_called_once_with("".join(lines[start_line:])) From 4cc9f78509eb477486064b1bd80f4c995dd80c07 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:30:50 +0300 Subject: [PATCH 66/91] Refactor code for Dependency Injection and decoupling --- bettyfixer/betty_fixer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bettyfixer/betty_fixer.py b/bettyfixer/betty_fixer.py index ac3bcca..0a14c3e 100644 --- a/bettyfixer/betty_fixer.py +++ b/bettyfixer/betty_fixer.py @@ -141,6 +141,7 @@ def process_errors(file_path): process_error_file(file_path) +# ❗ Needs to be refactored with Dependency Injection in mind def fix_betty_warnings(content, file_path): """ Fix Betty warnings in the specified content. @@ -190,6 +191,7 @@ def remove_blank_lines_inside_comments(file_path): return +# ❗ in serious need of refactoring. Decoupling and Dependency Injection def fix_betty_style(file_paths): """ Fix Betty style for the specified file paths. From 2aaf09ed40ba7cce5ea38e01d22766bf1990b31f Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:37:16 +0300 Subject: [PATCH 67/91] Add tests for betty_handler function --- tests/test_betty_fixer.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index fa97f59..949b805 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -203,3 +203,27 @@ def test_copy_remaining_lines(self, mocker): copy_remaining_lines(lines, start_line, new_file_path) mock_open.assert_called_once_with(new_file_path, 'w', encoding='utf-8') mock_open().write.assert_called_once_with("".join(lines[start_line:])) + + def test_betty_handler_no_errors(self, mocker): + """Test betty_handler function when there are no Betty errors.""" + mock_open = mocker.patch( + "builtins.open", mocker.mock_open(read_data="")) + mock_other_handlers = mocker.patch( + "bettyfixer.betty_fixer.other_handlers") + betty_handler("errors.txt") + mock_open.assert_called_once_with("errors.txt", 'r', encoding='utf-8') + mock_other_handlers.assert_not_called() + + def test_betty_handler_with_errors(self, mocker): + """Test betty_handler function when there are Betty errors.""" + error_lines = "More than 40 lines in a function\nline over 80 characters\n" + mock_open = mocker.patch( + "builtins.open", mocker.mock_open(read_data=error_lines)) + mock_other_handlers = mocker.patch( + "bettyfixer.betty_fixer.other_handlers") + mock_extract_and_print_variables = mocker.patch( + "bettyfixer.betty_fixer.extract_and_print_variables", return_value=("file_path",)) + betty_handler("errors.txt") + mock_open.assert_called_once_with("errors.txt", 'r', encoding='utf-8') + mock_extract_and_print_variables.assert_called() + mock_other_handlers.assert_called_with("file_path") From d29d6a1a6586a1b273feb7e6da611f72e12749fe Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:37:47 +0300 Subject: [PATCH 68/91] Add test_other_handlers function to test_betty_fixer.py --- tests/test_betty_fixer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 949b805..30d0a8b 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -227,3 +227,25 @@ def test_betty_handler_with_errors(self, mocker): mock_open.assert_called_once_with("errors.txt", 'r', encoding='utf-8') mock_extract_and_print_variables.assert_called() mock_other_handlers.assert_called_with("file_path") + + def test_other_handlers(self, mocker): + """Test other_handlers function.""" + mock_create_tasks_directory = mocker.patch( + "bettyfixer.betty_fixer.create_tasks_directory") + mock_copy_files_to_tasks = mocker.patch( + "bettyfixer.betty_fixer.copy_files_to_tasks") + mock_modify_main_files = mocker.patch( + "bettyfixer.betty_fixer.modify_main_files") + mock_clean_errors_file = mocker.patch( + "bettyfixer.betty_fixer.clean_errors_file") + mock_exctract_errors = mocker.patch( + "bettyfixer.betty_fixer.exctract_errors") + + file_path = "test_file.c" + other_handlers(file_path) + + mock_create_tasks_directory.assert_called_once() + mock_copy_files_to_tasks.assert_called_once_with([file_path]) + mock_modify_main_files.assert_called_once_with([file_path]) + mock_clean_errors_file.assert_called_once_with('errors.txt') + mock_exctract_errors.assert_called_once_with(file_path, 'errors.txt') From 6122dd6fc58f8ee3061eff0d0da6156e3a5bec4e Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:44:04 +0300 Subject: [PATCH 69/91] Add test for create_tasks_directory function --- tests/test_betty_fixer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 30d0a8b..702f845 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -249,3 +249,12 @@ def test_other_handlers(self, mocker): mock_modify_main_files.assert_called_once_with([file_path]) mock_clean_errors_file.assert_called_once_with('errors.txt') mock_exctract_errors.assert_called_once_with(file_path, 'errors.txt') + + def test_create_tasks_directory(self, mocker): + """Test create_tasks_directory function.""" + mock_makedirs = mocker.patch("os.makedirs") + mock_os_path_exists = mocker.patch( + "os.path.exists", return_value=False) + create_tasks_directory() + mock_os_path_exists.assert_called_once_with("tasks") + mock_makedirs.assert_called_once_with("tasks") From 9b9be3e65d7f8d5804f4ca144411a8a755dcba0f Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:50:31 +0300 Subject: [PATCH 70/91] Add tests for copy_files_to_tasks and modify_main_files functions --- tests/test_betty_fixer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 702f845..87ad869 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -258,3 +258,25 @@ def test_create_tasks_directory(self, mocker): create_tasks_directory() mock_os_path_exists.assert_called_once_with("tasks") mock_makedirs.assert_called_once_with("tasks") + + def test_copy_files_to_tasks(self, mocker): + """Test copy_files_to_tasks function.""" + mock_exists = mocker.patch("os.path.exists", return_value=False) + mock_open = mocker.patch("builtins.open", mocker.mock_open( + read_data="#include \nint main() {}\n#include \"file.h\"")) + files = ["file1.c", "file2.c"] + copy_files_to_tasks(files) + assert mock_exists.call_count == len(files) + # Each file is opened twice: once for reading and once for writing + assert mock_open.call_count == len(files) * 2 + mock_open.assert_any_call("file1.c", 'r', encoding='utf-8') + + def test_modify_main_files(self, mocker): + """Test modify_main_files function.""" + mock_open = mocker.patch("builtins.open", mocker.mock_open( + read_data="#include \nint main() {}\n#include \"file.h\"")) + files = ["file1.c", "file2.c"] + modify_main_files(files) + assert mock_open.call_count == len(files) * 2 + mock_open.assert_any_call("file1.c", 'r', encoding='utf-8') + mock_open.assert_any_call("file1.c", 'w', encoding='utf-8') From 6e7bc6da329b3f1f73748dfd3b3889f4ab8391ba Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:54:41 +0300 Subject: [PATCH 71/91] Add test for record_processed_file function --- tests/test_betty_fixer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 87ad869..b108c3e 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -280,3 +280,13 @@ def test_modify_main_files(self, mocker): assert mock_open.call_count == len(files) * 2 mock_open.assert_any_call("file1.c", 'r', encoding='utf-8') mock_open.assert_any_call("file1.c", 'w', encoding='utf-8') + + def test_record_processed_file(self, mocker): + """Test record_processed_file function.""" + HIDDEN_FILE_NAME = ".processed_files" # pylint: disable=invalid-name + mock_open = mocker.patch("builtins.open", mocker.mock_open()) + filename = "test_file.c" + record_processed_file(filename) + mock_open.assert_called_once_with( + HIDDEN_FILE_NAME, 'a', encoding='utf-8') + mock_open().write.assert_called_once_with(filename + '\n') From a1eee78aed820a934ea5fc4f5c3083afed8ebdb3 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:57:11 +0300 Subject: [PATCH 72/91] Add tests for is_file_processed function --- tests/test_betty_fixer.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index b108c3e..ba7dc16 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -290,3 +290,27 @@ def test_record_processed_file(self, mocker): mock_open.assert_called_once_with( HIDDEN_FILE_NAME, 'a', encoding='utf-8') mock_open().write.assert_called_once_with(filename + '\n') + + def test_is_file_processed(self, mocker): + """Test is_file_processed function.""" + mocker.patch("os.path.exists", return_value=True) + mocker.patch("builtins.open", mocker.mock_open( + read_data="test_file.c\n")) + + assert is_file_processed("test_file.c") is True + + def test_is_file_processed_not_exists(self, mocker): + """Test is_file_processed function when the file does not exist.""" + mocker.patch("os.path.exists", return_value=False) + + assert is_file_processed("test_file.c") is False + + def test_is_file_processed_not_processed(self, mocker): + """Test is_file_processed function when the file has not been processed.""" + # Mock os.path.exists to return True + mocker.patch("os.path.exists", return_value=True) + # Mock builtins.open to return a file without the filename in it + mocker.patch("builtins.open", mocker.mock_open( + read_data="other_file.c\n")) + + assert is_file_processed("test_file.c") is False From 0b1a794bc853af7aa9f5cb55611ced566fcff37b Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:05:57 +0300 Subject: [PATCH 73/91] Fix betty style and remove unused function --- tests/test_betty_fixer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index ba7dc16..6404886 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -9,7 +9,7 @@ remove_consecutive_blank_lines, add_parentheses_around_return, fix_comments, remove_trailing_whitespaces, fix_betty_warnings, remove_blank_lines_inside_comments, - fix_betty_style, more_than_5_functions_in_the_file, + fix_betty_style, find_available_file_name, copy_remaining_lines, betty_handler, other_handlers, create_tasks_directory, copy_files_to_tasks, modify_main_files, record_processed_file, From 4632459d3b803c74d0c9e8019cccb3b00a2a21b1 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:07:39 +0300 Subject: [PATCH 74/91] Fix pylint warning in test_betty_fixer.py --- tests/test_betty_fixer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 6404886..b0f6bdc 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -17,7 +17,7 @@ ) -class TestBettyFixer: +class TestBettyFixer: # pylint: disable=too-many-public-methods """ Test the betty_fixer module. """ From ed4c75fc8ae2140f32b2d7eb7a65125cf308890d Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 18:32:41 +0300 Subject: [PATCH 75/91] Add test for main function when .processed_files invoked --- tests/test_betty_fixer.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index b0f6bdc..a2453bc 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -3,13 +3,14 @@ """ import os import re +import sys import pytest from bettyfixer.betty_fixer import ( read_file, write_file, add_line_without_newline, remove_consecutive_blank_lines, add_parentheses_around_return, fix_comments, remove_trailing_whitespaces, fix_betty_warnings, remove_blank_lines_inside_comments, - fix_betty_style, + fix_betty_style, main, find_available_file_name, copy_remaining_lines, betty_handler, other_handlers, create_tasks_directory, copy_files_to_tasks, modify_main_files, record_processed_file, @@ -314,3 +315,13 @@ def test_is_file_processed_not_processed(self, mocker): read_data="other_file.c\n")) assert is_file_processed("test_file.c") is False + + def test_main_processed_files(self, mocker, capsys): + """Test main function when .processed_files exists.""" + mocker.patch("bettyfixer.betty_fixer.is_file_processed", + return_value=True) + + with pytest.raises(SystemExit): + main() + captured = capsys.readouterr() + assert "The files have already been processed. Skipping.\n" == captured.out From 84d29eda7a7b9fe3f6ceabe7a58cdfd02c74a195 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 18:33:23 +0300 Subject: [PATCH 76/91] Add test for main function with no arguments --- tests/test_betty_fixer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index a2453bc..d747e55 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -325,3 +325,14 @@ def test_main_processed_files(self, mocker, capsys): main() captured = capsys.readouterr() assert "The files have already been processed. Skipping.\n" == captured.out + + def test_main_no_args(self, mocker, capsys): + """Test main function with no arguments.""" + mocker.patch("bettyfixer.betty_fixer.is_file_processed", + return_value=False) + mocker.patch("sys.argv", ["betty_fixer"]) + with pytest.raises(SystemExit): + main() + + captured = capsys.readouterr() + assert "Usage: python -m betty_fixer_package.betty_fixer " in captured.out From c33977b2de41eb8ae6e9c5e7037c271a19cb1e3a Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Thu, 22 Feb 2024 18:34:10 +0300 Subject: [PATCH 77/91] Add test for main function with -H option --- tests/test_betty_fixer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index d747e55..3659998 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -336,3 +336,17 @@ def test_main_no_args(self, mocker, capsys): captured = capsys.readouterr() assert "Usage: python -m betty_fixer_package.betty_fixer " in captured.out + + def test_main_header_option(self, mocker): + """Test main function with -H option.""" + mocker.patch("bettyfixer.betty_fixer.is_file_processed", + return_value=False) + mocker.patch("bettyfixer.betty_fixer.betty_check", return_value=True) + mocker.patch("sys.argv", ["betty_fixer", "-H", "header.h"]) + mock_autoproto = mocker.patch("bettyfixer.betty_fixer.autoproto") + + main() + + assert sys.argv[sys.argv.index("-H") + 1] == "header.h" + mock_autoproto.assert_called_once_with( + ".", "header.h") From 453199d5ebb4f835198f1d42ba533736a4cc4aab Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 10:18:05 +0300 Subject: [PATCH 78/91] Add test for main function with -H option but no header --- tests/test_betty_fixer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 3659998..e641a34 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -350,3 +350,12 @@ def test_main_header_option(self, mocker): assert sys.argv[sys.argv.index("-H") + 1] == "header.h" mock_autoproto.assert_called_once_with( ".", "header.h") + + def test_main_header_option_no_header(self, mocker, capsys): + """Test main function with -H option but no header. + checks stdout for the error message. + """ + mocker.patch("sys.argv", ["betty_fixer", "-H"]) + main() + capured = capsys.readouterr() + assert "\x1b[31mUsage : bettyfixer -H .h\x1b[39m" in capured.out From a077d08893a23c7ef0ade223ffe405eed0f78cc6 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 10:18:23 +0300 Subject: [PATCH 79/91] Add test for main function with -H option --- tests/test_betty_fixer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index e641a34..b74e642 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -359,3 +359,13 @@ def test_main_header_option_no_header(self, mocker, capsys): main() capured = capsys.readouterr() assert "\x1b[31mUsage : bettyfixer -H .h\x1b[39m" in capured.out + + def test_main_header_print_assertion(self, mocker): + """Test main function with -H option but no header. + checks print_header_name_missing being called. + """ + mock_print_header_missing = mocker.patch( + "bettyfixer.betty_fixer.print_header_name_missing") + mocker.patch("sys.argv", ["betty_fixer", "-H"]) + main() + mock_print_header_missing.assert_called_once() From 888472f4559ff3caf680fc1a895bb68912df1358 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 10:22:49 +0300 Subject: [PATCH 80/91] Add test for main function with file arguments --- tests/test_betty_fixer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index b74e642..02617d9 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -369,3 +369,25 @@ def test_main_header_print_assertion(self, mocker): mocker.patch("sys.argv", ["betty_fixer", "-H"]) main() mock_print_header_missing.assert_called_once() + + def test_main_files(self, mocker): + """Test main function with file arguments.""" + mocker.patch("bettyfixer.betty_fixer.is_file_processed", + return_value=False) + mocker.patch("sys.argv", ["betty_fixer", "file1.c", "file2.c"]) + mock_betty_style = mocker.patch( + "bettyfixer.betty_fixer.fix_betty_style") + mock_vi_script = mocker.patch("bettyfixer.betty_fixer.run_vi_script") + mock_record_processed_file = mocker.patch( + "bettyfixer.betty_fixer.record_processed_file") + mocker.patch("os.remove") + + main() + + mock_betty_style.assert_called_once_with( + ["file1.c", "file2.c"]) + mock_vi_script.assert_has_calls( + [mocker.call("file1.c"), mocker.call("file2.c")]) + mock_record_processed_file.assert_has_calls( + [mocker.call("file1.c"), mocker.call("file2.c")]) + os.remove.assert_called_once_with('errors.txt') From bd168f39c522e976309242ebde704c429dfb2f19 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:11:42 +0300 Subject: [PATCH 81/91] Add test for errors_extractor module --- tests/test_errors_extractor.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_errors_extractor.py diff --git a/tests/test_errors_extractor.py b/tests/test_errors_extractor.py new file mode 100644 index 0000000..2ded824 --- /dev/null +++ b/tests/test_errors_extractor.py @@ -0,0 +1,21 @@ +""" +Test the errors_extractor module. +""" +from subprocess import CompletedProcess, CalledProcessError +from bettyfixer.errors_extractor import exctract_errors + + +def test_exctract_errors_no_errors(mocker): + """ + Test the exctract_errors function when Betty does not return any errors. + """ + mock_subprocess = mocker.patch('subprocess.run', return_value=CompletedProcess( + ['betty', 'file1.c'], 0, 'output', '')) + mock_open = mocker.patch('builtins.open', mocker.mock_open()) + + exctract_errors('file1.c', 'errors.txt') + + mock_subprocess.assert_called_once_with(['betty', 'file1.c'], + capture_output=True, text=True, check=True) + mock_open.assert_called_once_with('errors.txt', 'a', encoding='utf-8') + mock_open().write.assert_called_once_with('output') From 5d7676eb6c8bafdff5433725b89714e506d2fd03 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:11:55 +0300 Subject: [PATCH 82/91] Add tests for extract_errors function --- tests/test_errors_extractor.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_errors_extractor.py b/tests/test_errors_extractor.py index 2ded824..3bf80b7 100644 --- a/tests/test_errors_extractor.py +++ b/tests/test_errors_extractor.py @@ -19,3 +19,18 @@ def test_exctract_errors_no_errors(mocker): capture_output=True, text=True, check=True) mock_open.assert_called_once_with('errors.txt', 'a', encoding='utf-8') mock_open().write.assert_called_once_with('output') + + +def test_exctract_errors_with_errors(mocker): + """ + Test the exctract_errors function when Betty returns errors. + """ + mock_subprocess = mocker.patch('subprocess.run', side_effect=CalledProcessError( + ['betty', 'file1.c'], 1, 'output', 'error')) + mock_open = mocker.patch('builtins.open', mocker.mock_open()) + + exctract_errors('file1.c', 'errors.txt') + + mock_subprocess.assert_called_once_with(['betty', 'file1.c'], + capture_output=True, text=True, check=True) + mock_open.assert_called_once_with('errors.txt', 'a', encoding='utf-8') From 42f2db23c7b4a59dde66631a5c6933c84834f1b3 Mon Sep 17 00:00:00 2001 From: Younis <23105954+Younis-Ahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:16:02 +0300 Subject: [PATCH 83/91] Update linting.yml --- .github/workflows/linting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index de21288..ac2a252 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -17,7 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pylint pycodestyle colorama + pip install pylint pycodestyle colorama pytest - name: Analysing the code with pylint run: | pylint $(git ls-files '*.py') From 4ec3ae6aede804e3938d5df60470c6e3ab4deca9 Mon Sep 17 00:00:00 2001 From: Younis <23105954+Younis-Ahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:24:16 +0300 Subject: [PATCH 84/91] Create testing.yml --- .github/workflows/testing.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..deb5220 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,33 @@ +name: Unit testing application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint pycodestyle colorama pytest + - name: Create test-results directory + run: mkdir -p test-results + - name: Test with pytest + run: | + pytest --junitxml=test-results/results.xml -k 'not test_api_key_manager' + - uses: actions/upload-artifact@v3 + if: always() + with: + name: pytest-results + path: test-results + retention-days: 30 From 6dbe9dc0685d7d58a1fe78fc25219db171560f24 Mon Sep 17 00:00:00 2001 From: Younis <23105954+Younis-Ahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:27:17 +0300 Subject: [PATCH 85/91] Update linting.yml --- .github/workflows/linting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index ac2a252..72ea9cf 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -17,7 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pylint pycodestyle colorama pytest + pip install pylint pycodestyle colorama pytest pytest-mock - name: Analysing the code with pylint run: | pylint $(git ls-files '*.py') From 16ffec357c1d990c9de5426b838c421ad089caa6 Mon Sep 17 00:00:00 2001 From: Younis <23105954+Younis-Ahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:27:53 +0300 Subject: [PATCH 86/91] Update testing.yml --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index deb5220..4fbcafc 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -19,12 +19,12 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pylint pycodestyle colorama pytest + pip install pylint pycodestyle colorama pytest pytest-mock - name: Create test-results directory run: mkdir -p test-results - name: Test with pytest run: | - pytest --junitxml=test-results/results.xml -k 'not test_api_key_manager' + pytest --junitxml=test-results/results.xml - uses: actions/upload-artifact@v3 if: always() with: From d968055c06983683a7ae320b56836dcbeeda050d Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:50:07 +0300 Subject: [PATCH 87/91] Update max-line-length to 79 characters --- pylintrc | 2 +- tests/test_autoprototype.py | 27 ++++++----- tests/test_backup.py | 7 ++- tests/test_betty_fixer.py | 82 +++++++++++++++++++++++----------- tests/test_errors_extractor.py | 24 ++++++---- 5 files changed, 96 insertions(+), 46 deletions(-) diff --git a/pylintrc b/pylintrc index 9a06013..f59e26f 100644 --- a/pylintrc +++ b/pylintrc @@ -337,7 +337,7 @@ indent-after-paren=4 indent-string=' ' # Maximum number of characters on a single line. -max-line-length=100 +max-line-length=79 # Maximum number of lines in a module. max-module-lines=1000 diff --git a/tests/test_autoprototype.py b/tests/test_autoprototype.py index ee93e2b..59bb0dc 100644 --- a/tests/test_autoprototype.py +++ b/tests/test_autoprototype.py @@ -28,7 +28,8 @@ def setup_method(self): with open("test.c", "w", encoding="utf-8") as f: f.write( - 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') + 'int main(int argc, char **argv)\ +{\nprintf("Hello World"\nreturn 0; \n}') yield os.remove("test.c") @@ -53,11 +54,12 @@ def test_betty_check_installed(self, mocker): "subprocess.run"), mocker.patch("glob.glob") mock_glob.return_value = ["test.c"] - mock_run.return_value = CompletedProcess(args=['betty'] + mock_glob.return_value, - returncode=0, - stdout='ERROR: ', - stderr='WARNING:' - ) + mock_run.return_value = CompletedProcess( + args=['betty'] + mock_glob.return_value, + returncode=0, + stdout='ERROR: ', + stderr='WARNING:' + ) betty_check_result = betty_check() assert betty_check_result is not None assert betty_check_result is False @@ -122,14 +124,16 @@ def test_check_ctags_not_installed(self, mocker): assert ctag[0] is False and isinstance(ctag[1], str) def test_generate_tags_failure(self, mocker): - """ Test the generate_tags function not working from autoprototype.py""" + """ Test the generate_tags function not + working from autoprototype.py""" mock_run = mocker.patch("subprocess.run") mock_run.side_effect = subprocess.CalledProcessError( returncode=1, cmd=['ctags', '-R', '.'], stderr="Error") assert not generate_tags('.') def test_generate_tags_success(self, mocker): - """Test the generate_tags function when the subprocess command succeeds.""" + """Test the generate_tags function when the subprocess command + succeeds.""" mock_run = mocker.patch("subprocess.run") mock_run.return_value = CompletedProcess(args=[ 'ctags', '-R', '--c-kinds=+p', @@ -152,7 +156,8 @@ def test_generate_tags_success(self, mocker): @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_filter_tags_success(self): - """Test the filter_tags function when the subprocess command succeeds.""" + """Test the filter_tags function when the + subprocess command succeeds.""" generate_tags(".") result = filter_tags('.', "tags") @@ -226,7 +231,9 @@ def test_check_header_file(self): os.remove("test.h") result = check_header_file("test") assert result == ( - False, "Error: Invalid header file. It should have a '.h' extension.") + False, + "Error: Invalid header file. It should have a '.h' extension." + ) @pytest.mark.usefixtures("setup_tear_down_temp_files") def test_autoproto(self, mocker): diff --git a/tests/test_backup.py b/tests/test_backup.py index a91f4ae..41caad5 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -12,12 +12,15 @@ class TestBackup: @pytest.fixture(autouse=True) def setup_method(self): - """Create a test file.""" # pylint: disable=attribute-defined-outside-init + """Create a test file.""" + # pylint: disable=attribute-defined-outside-init self.test_file = 'test.c' with open(self.test_file, 'w', encoding='utf-8') as f: self.test_file = f.name f.write( - 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') + 'int main(int argc, char **argv){\nprintf(\ +"Hello World"\nreturn 0; \n}' + ) yield os.remove(self.test_file) if os.path.exists(self.test_file + '.bak'): diff --git a/tests/test_betty_fixer.py b/tests/test_betty_fixer.py index 02617d9..751fa4e 100644 --- a/tests/test_betty_fixer.py +++ b/tests/test_betty_fixer.py @@ -28,7 +28,8 @@ def setup_teardown(self): with open("test.c", "w", encoding="utf-8") as f: f.write( - 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}') + 'int main(int argc, char **argv)\ +{\nprintf("Hello World"\nreturn 0; \n}') yield os.remove("test.c") @@ -38,7 +39,8 @@ def setup_teardown(self): def test_read_file(self): """Test read_file function.""" assert read_file( - "test.c") == 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}' + "test.c") == 'int main(int argc, char **argv)\ +{\nprintf("Hello World"\nreturn 0; \n}' def test_write_file(self): """Test write_file function.""" @@ -50,7 +52,8 @@ def test_add_line_without_newline(self): """Test add_line_without_newline function.""" add_line_without_newline("test.c", "\n") assert read_file( - "test.c") == 'int main(int argc, char **argv){\nprintf("Hello World"\nreturn 0; \n}\n' + "test.c") == 'int main(int argc, char **argv)\ +{\nprintf("Hello World"\nreturn 0; \n}\n' def test_add_line_without_newline_fail(self): """Test add_line_without_newline function.""" @@ -99,13 +102,18 @@ def test_remove_trailing_whitespaces(self): "Hello World\t", "Hello World\t\t"] # ❗ "Hello World\n" and "Hello World\n " is failing assert all(remove_trailing_whitespaces(line) - == re.search(r"Hello World\S*", line).group() for line in lines) + == re.search( + r"Hello World\S*", line).group() for line in lines + ) - # ❗ @pytest.mark.skip(reason="Needs to be refactored with Dependency Injection in mind") + # ❗ @pytest.mark.skip(reason= + # "Needs to be refactored with Dependency Injection in mind") def test_fix_betty_warnings(self, mocker): """Test fix_betty_warnings function.""" mock_remove_consecutive_blank_lines = mocker.patch( - "bettyfixer.betty_fixer.remove_consecutive_blank_lines", return_value="some_content") + "bettyfixer.betty_fixer.remove_consecutive_blank_lines", + return_value="some_content" + ) mock_fix_comments = mocker.patch( "bettyfixer.betty_fixer.fix_comments", return_value="some_content") mock_remove_trailing_whitespaces = mocker.patch( @@ -132,29 +140,42 @@ def test_remove_blank_lines_inside_comments(self, mocker): mock_open.assert_any_call("some_file", 'w', encoding='utf-8') mock_open().writelines.assert_called_once_with(["/**\n", "*/"]) - # ❗@pytest.mark.skip(reason="in serious need of refactoring.Decoupling and Dependency Injection") +# ❗@pytest.mark.skip(reason= + # "in serious need of refactoring.Decoupling and Dependency Injection") def test_fix_betty_style(self, mocker): """Test fix_betty_style function.""" file_paths = ["file1", "file2", "file3"] mock_create_backup = mocker.patch( - "bettyfixer.betty_fixer.create_backup", return_value="file content") + "bettyfixer.betty_fixer.create_backup", + return_value="file content" + ) mock_run_vi_script = mocker.patch( - "bettyfixer.betty_fixer.run_vi_script", return_value="file content") + "bettyfixer.betty_fixer.run_vi_script", + return_value="file content" + ) mock_read_file = mocker.patch( - "bettyfixer.betty_fixer.read_file", return_value="file content") + "bettyfixer.betty_fixer.read_file", + return_value="file content" + ) mock_write_file = mocker.patch( - "bettyfixer.betty_fixer.write_file", return_value="file content") + "bettyfixer.betty_fixer.write_file", + return_value="file content" + ) mock_add_line_without_newline = mocker.patch( - "bettyfixer.betty_fixer.add_line_without_newline", return_value="file content") + "bettyfixer.betty_fixer.add_line_without_newline", + return_value="file content" + ) mock_process_errors = mocker.patch( - "bettyfixer.betty_fixer.process_errors", return_value="file content") + "bettyfixer.betty_fixer.process_errors", + return_value="file content" + ) mock_open = mocker.patch( "builtins.open", mocker.mock_open(read_data="file content")) fix_betty_style(file_paths) mock_process_errors.call_count = len(file_paths) * 2 - # Check that the mocked functions were called with the correct arguments + # Check that the mocked functions were called with correct args for file_path in file_paths: mock_create_backup.assert_any_call(file_path) mock_run_vi_script.assert_any_call(file_path) @@ -168,7 +189,9 @@ def test_fix_betty_style(self, mocker): mock_open().writelines.assert_called_with(["file content"]) # ❗ - @pytest.mark.skip(reason="Needs refactoring [DI, pure functions, decoupling]") + @pytest.mark.skip( + reason="Needs refactoring [DI, pure functions, decoupling]" + ) def test_more_than_5_functions_in_the_file(self, mocker): """Test more_than_5_functions_in_the_file function.""" pass # pylint: disable=unnecessary-pass @@ -183,7 +206,7 @@ def test_find_available_file_name_with_existing_files(self, mocker): """Test find_available_file_name when there are existing files with the same base name.""" exists_side_effect = [ - True, True, False] # Simulate that "test1.txt" and "test2.txt" exist + True, True, False] mocker.patch('os.path.exists', side_effect=exists_side_effect) assert find_available_file_name("test.txt") == "test3.txt" @@ -191,7 +214,7 @@ def test_find_available_file_name_with_many_existing_files(self, mocker): """Test find_available_file_name when there are many existing files with the same base name.""" exists_side_effect = [ - True] * 100 + [False] # Simulate that "test1.txt" to "test100.txt" exist + True] * 100 + [False] mocker.patch('os.path.exists', side_effect=exists_side_effect) assert find_available_file_name("test.txt") == "test101.txt" @@ -217,13 +240,16 @@ def test_betty_handler_no_errors(self, mocker): def test_betty_handler_with_errors(self, mocker): """Test betty_handler function when there are Betty errors.""" - error_lines = "More than 40 lines in a function\nline over 80 characters\n" + error_lines = "More than 40 lines in a function\nline over\ + 80 characters\n" mock_open = mocker.patch( "builtins.open", mocker.mock_open(read_data=error_lines)) mock_other_handlers = mocker.patch( "bettyfixer.betty_fixer.other_handlers") mock_extract_and_print_variables = mocker.patch( - "bettyfixer.betty_fixer.extract_and_print_variables", return_value=("file_path",)) + "bettyfixer.betty_fixer.extract_and_print_variables", + return_value=("file_path",) + ) betty_handler("errors.txt") mock_open.assert_called_once_with("errors.txt", 'r', encoding='utf-8') mock_extract_and_print_variables.assert_called() @@ -264,7 +290,8 @@ def test_copy_files_to_tasks(self, mocker): """Test copy_files_to_tasks function.""" mock_exists = mocker.patch("os.path.exists", return_value=False) mock_open = mocker.patch("builtins.open", mocker.mock_open( - read_data="#include \nint main() {}\n#include \"file.h\"")) + read_data="#include \nint main(\ +) {}\n#include \"file.h\"")) files = ["file1.c", "file2.c"] copy_files_to_tasks(files) assert mock_exists.call_count == len(files) @@ -275,7 +302,8 @@ def test_copy_files_to_tasks(self, mocker): def test_modify_main_files(self, mocker): """Test modify_main_files function.""" mock_open = mocker.patch("builtins.open", mocker.mock_open( - read_data="#include \nint main() {}\n#include \"file.h\"")) + read_data="#include \nint main(\ +) {}\n#include \"file.h\"")) files = ["file1.c", "file2.c"] modify_main_files(files) assert mock_open.call_count == len(files) * 2 @@ -307,7 +335,8 @@ def test_is_file_processed_not_exists(self, mocker): assert is_file_processed("test_file.c") is False def test_is_file_processed_not_processed(self, mocker): - """Test is_file_processed function when the file has not been processed.""" + """Test is_file_processed function when + the file has not been processed.""" # Mock os.path.exists to return True mocker.patch("os.path.exists", return_value=True) # Mock builtins.open to return a file without the filename in it @@ -324,7 +353,8 @@ def test_main_processed_files(self, mocker, capsys): with pytest.raises(SystemExit): main() captured = capsys.readouterr() - assert "The files have already been processed. Skipping.\n" == captured.out + assert "The files have already been processed.\ + Skipping.\n" == captured.out def test_main_no_args(self, mocker, capsys): """Test main function with no arguments.""" @@ -335,7 +365,8 @@ def test_main_no_args(self, mocker, capsys): main() captured = capsys.readouterr() - assert "Usage: python -m betty_fixer_package.betty_fixer " in captured.out + assert "Usage: python -m \ +betty_fixer_package.betty_fixer " in captured.out def test_main_header_option(self, mocker): """Test main function with -H option.""" @@ -358,7 +389,8 @@ def test_main_header_option_no_header(self, mocker, capsys): mocker.patch("sys.argv", ["betty_fixer", "-H"]) main() capured = capsys.readouterr() - assert "\x1b[31mUsage : bettyfixer -H .h\x1b[39m" in capured.out + assert "\x1b[31mUsage : bettyfixer -H \ +.h\x1b[39m" in capured.out def test_main_header_print_assertion(self, mocker): """Test main function with -H option but no header. diff --git a/tests/test_errors_extractor.py b/tests/test_errors_extractor.py index 3bf80b7..0c18db3 100644 --- a/tests/test_errors_extractor.py +++ b/tests/test_errors_extractor.py @@ -9,14 +9,18 @@ def test_exctract_errors_no_errors(mocker): """ Test the exctract_errors function when Betty does not return any errors. """ - mock_subprocess = mocker.patch('subprocess.run', return_value=CompletedProcess( - ['betty', 'file1.c'], 0, 'output', '')) + mock_subprocess = mocker.patch( + 'subprocess.run', return_value=CompletedProcess( + ['betty', 'file1.c'], 0, 'output', '') + ) mock_open = mocker.patch('builtins.open', mocker.mock_open()) exctract_errors('file1.c', 'errors.txt') - mock_subprocess.assert_called_once_with(['betty', 'file1.c'], - capture_output=True, text=True, check=True) + mock_subprocess.assert_called_once_with( + ['betty', 'file1.c'], + capture_output=True, text=True, check=True + ) mock_open.assert_called_once_with('errors.txt', 'a', encoding='utf-8') mock_open().write.assert_called_once_with('output') @@ -25,12 +29,16 @@ def test_exctract_errors_with_errors(mocker): """ Test the exctract_errors function when Betty returns errors. """ - mock_subprocess = mocker.patch('subprocess.run', side_effect=CalledProcessError( - ['betty', 'file1.c'], 1, 'output', 'error')) + mock_subprocess = mocker.patch( + 'subprocess.run', side_effect=CalledProcessError( + ['betty', 'file1.c'], 1, 'output', 'error') + ) mock_open = mocker.patch('builtins.open', mocker.mock_open()) exctract_errors('file1.c', 'errors.txt') - mock_subprocess.assert_called_once_with(['betty', 'file1.c'], - capture_output=True, text=True, check=True) + mock_subprocess.assert_called_once_with( + ['betty', 'file1.c'], + capture_output=True, text=True, check=True + ) mock_open.assert_called_once_with('errors.txt', 'a', encoding='utf-8') From 03147953f6425a1581ffe97f64ec11fd0a46a874 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:51:22 +0300 Subject: [PATCH 88/91] Exclude setup.py from pylint and pycodestyle analysis --- .github/workflows/linting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 72ea9cf..34abc14 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -20,7 +20,7 @@ jobs: pip install pylint pycodestyle colorama pytest pytest-mock - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + pylint $(git ls-files '*.py' | grep -v setup.py) - name: Analysing the code with pycodestyle run: | pycodestyle $(git ls-files '*.py' | grep -v setup.py) From a9038743380214f70dbd56db6569f9d715ed593a Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:58:46 +0300 Subject: [PATCH 89/91] Add ctags installation step to GitHub Actions workflow --- .github/workflows/testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 4fbcafc..5d7fa4f 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -20,6 +20,8 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint pycodestyle colorama pytest pytest-mock + - name: Install ctags + run: sudo apt-get update && sudo apt-get install -y exuberant-ctags - name: Create test-results directory run: mkdir -p test-results - name: Test with pytest From 2f6b22e6c43773d07a4c0ce0d685dead0a2a7083 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 15:06:30 +0300 Subject: [PATCH 90/91] Add betty installation step to testing workflow --- .github/workflows/testing.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 5d7fa4f..c4b7311 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -22,6 +22,10 @@ jobs: pip install pylint pycodestyle colorama pytest pytest-mock - name: Install ctags run: sudo apt-get update && sudo apt-get install -y exuberant-ctags + - name: Install betty + run: | + ./bettyfixer/install_dependency/.Betty/install.sh && + sudo mv bettyfixer/install_dependency/.Betty/betty.sh /bin/betty - name: Create test-results directory run: mkdir -p test-results - name: Test with pytest From 9fb6d2e77fcaef767da7c109ece15cbc1ecf9448 Mon Sep 17 00:00:00 2001 From: Younis-Ahmed <23105954+jonaahmed@users.noreply.github.com> Date: Sat, 24 Feb 2024 15:08:03 +0300 Subject: [PATCH 91/91] Update betty installation script to run with sudo --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c4b7311..260032e 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -24,7 +24,7 @@ jobs: run: sudo apt-get update && sudo apt-get install -y exuberant-ctags - name: Install betty run: | - ./bettyfixer/install_dependency/.Betty/install.sh && + sudo ./bettyfixer/install_dependency/.Betty/install.sh && sudo mv bettyfixer/install_dependency/.Betty/betty.sh /bin/betty - name: Create test-results directory run: mkdir -p test-results