Skip to content

Commit

Permalink
Added explicit test for KeyboardInterrupt raised in ProtocolUnit._exe…
Browse files Browse the repository at this point in the history
…cute
  • Loading branch information
dotsdl committed Aug 17, 2023
1 parent a61aa7c commit 976339c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion gufe/tests/test_protocolunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from pathlib import Path

from gufe.protocols.protocolunit import ProtocolUnit, Context, ProtocolUnitFailure
from gufe.protocols.protocolunit import ProtocolUnit, Context, ProtocolUnitFailure, ProtocolUnitResult
from gufe.tests.test_tokenization import GufeTokenizableTestsMixin


Expand All @@ -16,6 +16,16 @@ def _execute(ctx: Context, an_input=2, **inputs):
return {"foo": "bar"}


class DummyKeyboardInterruptUnit(ProtocolUnit):
@staticmethod
def _execute(ctx: Context, an_input=2, **inputs):

if an_input != 2:
raise KeyboardInterrupt

return {"foo": "bar"}


@pytest.fixture
def dummy_unit():
return DummyUnit(name="qux")
Expand Down Expand Up @@ -66,6 +76,26 @@ def test_execute(self, tmpdir):
with pytest.raises(ValueError, match="should always be 2"):
unit.execute(context=ctx, raise_error=True, an_input=3)

def test_execute_KeyboardInterrupt(self, tmpdir):
with tmpdir.as_cwd():

unit = DummyKeyboardInterruptUnit()

shared = Path('shared') / str(unit.key)
shared.mkdir(parents=True)

scratch = Path('scratch') / str(unit.key)
scratch.mkdir(parents=True)

ctx = Context(shared=shared, scratch=scratch)

with pytest.raises(KeyboardInterrupt):
unit.execute(context=ctx, an_input=3)

u: ProtocolUnitResult = unit.execute(context=ctx, an_input=2)

assert u.outputs == {'foo': 'bar'}

def test_normalize(self, dummy_unit):
thingy = dummy_unit.key

Expand Down

0 comments on commit 976339c

Please sign in to comment.