Skip to content

Commit

Permalink
add mocked error test
Browse files Browse the repository at this point in the history
  • Loading branch information
jthorton committed Jul 27, 2023
1 parent 1887e71 commit 6c461f6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions qcengine/tests/test_harness_canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,24 @@ def test_compute_bad_models(program, model):

with pytest.raises(qcng.exceptions.InputError) as exc:
ret = qcng.compute(inp, program, raise_error=True)

def test_psi4_restarts(monkeypatch):
"""
Make sure that a random error is raised which can be restarted if psi4 fails with no error message
"""
import msgpack
# create the psi4 task
inp = AtomicInput(molecule=qcng.get_molecule("hydrogen"), driver="energy", model={"method": "hf", "basis": "6-31G"})
def mock_execute(*args, **kwargs):
"mock the output of a failed psi4 task with missing error message"

mock_output = {
"sucess": False,
"outfiles": {"data.msgpack": msgpack.dumps({"missing": "data"})}
}
return True, mock_output

monkeypatch.setattr("qcengine.programs.psi4.execute", mock_execute)

with pytest.raises(qcng.exceptions.RandomError):
_ = qcng.compute(input_data=inp, program="psi4", raise_error=True, task_config={"retries": 0})

0 comments on commit 6c461f6

Please sign in to comment.