From 9bf42fae905b51f7e6180469d87c0c096ee3afdf Mon Sep 17 00:00:00 2001 From: fstagni Date: Tue, 29 Jun 2021 17:16:21 +0200 Subject: [PATCH] fix --- .../Agent/test/Test_Agent_JobAgent.py | 78 ++++++++++++------- .../Service/TornadoJobMonitoringHandler.py | 2 +- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py index 827b0080e66..b3264aa19f8 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py @@ -75,8 +75,16 @@ def test__getJDLParameters(mocker): assert result['Value']['Tags'] == ['16Processors', 'MultiProcessor'] -@pytest.mark.parametrize("mockJMInput, expected", [({'OK': True}, {'OK': True, 'Value': 'Job Rescheduled'}), ({ - 'OK': False, 'Message': "Test"}, {'OK': True, 'Value': 'Problem Rescheduling Job'})]) +@pytest.mark.parametrize( + "mockJMInput, expected", + [ + ({"OK": True}, {"OK": True, "Value": "Problem Rescheduling Job"}), + ( + {"OK": False, "Message": "Test"}, + {"OK": True, "Value": "Problem Rescheduling Job"}, + ), + ], +) def test__rescheduleFailedJob(mocker, mockJMInput, expected): """ Testing JobAgent()._rescheduleFailedJob() """ @@ -84,10 +92,6 @@ def test__rescheduleFailedJob(mocker, mockJMInput, expected): mockJM.return_value = mockJMInput mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__") - mocker.patch( - "DIRAC.WorkloadManagementSystem.Client.JobManagerClient.JobManagerClient.rescheduleJob", - side_effect=mockJM, - ) jobAgent = JobAgent('Test', 'Test1') @@ -103,16 +107,26 @@ def test__rescheduleFailedJob(mocker, mockJMInput, expected): @pytest.mark.parametrize( - "mockGCReplyInput, mockPMReplyInput, expected", [ - (True, { - 'OK': True, 'Value': 'Test'}, { - 'OK': True, 'Value': 'Test'}), (True, { - 'OK': False, 'Message': 'Test'}, { - 'OK': False, 'Message': 'Failed to setup proxy: Error retrieving proxy'}), (False, { - 'OK': True, 'Value': 'Test'}, { - 'OK': False, 'Message': 'Invalid Proxy'}), (False, { - 'OK': False, 'Message': 'Test'}, { - 'OK': False, 'Message': 'Invalid Proxy'})]) + "mockGCReplyInput, mockPMReplyInput, expected", + [ + (True, {"OK": True, "Value": "Test"}, {"OK": True, "Value": "Test"}), + ( + True, + {"OK": False, "Message": "Test"}, + {"OK": False, "Message": "Failed to setup proxy: Error retrieving proxy"}, + ), + ( + False, + {"OK": True, "Value": "Test"}, + {"OK": False, "Message": "Invalid Proxy"}, + ), + ( + False, + {"OK": False, "Message": "Test"}, + {"OK": False, "Message": "Invalid Proxy"}, + ), + ], +) def test__setupProxy(mocker, mockGCReplyInput, mockPMReplyInput, expected): """ Testing JobAgent()._setupProxy() """ @@ -162,16 +176,22 @@ def test__getCPUWorkLeft(mocker): @pytest.mark.parametrize( - "mockGCReplyInput, mockPMReplyInput, expected", [ - (True, { - 'OK': True, 'Value': 'Test'}, { - 'OK': True, 'Value': 'Test'}), (True, { - 'OK': False, 'Message': 'Test'}, { - 'OK': False, 'Message': 'Error retrieving proxy'}), (False, { - 'OK': True, 'Value': 'Test'}, { - 'OK': True, 'Value': 'Test'}), (False, { - 'OK': False, 'Message': 'Test'}, { - 'OK': False, 'Message': 'Error retrieving proxy'})]) + "mockGCReplyInput, mockPMReplyInput, expected", + [ + (True, {"OK": True, "Value": "Test"}, {"OK": True, "Value": "Test"}), + ( + True, + {"OK": False, "Message": "Test"}, + {"OK": False, "Message": "Error retrieving proxy"}, + ), + (False, {"OK": True, "Value": "Test"}, {"OK": True, "Value": "Test"}), + ( + False, + {"OK": False, "Message": "Test"}, + {"OK": False, "Message": "Error retrieving proxy"}, + ), + ], +) def test__requestProxyFromProxyManager(mocker, mockGCReplyInput, mockPMReplyInput, expected): """ Testing JobAgent()._requestProxyFromProxyManager() """ @@ -220,8 +240,10 @@ def test__checkInstallSoftware(mocker): assert result['Value'] == 'Job has no software installation requirement' -@pytest.mark.parametrize("mockJWInput, expected", [( - {'OK': False, 'Message': 'Test'}, {'OK': False, 'Message': 'Test'})]) +@pytest.mark.parametrize( + "mockJWInput, expected", + [({'OK': False, 'Message': 'Test'}, {'OK': False, 'Message': 'Test'})] +) def test_submitJob(mocker, mockJWInput, expected): """ Testing JobAgent()._submitJob() """ diff --git a/src/DIRAC/WorkloadManagementSystem/Service/TornadoJobMonitoringHandler.py b/src/DIRAC/WorkloadManagementSystem/Service/TornadoJobMonitoringHandler.py index 40dc601255a..885cebf6442 100644 --- a/src/DIRAC/WorkloadManagementSystem/Service/TornadoJobMonitoringHandler.py +++ b/src/DIRAC/WorkloadManagementSystem/Service/TornadoJobMonitoringHandler.py @@ -10,7 +10,7 @@ from DIRAC import gLogger from DIRAC.Core.Tornado.Server.TornadoService import TornadoService -from DIRAC.WorkloadManagementSystem.Service.JobMonitoringandler import JobMonitoringHandlerMixin +from DIRAC.WorkloadManagementSystem.Service.JobMonitoringHandler import JobMonitoringHandlerMixin sLog = gLogger.getSubLogger(__name__)