def test_testhandler_modules1(mock_ssh): """ Test that the module string remains empty after calling this method. """ job = {"modules": "", "resource": "test-machine", "handler": ""} mock_ssh.return_value = None _testhandler(job) assert job["modules"] == ""
def test_testhandler_except(mock_ssh): """ Test that the correct exception is raised when nothing can be detected. """ job = {"modules": "", "resource": "test-machine", "handler": ""} mock_ssh.side_effect = exceptions.SSHError("SSH Error", "Error") with pytest.raises(exceptions.HandlercheckError): _testhandler(job)
def test_testhandler_detection1(mock_ssh): """ Test that a handler can be detected. It is hard to specify exactly which to go for due to dictionaries being unordered. """ job = {"modules": "", "resource": "test-machine", "handler": ""} mock_ssh.return_value = None _testhandler(job) assert job["handler"] in ["aprun", "mpirun"]
def test_testhandler_detection2(mock_ssh): """ Test that a handler can be detected. It is hard to specify exactly which to go for due to dictionaries being unordered. Throw in a failure event. """ job = {"modules": "", "resource": "test-machine", "handler": ""} mock_ssh.side_effect = [exceptions.SSHError("SSH Error", "Error"), None] _testhandler(job) assert job["handler"] in ["aprun", "mpirun"]
def test_testhandler_modules2(mock_ssh): """ For provided modules, check that they are bring sent to SSH """ job = {"modules": "lsf, intel", "resource": "test-machine", "handler": ""} _testhandler(job) callargs = mock_ssh.call_args[0][1] assert 'module load lsf\n' in callargs assert 'module load intel\n' in callargs