From 2ab393265e4659d7f074dab49c44040ac6d6b391 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 14 Aug 2024 13:02:26 +0200 Subject: [PATCH 01/30] Add files via upload --- test/qlever/test_status_execute_mocken.py | 62 +++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/qlever/test_status_execute_mocken.py diff --git a/test/qlever/test_status_execute_mocken.py b/test/qlever/test_status_execute_mocken.py new file mode 100644 index 00000000..c2111351 --- /dev/null +++ b/test/qlever/test_status_execute_mocken.py @@ -0,0 +1,62 @@ +import unittest +from unittest.mock import patch, MagicMock +import psutil +from qlever.command import StatusCommand +from qlever.util import show_process_info +from io import StringIO +import sys + + +class TestStatusCommand(unittest.TestCase): + # Test the execute function while mocking psutil.process_iter and show_process_info + @patch('qlever.util.show_process_info') + @patch('psutil.process_iter') + def test_execute(self, mock_process_iter, mock_show_process_info): + args = MagicMock() + args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" + args.show = False + # replaces return of psutil.process_iter with simplified objects. + # For other testing use more realistic objects: {'name': 'systemd', 'pid': 1, 'username': 'root'} + mock_process_iter.return_value = ['process1.anders', 'process2.anders', 'process3.anders', 'example2.qlever'] + mock_show_process_info.side_effect = [False, False, False, True] + sc = StatusCommand + # execute the execute function and saving the result + result = sc.execute(args) + # Assert + mock_process_iter.assert_called_once() + mock_show_process_info.assert_called_once_with(mock_process_iter, args.cmdline_regex, show_heading=True) + assert result + + def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_info): + # Arrange + args = MagicMock() + args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" + args.show = False + + # Mock process_iter to return an empty list, simulating no matching processes + mock_process_iter.return_value = [] + + # Redirect stdout to capture print output + captured_output = StringIO() + sys.stdout = captured_output + + # Instantiate the StatusCommand + status_command = StatusCommand() + + # Act + result = status_command.execute(args) + + # Reset redirect. + sys.stdout = sys.__stdout__ + + # Assert + mock_process_iter.assert_called_once() + mock_show_process_info.assert_not_called() + self.assertFalse(result) + + # Verify the correct output was printed + self.assertIn("No processes found", captured_output.getvalue()) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From ac200b0af42448ccce9e3d9d1a48fbf06d8eabf5 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 14 Aug 2024 13:09:26 +0200 Subject: [PATCH 02/30] Update test_status_execute_mocken.py --- test/qlever/test_status_execute_mocken.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/qlever/test_status_execute_mocken.py b/test/qlever/test_status_execute_mocken.py index c2111351..675328ab 100644 --- a/test/qlever/test_status_execute_mocken.py +++ b/test/qlever/test_status_execute_mocken.py @@ -11,17 +11,20 @@ class TestStatusCommand(unittest.TestCase): # Test the execute function while mocking psutil.process_iter and show_process_info @patch('qlever.util.show_process_info') @patch('psutil.process_iter') - def test_execute(self, mock_process_iter, mock_show_process_info): + def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): args = MagicMock() args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" args.show = False + # replaces return of psutil.process_iter with simplified objects. # For other testing use more realistic objects: {'name': 'systemd', 'pid': 1, 'username': 'root'} mock_process_iter.return_value = ['process1.anders', 'process2.anders', 'process3.anders', 'example2.qlever'] mock_show_process_info.side_effect = [False, False, False, True] sc = StatusCommand + # execute the execute function and saving the result result = sc.execute(args) + # Assert mock_process_iter.assert_called_once() mock_show_process_info.assert_called_once_with(mock_process_iter, args.cmdline_regex, show_heading=True) @@ -33,17 +36,17 @@ def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_i args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" args.show = False - # Mock process_iter to return an empty list, simulating no matching processes + # Mock process_iter to return an empty list, simulating that no matching processes are found mock_process_iter.return_value = [] - # Redirect stdout to capture print output + # Capture the string-output captured_output = StringIO() sys.stdout = captured_output # Instantiate the StatusCommand status_command = StatusCommand() - # Act + # execute the execute function and saving the result result = status_command.execute(args) # Reset redirect. @@ -59,4 +62,4 @@ def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_i if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From 170417339e23194094229cfc4da816881b482e37 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 14 Aug 2024 13:20:45 +0200 Subject: [PATCH 03/30] Update test_status_execute_mocken.py --- test/qlever/test_status_execute_mocken.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/qlever/test_status_execute_mocken.py b/test/qlever/test_status_execute_mocken.py index 675328ab..9a7aafb5 100644 --- a/test/qlever/test_status_execute_mocken.py +++ b/test/qlever/test_status_execute_mocken.py @@ -3,6 +3,7 @@ import psutil from qlever.command import StatusCommand from qlever.util import show_process_info +import qlever.commands.status from io import StringIO import sys From 953358f8133f329cc2b64438c07df751aa8b7c1c Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 14 Aug 2024 13:22:33 +0200 Subject: [PATCH 04/30] Update test_status_execute_mocken.py --- test/qlever/test_status_execute_mocken.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/qlever/test_status_execute_mocken.py b/test/qlever/test_status_execute_mocken.py index 9a7aafb5..5edcf3da 100644 --- a/test/qlever/test_status_execute_mocken.py +++ b/test/qlever/test_status_execute_mocken.py @@ -60,7 +60,3 @@ def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_i # Verify the correct output was printed self.assertIn("No processes found", captured_output.getvalue()) - - -if __name__ == '__main__': - unittest.main() From 96ddcacca90eb3b87466e21445b641b67ed3530d Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 14 Aug 2024 13:23:56 +0200 Subject: [PATCH 05/30] Update test_status_execute_mocken.py --- test/qlever/test_status_execute_mocken.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/qlever/test_status_execute_mocken.py b/test/qlever/test_status_execute_mocken.py index 5edcf3da..11c0cce7 100644 --- a/test/qlever/test_status_execute_mocken.py +++ b/test/qlever/test_status_execute_mocken.py @@ -13,6 +13,7 @@ class TestStatusCommand(unittest.TestCase): @patch('qlever.util.show_process_info') @patch('psutil.process_iter') def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): + # mocking the input for the execute function args = MagicMock() args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" args.show = False @@ -32,7 +33,7 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info assert result def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_info): - # Arrange + # mocking the input for the execute function args = MagicMock() args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" args.show = False From 12537dd51c3f9a8327e43143c9e2f826778e7ac9 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 20 Aug 2024 09:37:54 +0200 Subject: [PATCH 06/30] Update test_status_execute_mocken.py uploaded pycharm file --- test/qlever/test_status_execute_mocken.py | 75 ++++++++++++++++------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/test/qlever/test_status_execute_mocken.py b/test/qlever/test_status_execute_mocken.py index 11c0cce7..6f268011 100644 --- a/test/qlever/test_status_execute_mocken.py +++ b/test/qlever/test_status_execute_mocken.py @@ -1,39 +1,67 @@ import unittest from unittest.mock import patch, MagicMock import psutil -from qlever.command import StatusCommand -from qlever.util import show_process_info -import qlever.commands.status +from qlever.commands.status import StatusCommand from io import StringIO import sys +from datetime import datetime class TestStatusCommand(unittest.TestCase): - # Test the execute function while mocking psutil.process_iter and show_process_info - @patch('qlever.util.show_process_info') + @patch('qlever.commands.status.show_process_info') @patch('psutil.process_iter') def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): - # mocking the input for the execute function + # Mocking the input for the execute function args = MagicMock() args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" args.show = False - - # replaces return of psutil.process_iter with simplified objects. - # For other testing use more realistic objects: {'name': 'systemd', 'pid': 1, 'username': 'root'} - mock_process_iter.return_value = ['process1.anders', 'process2.anders', 'process3.anders', 'example2.qlever'] - mock_show_process_info.side_effect = [False, False, False, True] - sc = StatusCommand - - # execute the execute function and saving the result + + # Creating mock psutil.Process objects with necessary attributes + mock_process1 = MagicMock() + mock_process1.as_dict.return_value = { + 'cmdline': ['cmdline1'], + 'pid': 1, + 'username': 'user1', + 'create_time': datetime.now().timestamp(), + 'memory_info': MagicMock(rss=512 * 1024 * 1024) # 512 MB + } + + mock_process2 = MagicMock() + mock_process2.as_dict.return_value = { + 'cmdline': ['cmdline2'], + 'pid': 2, + 'username': 'user2', + 'create_time': datetime.now().timestamp(), + 'memory_info': MagicMock(rss=1024 * 1024 * 1024) # 1 GB + } + + # Mock the return value of process_iter to be a list of these mocked process objects + mock_process_iter.return_value = [mock_process1, mock_process2] + + # Simulate show_process_info returning False for the first and True for the second process + mock_show_process_info.side_effect = [False, True] + + sc = StatusCommand() + + # Execute the function result = sc.execute(args) - - # Assert + + # Debugging: Print the actual calls to show_process_info + print(f"Actual show_process_info calls: {mock_show_process_info.call_args_list}") + + # Assert that process_iter was called once mock_process_iter.assert_called_once() - mock_show_process_info.assert_called_once_with(mock_process_iter, args.cmdline_regex, show_heading=True) - assert result + # Assert that show_process_info was called with the correct arguments + mock_show_process_info.assert_any_call(mock_process1, args.cmdline_regex, show_heading=True) + mock_show_process_info.assert_any_call(mock_process2, args.cmdline_regex, show_heading=True) + + self.assertIsNone(result) + + @patch('qlever.util.show_process_info') + @patch('psutil.process_iter') def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_info): - # mocking the input for the execute function + # Mocking the input for the execute function args = MagicMock() args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" args.show = False @@ -48,15 +76,18 @@ def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_i # Instantiate the StatusCommand status_command = StatusCommand() - # execute the execute function and saving the result + # Execute the function result = status_command.execute(args) - # Reset redirect. + # Reset redirect sys.stdout = sys.__stdout__ - # Assert + # Assert that process_iter was called once mock_process_iter.assert_called_once() + + # Assert that show_process_info was never called since there are no processes mock_show_process_info.assert_not_called() + self.assertFalse(result) # Verify the correct output was printed From 6a8046d93f16616c2cfb5e269fa7fd73523ee558 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 20 Aug 2024 10:28:23 +0200 Subject: [PATCH 07/30] Create pytest.yml createt automated testing --- .github/workflows/pytest.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 00000000..d1640086 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,29 @@ +name: Python package + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["pypy3.9", "pypy3.10", "3.9", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{matrix.python-version}} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Test with pytest + run: | + pip install pytest pytest-cov + pytest From 6704850cdd2417d10355596e87e7a7d18ccd6f32 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 21 Aug 2024 11:05:57 +0200 Subject: [PATCH 08/30] Create test_stop_execute create new folder commands and set up the file for testing the command file stop --- test/qlever/commands/test_stop_execute | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/qlever/commands/test_stop_execute diff --git a/test/qlever/commands/test_stop_execute b/test/qlever/commands/test_stop_execute new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/qlever/commands/test_stop_execute @@ -0,0 +1 @@ + From b58d7dddd53553e01b2a1e22c9bcf54dbfd572d3 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 21 Aug 2024 11:08:08 +0200 Subject: [PATCH 09/30] Update and rename test/qlever/test_status_execute_mocken.py to test/qlever/commands/test_status_execute_mocken.py changing the path of the test_status_execute_mocken file --- test/qlever/{ => commands}/test_status_execute_mocken.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/qlever/{ => commands}/test_status_execute_mocken.py (100%) diff --git a/test/qlever/test_status_execute_mocken.py b/test/qlever/commands/test_status_execute_mocken.py similarity index 100% rename from test/qlever/test_status_execute_mocken.py rename to test/qlever/commands/test_status_execute_mocken.py From d46e928e6aa888945ae2b992cefc6a7902006ca9 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 21 Aug 2024 13:27:12 +0200 Subject: [PATCH 10/30] Update test_status_execute_mocken.py 1. Add a test for the first part of the execute function 2. More detailed description in the comments --- .../commands/test_status_execute_mocken.py | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/test/qlever/commands/test_status_execute_mocken.py b/test/qlever/commands/test_status_execute_mocken.py index 6f268011..a346e11e 100644 --- a/test/qlever/commands/test_status_execute_mocken.py +++ b/test/qlever/commands/test_status_execute_mocken.py @@ -1,6 +1,7 @@ import unittest from unittest.mock import patch, MagicMock import psutil +import qlever.command from qlever.commands.status import StatusCommand from io import StringIO import sys @@ -10,6 +11,8 @@ class TestStatusCommand(unittest.TestCase): @patch('qlever.commands.status.show_process_info') @patch('psutil.process_iter') + # testing execute for 2 processes. Just the second one is a qlever process. + # Mocking the process_iter and show_process_info method and testing if the methods are called correctly. def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): # Mocking the input for the execute function args = MagicMock() @@ -18,22 +21,26 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info # Creating mock psutil.Process objects with necessary attributes mock_process1 = MagicMock() - mock_process1.as_dict.return_value = { + # to test with real psutil.process objects use this: + '''mock_process1.as_dict.return_value = { 'cmdline': ['cmdline1'], 'pid': 1, 'username': 'user1', 'create_time': datetime.now().timestamp(), 'memory_info': MagicMock(rss=512 * 1024 * 1024) # 512 MB - } + }''' + mock_process1.as_dict.return_value = {'test': [1]} mock_process2 = MagicMock() - mock_process2.as_dict.return_value = { + mock_process2.as_dict.return_value = {'test': [2]} + # to test with real psutil.process objects use this: + '''mock_process2.as_dict.return_value = { 'cmdline': ['cmdline2'], 'pid': 2, 'username': 'user2', 'create_time': datetime.now().timestamp(), 'memory_info': MagicMock(rss=1024 * 1024 * 1024) # 1 GB - } + }''' # Mock the return value of process_iter to be a list of these mocked process objects mock_process_iter.return_value = [mock_process1, mock_process2] @@ -60,6 +67,7 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info @patch('qlever.util.show_process_info') @patch('psutil.process_iter') + # Verify the correct output was printed for an empty list of processes. def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_info): # Mocking the input for the execute function args = MagicMock() @@ -88,7 +96,27 @@ def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_i # Assert that show_process_info was never called since there are no processes mock_show_process_info.assert_not_called() - self.assertFalse(result) + self.assertIsNone(result) # Verify the correct output was printed self.assertIn("No processes found", captured_output.getvalue()) + + @patch.object(qlever.command.QleverCommand, 'show') + # Test the first part of the execute function. Test if the print command is executed correctly. + def test_execute_show_action_description(self, mock_show): + # Mocking the input for the execute function + args = MagicMock() + args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" + mock_show.return_value = True + + sc = StatusCommand() + + # Execute the function + result = sc.execute(args) + + # Assert that verifies that show was called with the correct parameters + mock_show.assert_any_call(f"Show all processes on this machine where " + f"the command line matches {args.cmdline_regex}" + f" using Python's psutil library", only_show=args.show) + + self.assertFalse(result) From a62da4d49a92f5cdd233e1c4579d1a7b40596ead Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 21 Aug 2024 14:26:19 +0200 Subject: [PATCH 11/30] Add files via upload --- .../commands/test_status_other_methods.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/qlever/commands/test_status_other_methods.py diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py new file mode 100644 index 00000000..6890f850 --- /dev/null +++ b/test/qlever/commands/test_status_other_methods.py @@ -0,0 +1,55 @@ +import unittest +from qlever.commands.status import StatusCommand +import argparse + + +class TestStatusCommand(unittest.TestCase): + def test_description(self): + # Create an instance of StatusCommand + sc = StatusCommand() + + # Call the method + result = sc.description() + + self.assertEqual(result, "Show QLever processes running on this machine") + + def test_should_have_qleverfile(self): + # Create an instance of StatusCommand + sc = StatusCommand() + + # Call the method + result = sc.should_have_qleverfile() + + assert not result + + def test_relevant_qleverfile_arguments(self): + # Create an instance of StatusCommand + sc = StatusCommand() + + # Call the method + result = sc.relevant_qleverfile_arguments() + + self.assertEqual(result, {}) + + def test_additional_arguments(self): + # Create an instance of StatusCommand + sc = StatusCommand() + + # Create a parser and a subparser + parser = argparse.ArgumentParser() + subparser = parser.add_argument_group('test') + # Call the method + sc.additional_arguments(subparser) + # Parse an empty argument list to see the default + args = parser.parse_args([]) + + # Test that the default value is set correctly + self.assertEqual(args.cmdline_regex, "^(ServerMain|IndexBuilderMain)") + + # Test that the help text is correctly set + argument_help = subparser._group_actions[-1].help + self.assertEqual(argument_help, "Show only processes where the command line matches this regex") + + +if __name__ == '__main__': + unittest.main() From 98811a87c8cea0b61b035af80cef9f74fb387588 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Mon, 26 Aug 2024 12:59:00 +0200 Subject: [PATCH 12/30] Update test_status_other_methods.py --- test/qlever/commands/test_status_other_methods.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py index 6890f850..ee2edd0d 100644 --- a/test/qlever/commands/test_status_other_methods.py +++ b/test/qlever/commands/test_status_other_methods.py @@ -49,7 +49,3 @@ def test_additional_arguments(self): # Test that the help text is correctly set argument_help = subparser._group_actions[-1].help self.assertEqual(argument_help, "Show only processes where the command line matches this regex") - - -if __name__ == '__main__': - unittest.main() From 6fe65588aa35fa0962cf1254b7b9e3984d0c7b06 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 27 Aug 2024 09:40:35 +0200 Subject: [PATCH 13/30] Update pytest.yml --- .github/workflows/pytest.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index d1640086..20530325 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -22,7 +22,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt - name: Test with pytest run: | pip install pytest pytest-cov From e50ef8bac8667acd87c6bf50ec9e82f9ebd67042 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 10 Sep 2024 09:11:25 +0200 Subject: [PATCH 14/30] Update pytest.yml --- .github/workflows/pytest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 20530325..e6688406 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -22,6 +22,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + python -m pip install. - name: Test with pytest run: | pip install pytest pytest-cov From 549132caaee9e073f75d10b33df1d414e7df97ea Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 10 Sep 2024 09:11:59 +0200 Subject: [PATCH 15/30] Update pytest.yml --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index e6688406..4fe833d9 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -22,7 +22,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install. + python -m pip install . - name: Test with pytest run: | pip install pytest pytest-cov From c22f8db61ccf1c91bed3d1d87ec11eff1a0f9933 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 10 Sep 2024 09:20:42 +0200 Subject: [PATCH 16/30] Update pytest.yml --- .github/workflows/pytest.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 4fe833d9..8c95047c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,4 +1,4 @@ -name: Python package +name: Unit Tests on: push: @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - build: + unit_tests: runs-on: ubuntu-latest strategy: @@ -23,7 +23,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install . + pip install pytest pytest-cov - name: Test with pytest run: | - pip install pytest pytest-cov pytest From 50468f2ba0f5b1d491ec03c876d820833cbab4a9 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 10 Sep 2024 09:21:26 +0200 Subject: [PATCH 17/30] Update pytest.yml --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 8c95047c..e902cf3c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -26,4 +26,4 @@ jobs: pip install pytest pytest-cov - name: Test with pytest run: | - pytest + pytest -v From bbc593a67d1ab8eb651f5deb750ece9fe48d7d46 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Tue, 10 Sep 2024 09:35:30 +0200 Subject: [PATCH 18/30] Update and rename test_status_execute_mocken.py to test_status_execute.py --- .../{test_status_execute_mocken.py => test_status_execute.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/qlever/commands/{test_status_execute_mocken.py => test_status_execute.py} (100%) diff --git a/test/qlever/commands/test_status_execute_mocken.py b/test/qlever/commands/test_status_execute.py similarity index 100% rename from test/qlever/commands/test_status_execute_mocken.py rename to test/qlever/commands/test_status_execute.py From 47ed435fbfb089df2b10ff32e64ec6220dff5e5d Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Thu, 12 Sep 2024 13:14:55 +0200 Subject: [PATCH 19/30] Update test_status_execute.py Fixing some pep8 warnings, shortening the code and making it more precise. --- test/qlever/commands/test_status_execute.py | 51 ++++++++++----------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index a346e11e..50578a16 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -1,26 +1,31 @@ import unittest -from unittest.mock import patch, MagicMock -import psutil +from unittest.mock import patch, MagicMock, call import qlever.command from qlever.commands.status import StatusCommand from io import StringIO import sys -from datetime import datetime + + +def get_mock_args(only_show): + args = MagicMock() + args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" + args.show = only_show + return [args, args.cmdline_regex, args.show] class TestStatusCommand(unittest.TestCase): + @patch('qlever.commands.status.show_process_info') @patch('psutil.process_iter') # testing execute for 2 processes. Just the second one is a qlever process. # Mocking the process_iter and show_process_info method and testing if the methods are called correctly. def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): # Mocking the input for the execute function - args = MagicMock() - args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" - args.show = False + [args, args.cmdline_regex, args.show] = get_mock_args(False) # Creating mock psutil.Process objects with necessary attributes mock_process1 = MagicMock() + mock_process1.as_dict.return_value = {'test': [1]} # to test with real psutil.process objects use this: '''mock_process1.as_dict.return_value = { 'cmdline': ['cmdline1'], @@ -29,7 +34,6 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info 'create_time': datetime.now().timestamp(), 'memory_info': MagicMock(rss=512 * 1024 * 1024) # 512 MB }''' - mock_process1.as_dict.return_value = {'test': [1]} mock_process2 = MagicMock() mock_process2.as_dict.return_value = {'test': [2]} @@ -42,37 +46,35 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info 'memory_info': MagicMock(rss=1024 * 1024 * 1024) # 1 GB }''' + mock_process3 = MagicMock() + mock_process3.as_dict.return_value = {'test': [3]} + # Mock the return value of process_iter to be a list of these mocked process objects - mock_process_iter.return_value = [mock_process1, mock_process2] + mock_process_iter.return_value = [mock_process1, mock_process2, mock_process3] # Simulate show_process_info returning False for the first and True for the second process - mock_show_process_info.side_effect = [False, True] + mock_show_process_info.side_effect = [False, True, False] sc = StatusCommand() # Execute the function result = sc.execute(args) - # Debugging: Print the actual calls to show_process_info - print(f"Actual show_process_info calls: {mock_show_process_info.call_args_list}") - # Assert that process_iter was called once mock_process_iter.assert_called_once() - # Assert that show_process_info was called with the correct arguments - mock_show_process_info.assert_any_call(mock_process1, args.cmdline_regex, show_heading=True) - mock_show_process_info.assert_any_call(mock_process2, args.cmdline_regex, show_heading=True) - + # Assert that show_process_info was called 3times in correct order with the correct arguments + expected_calls = [call(mock_process1, args.cmdline_regex, show_heading=True), + call(mock_process2, args.cmdline_regex, show_heading=True), + call(mock_process3, args.cmdline_regex, show_heading=False)] + mock_show_process_info.assert_has_calls(expected_calls, any_order=False) self.assertIsNone(result) @patch('qlever.util.show_process_info') @patch('psutil.process_iter') - # Verify the correct output was printed for an empty list of processes. def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_info): # Mocking the input for the execute function - args = MagicMock() - args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" - args.show = False + [args, args.cmdline_regex, args.show] = get_mock_args(False) # Mock process_iter to return an empty list, simulating that no matching processes are found mock_process_iter.return_value = [] @@ -102,17 +104,12 @@ def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_i self.assertIn("No processes found", captured_output.getvalue()) @patch.object(qlever.command.QleverCommand, 'show') - # Test the first part of the execute function. Test if the print command is executed correctly. def test_execute_show_action_description(self, mock_show): # Mocking the input for the execute function - args = MagicMock() - args.cmdline_regex = "^(ServerMain|IndexBuilderMain)" - mock_show.return_value = True - - sc = StatusCommand() + [args, args.cmdline_regex, args.show] = get_mock_args(True) # Execute the function - result = sc.execute(args) + result = StatusCommand().execute(args) # Assert that verifies that show was called with the correct parameters mock_show.assert_any_call(f"Show all processes on this machine where " From 7a656ea811abcab76732b26ab4deaee203daf720 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Thu, 12 Sep 2024 13:15:48 +0200 Subject: [PATCH 20/30] Update test_status_other_methods.py Made the code shorter --- .../commands/test_status_other_methods.py | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py index ee2edd0d..fb608c28 100644 --- a/test/qlever/commands/test_status_other_methods.py +++ b/test/qlever/commands/test_status_other_methods.py @@ -5,30 +5,15 @@ class TestStatusCommand(unittest.TestCase): def test_description(self): - # Create an instance of StatusCommand - sc = StatusCommand() - - # Call the method - result = sc.description() - + result = StatusCommand().description() self.assertEqual(result, "Show QLever processes running on this machine") def test_should_have_qleverfile(self): - # Create an instance of StatusCommand - sc = StatusCommand() + self.assertFalse(StatusCommand().should_have_qleverfile()) - # Call the method - result = sc.should_have_qleverfile() - - assert not result def test_relevant_qleverfile_arguments(self): - # Create an instance of StatusCommand - sc = StatusCommand() - - # Call the method - result = sc.relevant_qleverfile_arguments() - + result = StatusCommand().relevant_qleverfile_arguments() self.assertEqual(result, {}) def test_additional_arguments(self): From 833bad6ffaac7ea27a0c3faba556953b4eac33fe Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Thu, 12 Sep 2024 14:29:40 +0200 Subject: [PATCH 21/30] Update test_status_execute.py --- test/qlever/commands/test_status_execute.py | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index 50578a16..63bd53b5 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -19,7 +19,8 @@ class TestStatusCommand(unittest.TestCase): @patch('psutil.process_iter') # testing execute for 2 processes. Just the second one is a qlever process. # Mocking the process_iter and show_process_info method and testing if the methods are called correctly. - def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): + def test_execute_processes_found(self, mock_process_iter, + mock_show_process_info): # Mocking the input for the execute function [args, args.cmdline_regex, args.show] = get_mock_args(False) @@ -50,7 +51,8 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info mock_process3.as_dict.return_value = {'test': [3]} # Mock the return value of process_iter to be a list of these mocked process objects - mock_process_iter.return_value = [mock_process1, mock_process2, mock_process3] + mock_process_iter.return_value = [mock_process1, mock_process2, + mock_process3] # Simulate show_process_info returning False for the first and True for the second process mock_show_process_info.side_effect = [False, True, False] @@ -64,15 +66,18 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info mock_process_iter.assert_called_once() # Assert that show_process_info was called 3times in correct order with the correct arguments - expected_calls = [call(mock_process1, args.cmdline_regex, show_heading=True), - call(mock_process2, args.cmdline_regex, show_heading=True), - call(mock_process3, args.cmdline_regex, show_heading=False)] - mock_show_process_info.assert_has_calls(expected_calls, any_order=False) + expected_calls = [ + call(mock_process1, args.cmdline_regex, show_heading=True), + call(mock_process2, args.cmdline_regex, show_heading=True), + call(mock_process3, args.cmdline_regex, show_heading=False)] + mock_show_process_info.assert_has_calls(expected_calls, + any_order=False) self.assertIsNone(result) @patch('qlever.util.show_process_info') @patch('psutil.process_iter') - def test_execute_no_processes_found(self, mock_process_iter, mock_show_process_info): + def test_execute_no_processes_found(self, mock_process_iter, + mock_show_process_info): # Mocking the input for the execute function [args, args.cmdline_regex, args.show] = get_mock_args(False) @@ -113,7 +118,8 @@ def test_execute_show_action_description(self, mock_show): # Assert that verifies that show was called with the correct parameters mock_show.assert_any_call(f"Show all processes on this machine where " - f"the command line matches {args.cmdline_regex}" - f" using Python's psutil library", only_show=args.show) + f"the command line matches {args.cmdline_regex}" + f" using Python's psutil library", + only_show=args.show) self.assertFalse(result) From f6c759d91306936c82e5fff4c85b55536807329a Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Thu, 12 Sep 2024 14:31:18 +0200 Subject: [PATCH 22/30] Update test_status_other_methods.py --- test/qlever/commands/test_status_other_methods.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py index fb608c28..190b58b4 100644 --- a/test/qlever/commands/test_status_other_methods.py +++ b/test/qlever/commands/test_status_other_methods.py @@ -6,12 +6,12 @@ class TestStatusCommand(unittest.TestCase): def test_description(self): result = StatusCommand().description() - self.assertEqual(result, "Show QLever processes running on this machine") + self.assertEqual(result, + "Show QLever processes running on this machine") def test_should_have_qleverfile(self): self.assertFalse(StatusCommand().should_have_qleverfile()) - def test_relevant_qleverfile_arguments(self): result = StatusCommand().relevant_qleverfile_arguments() self.assertEqual(result, {}) @@ -29,8 +29,10 @@ def test_additional_arguments(self): args = parser.parse_args([]) # Test that the default value is set correctly - self.assertEqual(args.cmdline_regex, "^(ServerMain|IndexBuilderMain)") + self.assertEqual(args.cmdline_regex, + "^(ServerMain|IndexBuilderMain)") # Test that the help text is correctly set argument_help = subparser._group_actions[-1].help - self.assertEqual(argument_help, "Show only processes where the command line matches this regex") + self.assertEqual(argument_help, + "Show only processes where the command line matches this regex") From d3c020bdb73fc1e1050433b1ae6164c243a77f19 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Thu, 12 Sep 2024 14:33:01 +0200 Subject: [PATCH 23/30] Delete test/qlever/commands/test_stop_execute --- test/qlever/commands/test_stop_execute | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test/qlever/commands/test_stop_execute diff --git a/test/qlever/commands/test_stop_execute b/test/qlever/commands/test_stop_execute deleted file mode 100644 index 8b137891..00000000 --- a/test/qlever/commands/test_stop_execute +++ /dev/null @@ -1 +0,0 @@ - From c1fd7b76549985a738826a0f7be454538116b035 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 9 Oct 2024 12:15:22 +0200 Subject: [PATCH 24/30] Update test_status_other_methods.py --- test/qlever/commands/test_status_other_methods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py index 190b58b4..c1c00f5f 100644 --- a/test/qlever/commands/test_status_other_methods.py +++ b/test/qlever/commands/test_status_other_methods.py @@ -29,7 +29,7 @@ def test_additional_arguments(self): args = parser.parse_args([]) # Test that the default value is set correctly - self.assertEqual(args.cmdline_regex, + self.assertEqual(args.cmdline_regex, "^(ServerMain|IndexBuilderMain)") # Test that the help text is correctly set From fb7bf5381a8981eb150d14760f8128758400f4a7 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 9 Oct 2024 12:18:21 +0200 Subject: [PATCH 25/30] Update test_status_execute.py --- test/qlever/commands/test_status_execute.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index 63bd53b5..976dbae5 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -50,11 +50,13 @@ def test_execute_processes_found(self, mock_process_iter, mock_process3 = MagicMock() mock_process3.as_dict.return_value = {'test': [3]} - # Mock the return value of process_iter to be a list of these mocked process objects + # Mock the return value of process_iter + # to be a list of these mocked process objects mock_process_iter.return_value = [mock_process1, mock_process2, mock_process3] - # Simulate show_process_info returning False for the first and True for the second process + # Simulate show_process_info returning False for the first + # True for the second and False for the third process mock_show_process_info.side_effect = [False, True, False] sc = StatusCommand() @@ -65,7 +67,8 @@ def test_execute_processes_found(self, mock_process_iter, # Assert that process_iter was called once mock_process_iter.assert_called_once() - # Assert that show_process_info was called 3times in correct order with the correct arguments + # Assert that show_process_info was called 3times + # in correct order with the correct arguments expected_calls = [ call(mock_process1, args.cmdline_regex, show_heading=True), call(mock_process2, args.cmdline_regex, show_heading=True), @@ -81,7 +84,8 @@ def test_execute_no_processes_found(self, mock_process_iter, # Mocking the input for the execute function [args, args.cmdline_regex, args.show] = get_mock_args(False) - # Mock process_iter to return an empty list, simulating that no matching processes are found + # Mock process_iter to return an empty list, + # simulating that no matching processes are found mock_process_iter.return_value = [] # Capture the string-output @@ -100,7 +104,8 @@ def test_execute_no_processes_found(self, mock_process_iter, # Assert that process_iter was called once mock_process_iter.assert_called_once() - # Assert that show_process_info was never called since there are no processes + # Assert that show_process_info was never called + # since there are no processes mock_show_process_info.assert_not_called() self.assertIsNone(result) From 80d0c48d7edab8335c897836f41460021123ae04 Mon Sep 17 00:00:00 2001 From: SimonL22 Date: Wed, 9 Oct 2024 12:29:27 +0200 Subject: [PATCH 26/30] Update test_status_execute.py --- test/qlever/commands/test_status_execute.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index 976dbae5..57cc0873 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -18,7 +18,8 @@ class TestStatusCommand(unittest.TestCase): @patch('qlever.commands.status.show_process_info') @patch('psutil.process_iter') # testing execute for 2 processes. Just the second one is a qlever process. - # Mocking the process_iter and show_process_info method and testing if the methods are called correctly. + # Mocking the process_iter and show_process_info method and testing + # if the methods are called correctly. def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): # Mocking the input for the execute function From 6ef67ed311ac5c606f24edbdf19fd7c9a3ec5417 Mon Sep 17 00:00:00 2001 From: Johannes Kalmbach Date: Mon, 23 Dec 2024 10:11:38 +0100 Subject: [PATCH 27/30] formatting --- test/qlever/commands/test_status_execute.py | 54 +++++++++---------- .../commands/test_status_other_methods.py | 14 ++--- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index 57cc0873..3af3a072 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -14,47 +14,44 @@ def get_mock_args(only_show): class TestStatusCommand(unittest.TestCase): - - @patch('qlever.commands.status.show_process_info') - @patch('psutil.process_iter') + @patch("qlever.commands.status.show_process_info") + @patch("psutil.process_iter") # testing execute for 2 processes. Just the second one is a qlever process. - # Mocking the process_iter and show_process_info method and testing + # Mocking the process_iter and show_process_info method and testing # if the methods are called correctly. - def test_execute_processes_found(self, mock_process_iter, - mock_show_process_info): + def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): # Mocking the input for the execute function [args, args.cmdline_regex, args.show] = get_mock_args(False) # Creating mock psutil.Process objects with necessary attributes mock_process1 = MagicMock() - mock_process1.as_dict.return_value = {'test': [1]} + mock_process1.as_dict.return_value = {"test": [1]} # to test with real psutil.process objects use this: - '''mock_process1.as_dict.return_value = { + """mock_process1.as_dict.return_value = { 'cmdline': ['cmdline1'], 'pid': 1, 'username': 'user1', 'create_time': datetime.now().timestamp(), 'memory_info': MagicMock(rss=512 * 1024 * 1024) # 512 MB - }''' + }""" mock_process2 = MagicMock() - mock_process2.as_dict.return_value = {'test': [2]} + mock_process2.as_dict.return_value = {"test": [2]} # to test with real psutil.process objects use this: - '''mock_process2.as_dict.return_value = { + """mock_process2.as_dict.return_value = { 'cmdline': ['cmdline2'], 'pid': 2, 'username': 'user2', 'create_time': datetime.now().timestamp(), 'memory_info': MagicMock(rss=1024 * 1024 * 1024) # 1 GB - }''' + }""" mock_process3 = MagicMock() - mock_process3.as_dict.return_value = {'test': [3]} + mock_process3.as_dict.return_value = {"test": [3]} # Mock the return value of process_iter # to be a list of these mocked process objects - mock_process_iter.return_value = [mock_process1, mock_process2, - mock_process3] + mock_process_iter.return_value = [mock_process1, mock_process2, mock_process3] # Simulate show_process_info returning False for the first # True for the second and False for the third process @@ -73,15 +70,16 @@ def test_execute_processes_found(self, mock_process_iter, expected_calls = [ call(mock_process1, args.cmdline_regex, show_heading=True), call(mock_process2, args.cmdline_regex, show_heading=True), - call(mock_process3, args.cmdline_regex, show_heading=False)] - mock_show_process_info.assert_has_calls(expected_calls, - any_order=False) + call(mock_process3, args.cmdline_regex, show_heading=False), + ] + mock_show_process_info.assert_has_calls(expected_calls, any_order=False) self.assertIsNone(result) - @patch('qlever.util.show_process_info') - @patch('psutil.process_iter') - def test_execute_no_processes_found(self, mock_process_iter, - mock_show_process_info): + @patch("qlever.util.show_process_info") + @patch("psutil.process_iter") + def test_execute_no_processes_found( + self, mock_process_iter, mock_show_process_info + ): # Mocking the input for the execute function [args, args.cmdline_regex, args.show] = get_mock_args(False) @@ -114,7 +112,7 @@ def test_execute_no_processes_found(self, mock_process_iter, # Verify the correct output was printed self.assertIn("No processes found", captured_output.getvalue()) - @patch.object(qlever.command.QleverCommand, 'show') + @patch.object(qlever.command.QleverCommand, "show") def test_execute_show_action_description(self, mock_show): # Mocking the input for the execute function [args, args.cmdline_regex, args.show] = get_mock_args(True) @@ -123,9 +121,11 @@ def test_execute_show_action_description(self, mock_show): result = StatusCommand().execute(args) # Assert that verifies that show was called with the correct parameters - mock_show.assert_any_call(f"Show all processes on this machine where " - f"the command line matches {args.cmdline_regex}" - f" using Python's psutil library", - only_show=args.show) + mock_show.assert_any_call( + f"Show all processes on this machine where " + f"the command line matches {args.cmdline_regex}" + f" using Python's psutil library", + only_show=args.show, + ) self.assertFalse(result) diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py index c1c00f5f..ab3b5cbf 100644 --- a/test/qlever/commands/test_status_other_methods.py +++ b/test/qlever/commands/test_status_other_methods.py @@ -6,8 +6,7 @@ class TestStatusCommand(unittest.TestCase): def test_description(self): result = StatusCommand().description() - self.assertEqual(result, - "Show QLever processes running on this machine") + self.assertEqual(result, "Show QLever processes running on this machine") def test_should_have_qleverfile(self): self.assertFalse(StatusCommand().should_have_qleverfile()) @@ -22,17 +21,18 @@ def test_additional_arguments(self): # Create a parser and a subparser parser = argparse.ArgumentParser() - subparser = parser.add_argument_group('test') + subparser = parser.add_argument_group("test") # Call the method sc.additional_arguments(subparser) # Parse an empty argument list to see the default args = parser.parse_args([]) # Test that the default value is set correctly - self.assertEqual(args.cmdline_regex, - "^(ServerMain|IndexBuilderMain)") + self.assertEqual(args.cmdline_regex, "^(ServerMain|IndexBuilderMain)") # Test that the help text is correctly set argument_help = subparser._group_actions[-1].help - self.assertEqual(argument_help, - "Show only processes where the command line matches this regex") + self.assertEqual( + argument_help, + "Show only processes where the command line matches this regex", + ) From 1cf6d166f4ac69e55b5878407674a181d8a10fff Mon Sep 17 00:00:00 2001 From: Johannes Kalmbach Date: Mon, 23 Dec 2024 10:24:05 +0100 Subject: [PATCH 28/30] fix tests --- test/qlever/commands/test_status_execute.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index 3af3a072..7fdd1af2 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -73,7 +73,7 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info call(mock_process3, args.cmdline_regex, show_heading=False), ] mock_show_process_info.assert_has_calls(expected_calls, any_order=False) - self.assertIsNone(result) + self.assertTrue(result) @patch("qlever.util.show_process_info") @patch("psutil.process_iter") @@ -107,7 +107,7 @@ def test_execute_no_processes_found( # since there are no processes mock_show_process_info.assert_not_called() - self.assertIsNone(result) + self.assertTrue(result) # Verify the correct output was printed self.assertIn("No processes found", captured_output.getvalue()) @@ -128,4 +128,4 @@ def test_execute_show_action_description(self, mock_show): only_show=args.show, ) - self.assertFalse(result) + self.assertTrue(result) From 2fc801a4cc075a6d06badb4558b0d9270da6b153 Mon Sep 17 00:00:00 2001 From: Johannes Kalmbach Date: Mon, 23 Dec 2024 10:32:26 +0100 Subject: [PATCH 29/30] formatting fixed --- pyproject.toml | 3 +++ test/qlever/commands/test_status_execute.py | 14 +++++++++++--- test/qlever/commands/test_status_other_methods.py | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8efc6315..f891b32e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,3 +35,6 @@ package-data = { "qlever" = ["Qleverfiles/*"] } [tool.pytest.ini_options] pythonpath = ["src"] + +[tool.ruff] +line-length = 79 diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index 7fdd1af2..bc6ad1f8 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -19,7 +19,9 @@ class TestStatusCommand(unittest.TestCase): # testing execute for 2 processes. Just the second one is a qlever process. # Mocking the process_iter and show_process_info method and testing # if the methods are called correctly. - def test_execute_processes_found(self, mock_process_iter, mock_show_process_info): + def test_execute_processes_found( + self, mock_process_iter, mock_show_process_info + ): # Mocking the input for the execute function [args, args.cmdline_regex, args.show] = get_mock_args(False) @@ -51,7 +53,11 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info # Mock the return value of process_iter # to be a list of these mocked process objects - mock_process_iter.return_value = [mock_process1, mock_process2, mock_process3] + mock_process_iter.return_value = [ + mock_process1, + mock_process2, + mock_process3, + ] # Simulate show_process_info returning False for the first # True for the second and False for the third process @@ -72,7 +78,9 @@ def test_execute_processes_found(self, mock_process_iter, mock_show_process_info call(mock_process2, args.cmdline_regex, show_heading=True), call(mock_process3, args.cmdline_regex, show_heading=False), ] - mock_show_process_info.assert_has_calls(expected_calls, any_order=False) + mock_show_process_info.assert_has_calls( + expected_calls, any_order=False + ) self.assertTrue(result) @patch("qlever.util.show_process_info") diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py index ab3b5cbf..3e098012 100644 --- a/test/qlever/commands/test_status_other_methods.py +++ b/test/qlever/commands/test_status_other_methods.py @@ -6,7 +6,9 @@ class TestStatusCommand(unittest.TestCase): def test_description(self): result = StatusCommand().description() - self.assertEqual(result, "Show QLever processes running on this machine") + self.assertEqual( + result, "Show QLever processes running on this machine" + ) def test_should_have_qleverfile(self): self.assertFalse(StatusCommand().should_have_qleverfile()) From 5fb5ab0d1a75733677f25ca65330db2d3012f856 Mon Sep 17 00:00:00 2001 From: Johannes Kalmbach Date: Mon, 23 Dec 2024 10:39:52 +0100 Subject: [PATCH 30/30] also sort the imports via ruff --- pyproject.toml | 2 ++ test/qlever/commands/test_status_execute.py | 7 ++++--- test/qlever/commands/test_status_other_methods.py | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f891b32e..5987f4f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,3 +38,5 @@ pythonpath = ["src"] [tool.ruff] line-length = 79 +[tool.ruff.lint] +extend-select = ["I"] diff --git a/test/qlever/commands/test_status_execute.py b/test/qlever/commands/test_status_execute.py index bc6ad1f8..7f993c81 100644 --- a/test/qlever/commands/test_status_execute.py +++ b/test/qlever/commands/test_status_execute.py @@ -1,9 +1,10 @@ +import sys import unittest -from unittest.mock import patch, MagicMock, call +from io import StringIO +from unittest.mock import MagicMock, call, patch + import qlever.command from qlever.commands.status import StatusCommand -from io import StringIO -import sys def get_mock_args(only_show): diff --git a/test/qlever/commands/test_status_other_methods.py b/test/qlever/commands/test_status_other_methods.py index 3e098012..c1954000 100644 --- a/test/qlever/commands/test_status_other_methods.py +++ b/test/qlever/commands/test_status_other_methods.py @@ -1,6 +1,7 @@ +import argparse import unittest + from qlever.commands.status import StatusCommand -import argparse class TestStatusCommand(unittest.TestCase):